123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- function ok(a, msg) {
- dump("OK: " + !!a + " => " + a + " " + msg + "\n");
- postMessage({type: 'status', status: !!a, msg: a + ": " + msg });
- }
- function is(a, b, msg) {
- dump("IS: " + (a===b) + " => " + a + " | " + b + " " + msg + "\n");
- postMessage({type: 'status', status: a === b, msg: a + " === " + b + ": " + msg });
- }
- onmessage = function() {
- status = false;
- try {
- if ((URL instanceof Object)) {
- status = true;
- }
- } catch(e) {
- }
- var tests = [
- { url: 'http://www.abc.com',
- base: undefined,
- error: false,
- href: 'http://www.abc.com/',
- origin: 'http://www.abc.com',
- protocol: 'http:',
- username: '',
- password: '',
- host: 'www.abc.com',
- hostname: 'www.abc.com',
- port: '',
- pathname: '/',
- search: '',
- hash: ''
- },
- { url: 'ftp://auser:apw@www.abc.com',
- base: undefined,
- error: false,
- href: 'ftp://auser:apw@www.abc.com/',
- origin: 'ftp://www.abc.com',
- protocol: 'ftp:',
- username: 'auser',
- password: 'apw',
- host: 'www.abc.com',
- hostname: 'www.abc.com',
- port: '',
- pathname: '/',
- search: '',
- hash: ''
- },
- { url: 'http://www.abc.com:90/apath/',
- base: undefined,
- error: false,
- href: 'http://www.abc.com:90/apath/',
- origin: 'http://www.abc.com:90',
- protocol: 'http:',
- username: '',
- password: '',
- host: 'www.abc.com:90',
- hostname: 'www.abc.com',
- port: '90',
- pathname: '/apath/',
- search: '',
- hash: ''
- },
- { url: 'http://www.abc.com/apath/afile.txt#ahash',
- base: undefined,
- error: false,
- href: 'http://www.abc.com/apath/afile.txt#ahash',
- origin: 'http://www.abc.com',
- protocol: 'http:',
- username: '',
- password: '',
- host: 'www.abc.com',
- hostname: 'www.abc.com',
- port: '',
- pathname: '/apath/afile.txt',
- search: '',
- hash: '#ahash'
- },
- { url: 'http://example.com/?test#hash',
- base: undefined,
- error: false,
- href: 'http://example.com/?test#hash',
- origin: 'http://example.com',
- protocol: 'http:',
- username: '',
- password: '',
- host: 'example.com',
- hostname: 'example.com',
- port: '',
- pathname: '/',
- search: '?test',
- hash: '#hash'
- },
- { url: 'http://example.com/?test',
- base: undefined,
- error: false,
- href: 'http://example.com/?test',
- origin: 'http://example.com',
- protocol: 'http:',
- username: '',
- password: '',
- host: 'example.com',
- hostname: 'example.com',
- port: '',
- pathname: '/',
- search: '?test',
- hash: ''
- },
- { url: 'http://example.com/carrot#question%3f',
- base: undefined,
- error: false,
- hash: '#question%3f'
- },
- { url: 'https://example.com:4443?',
- base: undefined,
- error: false,
- protocol: 'https:',
- port: '4443',
- pathname: '/',
- hash: '',
- search: ''
- },
- { url: 'http://www.abc.com/apath/afile.txt#ahash?asearch',
- base: undefined,
- error: false,
- href: 'http://www.abc.com/apath/afile.txt#ahash?asearch',
- protocol: 'http:',
- pathname: '/apath/afile.txt',
- hash: '#ahash?asearch',
- search: ''
- },
- { url: 'http://www.abc.com/apath/afile.txt?asearch#ahash',
- base: undefined,
- error: false,
- href: 'http://www.abc.com/apath/afile.txt?asearch#ahash',
- protocol: 'http:',
- pathname: '/apath/afile.txt',
- hash: '#ahash',
- search: '?asearch'
- },
- { url: 'http://abc.com/apath/afile.txt?#ahash',
- base: undefined,
- error: false,
- pathname: '/apath/afile.txt',
- hash: '#ahash',
- search: ''
- },
- { url: 'http://auser:apassword@www.abc.com:90/apath/afile.txt?asearch#ahash',
- base: undefined,
- error: false,
- protocol: 'http:',
- username: 'auser',
- password: 'apassword',
- host: 'www.abc.com:90',
- hostname: 'www.abc.com',
- port: '90',
- pathname: '/apath/afile.txt',
- hash: '#ahash',
- search: '?asearch',
- origin: 'http://www.abc.com:90'
- },
- { url: '/foo#bar',
- base: 'www.test.org',
- error: true,
- },
- { url: '/foo#bar',
- base: null,
- error: true,
- },
- { url: '/foo#bar',
- base: 42,
- error: true,
- },
- { url: 'ftp://ftp.something.net',
- base: undefined,
- error: false,
- protocol: 'ftp:',
- },
- { url: 'file:///tmp/file',
- base: undefined,
- error: false,
- protocol: 'file:',
- },
- { url: 'gopher://gopher.something.net',
- base: undefined,
- error: false,
- protocol: 'gopher:',
- },
- { url: 'ws://ws.something.net',
- base: undefined,
- error: false,
- protocol: 'ws:',
- },
- { url: 'wss://ws.something.net',
- base: undefined,
- error: false,
- protocol: 'wss:',
- },
- { url: 'foo://foo.something.net',
- base: undefined,
- error: false,
- protocol: 'foo:',
- },
- ];
- while(tests.length) {
- var test = tests.shift();
- var error = false;
- var url;
- try {
- if (test.base) {
- url = new URL(test.url, test.base);
- } else {
- url = new URL(test.url);
- }
- } catch(e) {
- error = true;
- }
- is(test.error, error, "Error creating URL");
- if (test.error) {
- continue;
- }
- if ('href' in test) is(url.href, test.href, "href");
- if ('origin' in test) is(url.origin, test.origin, "origin");
- if ('protocol' in test) is(url.protocol, test.protocol, "protocol");
- if ('username' in test) is(url.username, test.username, "username");
- if ('password' in test) is(url.password, test.password, "password");
- if ('host' in test) is(url.host, test.host, "host");
- if ('hostname' in test) is(url.hostname, test.hostname, "hostname");
- if ('port' in test) is(url.port, test.port, "port");
- if ('pathname' in test) is(url.pathname, test.pathname, "pathname");
- if ('search' in test) is(url.search, test.search, "search");
- if ('hash' in test) is(url.hash, test.hash, "hash");
- url = new URL('https://www.example.net/what#foo?bar');
- ok(url, "Url exists!");
- if ('href' in test) url.href = test.href;
- if ('protocol' in test) url.protocol = test.protocol;
- if ('username' in test && test.username) url.username = test.username;
- if ('password' in test && test.password) url.password = test.password;
- if ('host' in test) url.host = test.host;
- if ('hostname' in test) url.hostname = test.hostname;
- if ('port' in test) url.port = test.port;
- if ('pathname' in test) url.pathname = test.pathname;
- if ('search' in test) url.search = test.search;
- if ('hash' in test) url.hash = test.hash;
- if ('href' in test) is(url.href, test.href, "href");
- if ('origin' in test) is(url.origin, test.origin, "origin");
- if ('protocol' in test) is(url.protocol, test.protocol, "protocol");
- if ('username' in test) is(url.username, test.username, "username");
- if ('password' in test) is(url.password, test.password, "password");
- if ('host' in test) is(url.host, test.host, "host");
- if ('hostname' in test) is(test.hostname, url.hostname, "hostname");
- if ('port' in test) is(test.port, url.port, "port");
- if ('pathname' in test) is(test.pathname, url.pathname, "pathname");
- if ('search' in test) is(test.search, url.search, "search");
- if ('hash' in test) is(test.hash, url.hash, "hash");
- if ('href' in test) is (test.href, url + '', 'stringify works');
- }
- postMessage({type: 'finish' });
- }
|