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