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