1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-12 11:15:04 +02:00
video.js/test/unit/utils/url.test.js

66 lines
2.5 KiB
JavaScript
Raw Normal View History

Broke up Lib and Util into smaller libraries of functions Broke out bind, guid, and element data functions from Lib Separated out more dom functions in to dom.js Broke out URL functions into url.js Removed setLocalStorage since it wasn't being used Moved browser tests out of lib Moved log functions into their own file Removed trim() since it wasn't being used Moved formatTime into its own file Moved round into its own file and renamed roundFloat() Moved capitalize into its own file and renamed as toTitleCase() Moved createTimeRange into its own file Removed Lib.arr.forEach infavor of the native forEach Removed Lib.obj.create in favor of native Object.create (ES6-sham) Removed obj.each in favor of native Object.getOwnPropertyNames().forEach() Removed obj.merge and copy. Using lodash.assign instead. Replaced Lib.obj.isPlain with lodash.isPlainObject Removed Lib.obj.isArray in favor of the native Array.isArray Also removed the lib.js tests file as all tests have been moved or removed. Removed Lib.isEmpty in favor of !Object.getOwnPropertyNames().length Switched Util.mergeOptions and deepMerge to use new mergeOptions() Moved Lib.TEST_VID to Html5.TEST_VID Removed Lib references everywhere. Woo! Attempting to fix sourcemap test errors by setting grunt-browserify version Switched to object.assign from lodash.assign Removed unused 'inherits' dependency Reorganzied test files and added '.test' to file names Combined js/core.js and js/video.js Moved events.js into the utils directory
2015-05-04 01:12:38 +02:00
import document from 'global/document';
import window from 'global/window';
import * as Url from '../../../src/js/utils/url.js';
test('should parse the details of a url correctly', function(){
equal(Url.parseUrl('#').protocol, window.location.protocol, 'parsed relative url protocol');
equal(Url.parseUrl('#').host, window.location.host, 'parsed relative url host');
equal(Url.parseUrl('http://example.com').protocol, 'http:', 'parsed example url protocol');
equal(Url.parseUrl('http://example.com').hostname, 'example.com', 'parsed example url hostname');
equal(Url.parseUrl('http://example.com:1234').port, '1234', 'parsed example url port');
});
test('should strip port from hosts using http or https', function() {
var url;
var origDocCreate = document.createElement;
// attempts to create elements will return an anchor tag that
// misbehaves like IE9
document.createElement = function() {
return {
hostname: 'example.com',
host: 'example.com:80',
protocol: 'http:',
port: '80',
pathname: '/domain/relative/url',
hash: ''
};
};
url = Url.parseUrl('/domain/relative/url');
ok(!(/.*:80$/).test(url.host), ':80 is not appended to the host');
document.createElement = origDocCreate;
});
test('should get an absolute URL', function(){
// Errors on compiled tests that don't use unit.html. Need a better solution.
// ok(Url.getAbsoluteURL('unit.html') === window.location.href);
ok(Url.getAbsoluteURL('http://asdf.com') === 'http://asdf.com');
ok(Url.getAbsoluteURL('https://asdf.com/index.html') === 'https://asdf.com/index.html');
});
//getFileExtension tests
test('should get the file extension of the passed path', function() {
equal(Url.getFileExtension('/foo/bar/test.video.wgg'), 'wgg');
equal(Url.getFileExtension('test./video.mp4'), 'mp4');
equal(Url.getFileExtension('.bar/test.video.m4v'), 'm4v');
equal(Url.getFileExtension('foo/.bar/test.video.flv'), 'flv');
equal(Url.getFileExtension('foo/.bar/test.video.flv?foo=bar'), 'flv');
equal(Url.getFileExtension('http://www.test.com/video.mp4'), 'mp4');
equal(Url.getFileExtension('http://foo/bar/test.video.wgg'), 'wgg');
//edge cases
equal(Url.getFileExtension('http://...'), '');
equal(Url.getFileExtension('foo/.bar/testvideo'), '');
equal(Url.getFileExtension(''), '');
equal(Url.getFileExtension(null), '');
equal(Url.getFileExtension(undefined), '');
//with capital letters
equal(Url.getFileExtension('test.video.MP4'), 'mp4');
equal(Url.getFileExtension('test.video.FLV'), 'flv');
});