Bug 1943650 - Command-line --help output misformatted after --dbus-service. r=emilio
[gecko.git] / dom / url / tests / urlApi_worker.js
blob5a969c8e4caec12ba68898672bc287e71e4e9a47
1 /* eslint-env worker */
3 function ok(a, msg) {
4 dump("OK: " + !!a + " => " + a + " " + msg + "\n");
5 postMessage({ type: "status", status: !!a, msg: a + ": " + msg });
8 function is(a, b, msg) {
9 dump("IS: " + (a === b) + " => " + a + " | " + b + " " + msg + "\n");
10 postMessage({
11 type: "status",
12 status: a === b,
13 msg: a + " === " + b + ": " + msg,
14 });
17 // eslint-disable-next-line complexity
18 onmessage = function () {
19 let status = false;
20 try {
21 if (URL instanceof Object) {
22 status = true;
24 } catch (e) {}
26 ok(status, "URL in workers \\o/");
28 var tests = [
30 url: "http://www.abc.com",
31 base: undefined,
32 error: false,
33 href: "http://www.abc.com/",
34 origin: "http://www.abc.com",
35 protocol: "http:",
36 username: "",
37 password: "",
38 host: "www.abc.com",
39 hostname: "www.abc.com",
40 port: "",
41 pathname: "/",
42 search: "",
43 hash: "",
46 url: "ftp://auser:apw@www.abc.com",
47 base: undefined,
48 error: false,
49 href: "ftp://auser:apw@www.abc.com/",
50 origin: "ftp://www.abc.com",
51 protocol: "ftp:",
52 username: "auser",
53 password: "apw",
54 host: "www.abc.com",
55 hostname: "www.abc.com",
56 port: "",
57 pathname: "/",
58 search: "",
59 hash: "",
62 url: "http://www.abc.com:90/apath/",
63 base: undefined,
64 error: false,
65 href: "http://www.abc.com:90/apath/",
66 origin: "http://www.abc.com:90",
67 protocol: "http:",
68 username: "",
69 password: "",
70 host: "www.abc.com:90",
71 hostname: "www.abc.com",
72 port: "90",
73 pathname: "/apath/",
74 search: "",
75 hash: "",
78 url: "http://www.abc.com/apath/afile.txt#ahash",
79 base: undefined,
80 error: false,
81 href: "http://www.abc.com/apath/afile.txt#ahash",
82 origin: "http://www.abc.com",
83 protocol: "http:",
84 username: "",
85 password: "",
86 host: "www.abc.com",
87 hostname: "www.abc.com",
88 port: "",
89 pathname: "/apath/afile.txt",
90 search: "",
91 hash: "#ahash",
94 url: "http://example.com/?test#hash",
95 base: undefined,
96 error: false,
97 href: "http://example.com/?test#hash",
98 origin: "http://example.com",
99 protocol: "http:",
100 username: "",
101 password: "",
102 host: "example.com",
103 hostname: "example.com",
104 port: "",
105 pathname: "/",
106 search: "?test",
107 hash: "#hash",
110 url: "http://example.com/?test",
111 base: undefined,
112 error: false,
113 href: "http://example.com/?test",
114 origin: "http://example.com",
115 protocol: "http:",
116 username: "",
117 password: "",
118 host: "example.com",
119 hostname: "example.com",
120 port: "",
121 pathname: "/",
122 search: "?test",
123 hash: "",
126 url: "http://example.com/carrot#question%3f",
127 base: undefined,
128 error: false,
129 hash: "#question%3f",
132 url: "https://example.com:4443?",
133 base: undefined,
134 error: false,
135 protocol: "https:",
136 port: "4443",
137 pathname: "/",
138 hash: "",
139 search: "",
142 url: "http://www.abc.com/apath/afile.txt#ahash?asearch",
143 base: undefined,
144 error: false,
145 href: "http://www.abc.com/apath/afile.txt#ahash?asearch",
146 protocol: "http:",
147 pathname: "/apath/afile.txt",
148 hash: "#ahash?asearch",
149 search: "",
152 url: "http://www.abc.com/apath/afile.txt?asearch#ahash",
153 base: undefined,
154 error: false,
155 href: "http://www.abc.com/apath/afile.txt?asearch#ahash",
156 protocol: "http:",
157 pathname: "/apath/afile.txt",
158 hash: "#ahash",
159 search: "?asearch",
162 url: "http://abc.com/apath/afile.txt?#ahash",
163 base: undefined,
164 error: false,
165 pathname: "/apath/afile.txt",
166 hash: "#ahash",
167 search: "",
170 url: "http://auser:apassword@www.abc.com:90/apath/afile.txt?asearch#ahash",
171 base: undefined,
172 error: false,
173 protocol: "http:",
174 username: "auser",
175 password: "apassword",
176 host: "www.abc.com:90",
177 hostname: "www.abc.com",
178 port: "90",
179 pathname: "/apath/afile.txt",
180 hash: "#ahash",
181 search: "?asearch",
182 origin: "http://www.abc.com:90",
185 { url: "/foo#bar", base: "www.test.org", error: true },
186 { url: "/foo#bar", base: null, error: true },
187 { url: "/foo#bar", base: 42, error: true },
189 url: "ftp://ftp.something.net",
190 base: undefined,
191 error: false,
192 protocol: "ftp:",
195 url: "file:///tmp/file",
196 base: undefined,
197 error: false,
198 protocol: "file:",
201 url: "gopher://gopher.something.net",
202 base: undefined,
203 error: false,
204 protocol: "gopher:",
205 expectedChangedProtocol: "https:",
208 url: "ws://ws.something.net",
209 base: undefined,
210 error: false,
211 protocol: "ws:",
214 url: "wss://ws.something.net",
215 base: undefined,
216 error: false,
217 protocol: "wss:",
220 url: "foo://foo.something.net",
221 base: undefined,
222 error: false,
223 protocol: "foo:",
224 expectedChangedProtocol: "https:",
228 while (tests.length) {
229 var test = tests.shift();
231 var error = false;
232 var url;
233 try {
234 if (test.base) {
235 url = new URL(test.url, test.base);
236 } else {
237 url = new URL(test.url);
239 } catch (e) {
240 error = true;
243 is(test.error, error, "Error creating URL");
244 if (test.error) {
245 continue;
248 if ("href" in test) {
249 is(url.href, test.href, "href");
251 if ("origin" in test) {
252 is(url.origin, test.origin, "origin");
254 if ("protocol" in test) {
255 is(url.protocol, test.protocol, "protocol");
257 if ("username" in test) {
258 is(url.username, test.username, "username");
260 if ("password" in test) {
261 is(url.password, test.password, "password");
263 if ("host" in test) {
264 is(url.host, test.host, "host");
266 if ("hostname" in test) {
267 is(url.hostname, test.hostname, "hostname");
269 if ("port" in test) {
270 is(url.port, test.port, "port");
272 if ("pathname" in test) {
273 is(url.pathname, test.pathname, "pathname");
275 if ("search" in test) {
276 is(url.search, test.search, "search");
278 if ("hash" in test) {
279 is(url.hash, test.hash, "hash");
282 url = new URL("https://www.example.net/what#foo?bar");
283 ok(url, "Url exists!");
285 if ("href" in test) {
286 url.href = test.href;
288 if ("protocol" in test) {
289 url.protocol = test.protocol;
291 if ("username" in test && test.username) {
292 url.username = test.username;
294 if ("password" in test && test.password) {
295 url.password = test.password;
297 if ("host" in test) {
298 url.host = test.host;
300 if ("hostname" in test) {
301 url.hostname = test.hostname;
303 if ("port" in test) {
304 url.port = test.port;
306 if ("pathname" in test) {
307 url.pathname = test.pathname;
309 if ("search" in test) {
310 url.search = test.search;
312 if ("hash" in test) {
313 url.hash = test.hash;
316 if ("href" in test) {
317 is(url.href, test.href, "href");
319 if ("origin" in test) {
320 is(url.origin, test.origin, "origin");
322 if ("expectedChangedProtocol" in test) {
323 is(url.protocol, test.expectedChangedProtocol, "protocol");
324 } else if ("protocol" in test) {
325 is(url.protocol, test.protocol, "protocol");
327 if ("username" in test) {
328 is(url.username, test.username, "username");
330 if ("password" in test) {
331 is(url.password, test.password, "password");
333 if ("host" in test) {
334 is(url.host, test.host, "host");
336 if ("hostname" in test) {
337 is(test.hostname, url.hostname, "hostname");
339 if ("port" in test) {
340 is(test.port, url.port, "port");
342 if ("pathname" in test) {
343 is(test.pathname, url.pathname, "pathname");
345 if ("search" in test) {
346 is(test.search, url.search, "search");
348 if ("hash" in test) {
349 is(test.hash, url.hash, "hash");
352 if ("href" in test) {
353 is(test.href, url + "", "stringify works");
357 postMessage({ type: "finish" });