dom/workers/test/urlApi_worker.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 function ok(a, msg) {
michael@0 2 dump("OK: " + !!a + " => " + a + " " + msg + "\n");
michael@0 3 postMessage({type: 'status', status: !!a, msg: a + ": " + msg });
michael@0 4 }
michael@0 5
michael@0 6 function is(a, b, msg) {
michael@0 7 dump("IS: " + (a===b) + " => " + a + " | " + b + " " + msg + "\n");
michael@0 8 postMessage({type: 'status', status: a === b, msg: a + " === " + b + ": " + msg });
michael@0 9 }
michael@0 10
michael@0 11 onmessage = function() {
michael@0 12 status = false;
michael@0 13 try {
michael@0 14 if ((URL instanceof Object)) {
michael@0 15 status = true;
michael@0 16 }
michael@0 17 } catch(e) {
michael@0 18 }
michael@0 19
michael@0 20 var tests = [
michael@0 21 { url: 'http://www.abc.com',
michael@0 22 base: undefined,
michael@0 23 error: false,
michael@0 24 href: 'http://www.abc.com/',
michael@0 25 origin: 'http://www.abc.com',
michael@0 26 protocol: 'http:',
michael@0 27 username: '',
michael@0 28 password: '',
michael@0 29 host: 'www.abc.com',
michael@0 30 hostname: 'www.abc.com',
michael@0 31 port: '',
michael@0 32 pathname: '/',
michael@0 33 search: '',
michael@0 34 hash: ''
michael@0 35 },
michael@0 36 { url: 'ftp://auser:apw@www.abc.com',
michael@0 37 base: undefined,
michael@0 38 error: false,
michael@0 39 href: 'ftp://auser:apw@www.abc.com/',
michael@0 40 origin: 'ftp://www.abc.com',
michael@0 41 protocol: 'ftp:',
michael@0 42 username: 'auser',
michael@0 43 password: 'apw',
michael@0 44 host: 'www.abc.com',
michael@0 45 hostname: 'www.abc.com',
michael@0 46 port: '',
michael@0 47 pathname: '/',
michael@0 48 search: '',
michael@0 49 hash: ''
michael@0 50 },
michael@0 51 { url: 'http://www.abc.com:90/apath/',
michael@0 52 base: undefined,
michael@0 53 error: false,
michael@0 54 href: 'http://www.abc.com:90/apath/',
michael@0 55 origin: 'http://www.abc.com:90',
michael@0 56 protocol: 'http:',
michael@0 57 username: '',
michael@0 58 password: '',
michael@0 59 host: 'www.abc.com:90',
michael@0 60 hostname: 'www.abc.com',
michael@0 61 port: '90',
michael@0 62 pathname: '/apath/',
michael@0 63 search: '',
michael@0 64 hash: ''
michael@0 65 },
michael@0 66 { url: 'http://www.abc.com/apath/afile.txt#ahash',
michael@0 67 base: undefined,
michael@0 68 error: false,
michael@0 69 href: 'http://www.abc.com/apath/afile.txt#ahash',
michael@0 70 origin: 'http://www.abc.com',
michael@0 71 protocol: 'http:',
michael@0 72 username: '',
michael@0 73 password: '',
michael@0 74 host: 'www.abc.com',
michael@0 75 hostname: 'www.abc.com',
michael@0 76 port: '',
michael@0 77 pathname: '/apath/afile.txt',
michael@0 78 search: '',
michael@0 79 hash: '#ahash'
michael@0 80 },
michael@0 81 { url: 'http://example.com/?test#hash',
michael@0 82 base: undefined,
michael@0 83 error: false,
michael@0 84 href: 'http://example.com/?test#hash',
michael@0 85 origin: 'http://example.com',
michael@0 86 protocol: 'http:',
michael@0 87 username: '',
michael@0 88 password: '',
michael@0 89 host: 'example.com',
michael@0 90 hostname: 'example.com',
michael@0 91 port: '',
michael@0 92 pathname: '/',
michael@0 93 search: '?test',
michael@0 94 hash: '#hash'
michael@0 95 },
michael@0 96 { url: 'http://example.com/?test',
michael@0 97 base: undefined,
michael@0 98 error: false,
michael@0 99 href: 'http://example.com/?test',
michael@0 100 origin: 'http://example.com',
michael@0 101 protocol: 'http:',
michael@0 102 username: '',
michael@0 103 password: '',
michael@0 104 host: 'example.com',
michael@0 105 hostname: 'example.com',
michael@0 106 port: '',
michael@0 107 pathname: '/',
michael@0 108 search: '?test',
michael@0 109 hash: ''
michael@0 110 },
michael@0 111 { url: 'http://example.com/carrot#question%3f',
michael@0 112 base: undefined,
michael@0 113 error: false,
michael@0 114 hash: '#question?'
michael@0 115 },
michael@0 116 { url: 'https://example.com:4443?',
michael@0 117 base: undefined,
michael@0 118 error: false,
michael@0 119 protocol: 'https:',
michael@0 120 port: '4443',
michael@0 121 pathname: '/',
michael@0 122 hash: '',
michael@0 123 search: ''
michael@0 124 },
michael@0 125 { url: 'http://www.abc.com/apath/afile.txt#ahash?asearch',
michael@0 126 base: undefined,
michael@0 127 error: false,
michael@0 128 href: 'http://www.abc.com/apath/afile.txt#ahash?asearch',
michael@0 129 protocol: 'http:',
michael@0 130 pathname: '/apath/afile.txt',
michael@0 131 hash: '#ahash?asearch',
michael@0 132 search: ''
michael@0 133 },
michael@0 134 { url: 'http://www.abc.com/apath/afile.txt?asearch#ahash',
michael@0 135 base: undefined,
michael@0 136 error: false,
michael@0 137 href: 'http://www.abc.com/apath/afile.txt?asearch#ahash',
michael@0 138 protocol: 'http:',
michael@0 139 pathname: '/apath/afile.txt',
michael@0 140 hash: '#ahash',
michael@0 141 search: '?asearch'
michael@0 142 },
michael@0 143 { url: 'http://abc.com/apath/afile.txt?#ahash',
michael@0 144 base: undefined,
michael@0 145 error: false,
michael@0 146 pathname: '/apath/afile.txt',
michael@0 147 hash: '#ahash',
michael@0 148 search: ''
michael@0 149 },
michael@0 150 { url: 'http://auser:apassword@www.abc.com:90/apath/afile.txt?asearch#ahash',
michael@0 151 base: undefined,
michael@0 152 error: false,
michael@0 153 protocol: 'http:',
michael@0 154 username: 'auser',
michael@0 155 password: 'apassword',
michael@0 156 host: 'www.abc.com:90',
michael@0 157 hostname: 'www.abc.com',
michael@0 158 port: '90',
michael@0 159 pathname: '/apath/afile.txt',
michael@0 160 hash: '#ahash',
michael@0 161 search: '?asearch',
michael@0 162 origin: 'http://www.abc.com:90'
michael@0 163 },
michael@0 164
michael@0 165 { url: '/foo#bar',
michael@0 166 base: 'www.test.org',
michael@0 167 error: true,
michael@0 168 },
michael@0 169 { url: '/foo#bar',
michael@0 170 base: null,
michael@0 171 error: true,
michael@0 172 },
michael@0 173 { url: '/foo#bar',
michael@0 174 base: 42,
michael@0 175 error: true,
michael@0 176 },
michael@0 177 { url: 'ftp://ftp.something.net',
michael@0 178 base: undefined,
michael@0 179 error: false,
michael@0 180 protocol: 'ftp:',
michael@0 181 },
michael@0 182 { url: 'file:///tmp/file',
michael@0 183 base: undefined,
michael@0 184 error: false,
michael@0 185 protocol: 'file:',
michael@0 186 },
michael@0 187 { url: 'gopher://gopher.something.net',
michael@0 188 base: undefined,
michael@0 189 error: false,
michael@0 190 protocol: 'gopher:',
michael@0 191 },
michael@0 192 { url: 'ws://ws.something.net',
michael@0 193 base: undefined,
michael@0 194 error: false,
michael@0 195 protocol: 'ws:',
michael@0 196 },
michael@0 197 { url: 'wss://ws.something.net',
michael@0 198 base: undefined,
michael@0 199 error: false,
michael@0 200 protocol: 'wss:',
michael@0 201 },
michael@0 202 { url: 'foo://foo.something.net',
michael@0 203 base: undefined,
michael@0 204 error: false,
michael@0 205 protocol: 'foo:',
michael@0 206 },
michael@0 207 ];
michael@0 208
michael@0 209 while(tests.length) {
michael@0 210 var test = tests.shift();
michael@0 211
michael@0 212 var error = false;
michael@0 213 var url;
michael@0 214 try {
michael@0 215 if (test.base) {
michael@0 216 url = new URL(test.url, test.base);
michael@0 217 } else {
michael@0 218 url = new URL(test.url);
michael@0 219 }
michael@0 220 } catch(e) {
michael@0 221 error = true;
michael@0 222 }
michael@0 223
michael@0 224 is(test.error, error, "Error creating URL");
michael@0 225 if (test.error) {
michael@0 226 continue;
michael@0 227 }
michael@0 228
michael@0 229 if ('href' in test) is(url.href, test.href, "href");
michael@0 230 if ('origin' in test) is(url.origin, test.origin, "origin");
michael@0 231 if ('protocol' in test) is(url.protocol, test.protocol, "protocol");
michael@0 232 if ('username' in test) is(url.username, test.username, "username");
michael@0 233 if ('password' in test) is(url.password, test.password, "password");
michael@0 234 if ('host' in test) is(url.host, test.host, "host");
michael@0 235 if ('hostname' in test) is(url.hostname, test.hostname, "hostname");
michael@0 236 if ('port' in test) is(url.port, test.port, "port");
michael@0 237 if ('pathname' in test) is(url.pathname, test.pathname, "pathname");
michael@0 238 if ('search' in test) is(url.search, test.search, "search");
michael@0 239 if ('hash' in test) is(url.hash, test.hash, "hash");
michael@0 240
michael@0 241 url = new URL('https://www.example.net/what#foo?bar');
michael@0 242 ok(url, "Url exists!");
michael@0 243
michael@0 244 if ('href' in test) url.href = test.href;
michael@0 245 if ('protocol' in test) url.protocol = test.protocol;
michael@0 246 if ('username' in test && test.username) url.username = test.username;
michael@0 247 if ('password' in test && test.password) url.password = test.password;
michael@0 248 if ('host' in test) url.host = test.host;
michael@0 249 if ('hostname' in test) url.hostname = test.hostname;
michael@0 250 if ('port' in test) url.port = test.port;
michael@0 251 if ('pathname' in test) url.pathname = test.pathname;
michael@0 252 if ('search' in test) url.search = test.search;
michael@0 253 if ('hash' in test) url.hash = test.hash;
michael@0 254
michael@0 255 if ('href' in test) is(url.href, test.href, "href");
michael@0 256 if ('origin' in test) is(url.origin, test.origin, "origin");
michael@0 257 if ('protocol' in test) is(url.protocol, test.protocol, "protocol");
michael@0 258 if ('username' in test) is(url.username, test.username, "username");
michael@0 259 if ('password' in test) is(url.password, test.password, "password");
michael@0 260 if ('host' in test) is(url.host, test.host, "host");
michael@0 261 if ('hostname' in test) is(test.hostname, url.hostname, "hostname");
michael@0 262 if ('port' in test) is(test.port, url.port, "port");
michael@0 263 if ('pathname' in test) is(test.pathname, url.pathname, "pathname");
michael@0 264 if ('search' in test) is(test.search, url.search, "search");
michael@0 265 if ('hash' in test) is(test.hash, url.hash, "hash");
michael@0 266
michael@0 267 if ('href' in test) is (test.href, url + '', 'stringify works');
michael@0 268 }
michael@0 269
michael@0 270 postMessage({type: 'finish' });
michael@0 271 }
michael@0 272

mercurial