1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/test/test_url.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,296 @@ 1.4 + 1.5 +<!DOCTYPE HTML> 1.6 +<html> 1.7 +<head> 1.8 + <meta charset="utf-8"> 1.9 + <title>Test URL API</title> 1.10 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.11 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.12 +</head> 1.13 +<body> 1.14 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=887364">Mozilla Bug 887364</a> 1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=991471">Mozilla Bug 991471</a> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=996055">Mozilla Bug 996055</a> 1.17 +<p id="display"></p> 1.18 +<div id="content" style="display: none"> 1.19 + <iframe name="x" id="x"></iframe> 1.20 + <iframe name="y" id="y"></iframe> 1.21 +</div> 1.22 +<pre id="test"> 1.23 +</pre> 1.24 + <script type="application/javascript"> 1.25 + 1.26 + /** Test for Bug 887364 **/ 1.27 + ok("URL" in window, "window.URL exists"); 1.28 + 1.29 + var tests = [ 1.30 + { url: 'http://www.abc.com', 1.31 + base: undefined, 1.32 + error: false, 1.33 + href: 'http://www.abc.com/', 1.34 + origin: 'http://www.abc.com', 1.35 + protocol: 'http:', 1.36 + username: '', 1.37 + password: '', 1.38 + host: 'www.abc.com', 1.39 + hostname: 'www.abc.com', 1.40 + port: '', 1.41 + pathname: '/', 1.42 + search: '', 1.43 + hash: '' 1.44 + }, 1.45 + { url: 'ftp://auser:apw@www.abc.com', 1.46 + base: undefined, 1.47 + error: false, 1.48 + href: 'ftp://auser:apw@www.abc.com/', 1.49 + origin: 'ftp://www.abc.com', 1.50 + protocol: 'ftp:', 1.51 + username: 'auser', 1.52 + password: 'apw', 1.53 + host: 'www.abc.com', 1.54 + hostname: 'www.abc.com', 1.55 + port: '', 1.56 + pathname: '/', 1.57 + search: '', 1.58 + hash: '' 1.59 + }, 1.60 + { url: 'http://www.abc.com:90/apath/', 1.61 + base: undefined, 1.62 + error: false, 1.63 + href: 'http://www.abc.com:90/apath/', 1.64 + origin: 'http://www.abc.com:90', 1.65 + protocol: 'http:', 1.66 + username: '', 1.67 + password: '', 1.68 + host: 'www.abc.com:90', 1.69 + hostname: 'www.abc.com', 1.70 + port: '90', 1.71 + pathname: '/apath/', 1.72 + search: '', 1.73 + hash: '' 1.74 + }, 1.75 + { url: 'http://www.abc.com/apath/afile.txt#ahash', 1.76 + base: undefined, 1.77 + error: false, 1.78 + href: 'http://www.abc.com/apath/afile.txt#ahash', 1.79 + origin: 'http://www.abc.com', 1.80 + protocol: 'http:', 1.81 + username: '', 1.82 + password: '', 1.83 + host: 'www.abc.com', 1.84 + hostname: 'www.abc.com', 1.85 + port: '', 1.86 + pathname: '/apath/afile.txt', 1.87 + search: '', 1.88 + hash: '#ahash' 1.89 + }, 1.90 + { url: 'http://example.com/?test#hash', 1.91 + base: undefined, 1.92 + error: false, 1.93 + href: 'http://example.com/?test#hash', 1.94 + origin: 'http://example.com', 1.95 + protocol: 'http:', 1.96 + username: '', 1.97 + password: '', 1.98 + host: 'example.com', 1.99 + hostname: 'example.com', 1.100 + port: '', 1.101 + pathname: '/', 1.102 + search: '?test', 1.103 + hash: '#hash' 1.104 + }, 1.105 + { url: 'http://example.com/?test', 1.106 + base: undefined, 1.107 + error: false, 1.108 + href: 'http://example.com/?test', 1.109 + origin: 'http://example.com', 1.110 + protocol: 'http:', 1.111 + username: '', 1.112 + password: '', 1.113 + host: 'example.com', 1.114 + hostname: 'example.com', 1.115 + port: '', 1.116 + pathname: '/', 1.117 + search: '?test', 1.118 + hash: '' 1.119 + }, 1.120 + { url: 'http://example.com/carrot#question%3f', 1.121 + base: undefined, 1.122 + error: false, 1.123 + hash: '#question?' 1.124 + }, 1.125 + { url: 'https://example.com:4443?', 1.126 + base: undefined, 1.127 + error: false, 1.128 + protocol: 'https:', 1.129 + port: '4443', 1.130 + pathname: '/', 1.131 + hash: '', 1.132 + search: '' 1.133 + }, 1.134 + { url: 'http://www.abc.com/apath/afile.txt#ahash?asearch', 1.135 + base: undefined, 1.136 + error: false, 1.137 + href: 'http://www.abc.com/apath/afile.txt#ahash?asearch', 1.138 + protocol: 'http:', 1.139 + pathname: '/apath/afile.txt', 1.140 + hash: '#ahash?asearch', 1.141 + search: '' 1.142 + }, 1.143 + { url: 'http://www.abc.com/apath/afile.txt?asearch#ahash', 1.144 + base: undefined, 1.145 + error: false, 1.146 + href: 'http://www.abc.com/apath/afile.txt?asearch#ahash', 1.147 + protocol: 'http:', 1.148 + pathname: '/apath/afile.txt', 1.149 + hash: '#ahash', 1.150 + search: '?asearch' 1.151 + }, 1.152 + { url: 'http://abc.com/apath/afile.txt?#ahash', 1.153 + base: undefined, 1.154 + error: false, 1.155 + pathname: '/apath/afile.txt', 1.156 + hash: '#ahash', 1.157 + search: '' 1.158 + }, 1.159 + { url: 'http://auser:apassword@www.abc.com:90/apath/afile.txt?asearch#ahash', 1.160 + base: undefined, 1.161 + error: false, 1.162 + protocol: 'http:', 1.163 + username: 'auser', 1.164 + password: 'apassword', 1.165 + host: 'www.abc.com:90', 1.166 + hostname: 'www.abc.com', 1.167 + port: '90', 1.168 + pathname: '/apath/afile.txt', 1.169 + hash: '#ahash', 1.170 + search: '?asearch', 1.171 + origin: 'http://www.abc.com:90' 1.172 + }, 1.173 + 1.174 + { url: '/foo#bar', 1.175 + base: 'www.test.org', 1.176 + error: true, 1.177 + }, 1.178 + { url: '/foo#bar', 1.179 + base: null, 1.180 + error: true, 1.181 + }, 1.182 + { url: '/foo#bar', 1.183 + base: 42, 1.184 + error: true, 1.185 + }, 1.186 + { url: 'ftp://ftp.something.net', 1.187 + base: undefined, 1.188 + error: false, 1.189 + protocol: 'ftp:', 1.190 + }, 1.191 + { url: 'file:///tmp/file', 1.192 + base: undefined, 1.193 + error: false, 1.194 + protocol: 'file:', 1.195 + }, 1.196 + { url: 'gopher://gopher.something.net', 1.197 + base: undefined, 1.198 + error: false, 1.199 + protocol: 'gopher:', 1.200 + }, 1.201 + { url: 'ws://ws.something.net', 1.202 + base: undefined, 1.203 + error: false, 1.204 + protocol: 'ws:', 1.205 + }, 1.206 + { url: 'wss://ws.something.net', 1.207 + base: undefined, 1.208 + error: false, 1.209 + protocol: 'wss:', 1.210 + }, 1.211 + { url: 'foo://foo.something.net', 1.212 + base: undefined, 1.213 + error: false, 1.214 + protocol: 'foo:', 1.215 + }, 1.216 + ]; 1.217 + 1.218 + while(tests.length) { 1.219 + var test = tests.shift(); 1.220 + 1.221 + var error = false; 1.222 + var url; 1.223 + try { 1.224 + if (test.base) { 1.225 + url = new URL(test.url, test.base); 1.226 + } else { 1.227 + url = new URL(test.url); 1.228 + } 1.229 + } catch(e) { 1.230 + error = true; 1.231 + } 1.232 + 1.233 + is(test.error, error, "Error creating URL"); 1.234 + if (test.error) { 1.235 + continue; 1.236 + } 1.237 + 1.238 + if ('href' in test) is(url.href, test.href, "href"); 1.239 + if ('origin' in test) is(url.origin, test.origin, "origin"); 1.240 + if ('protocol' in test) is(url.protocol, test.protocol, "protocol"); 1.241 + if ('username' in test) is(url.username, test.username, "username"); 1.242 + if ('password' in test) is(url.password, test.password, "password"); 1.243 + if ('host' in test) is(url.host, test.host, "host"); 1.244 + if ('hostname' in test) is(url.hostname, test.hostname, "hostname"); 1.245 + if ('port' in test) is(url.port, test.port, "port"); 1.246 + if ('pathname' in test) is(url.pathname, test.pathname, "pathname"); 1.247 + if ('search' in test) is(url.search, test.search, "search"); 1.248 + if ('hash' in test) is(url.hash, test.hash, "hash"); 1.249 + 1.250 + url = new URL('https://www.example.net/what#foo?bar'); 1.251 + ok(url, "Url exists!"); 1.252 + 1.253 + if ('href' in test) url.href = test.href; 1.254 + if ('protocol' in test) url.protocol = test.protocol; 1.255 + if ('username' in test && test.username) url.username = test.username; 1.256 + if ('password' in test && test.password) url.password = test.password; 1.257 + if ('host' in test) url.host = test.host; 1.258 + if ('hostname' in test) url.hostname = test.hostname; 1.259 + if ('port' in test) url.port = test.port; 1.260 + if ('pathname' in test) url.pathname = test.pathname; 1.261 + if ('search' in test) url.search = test.search; 1.262 + if ('hash' in test) url.hash = test.hash; 1.263 + 1.264 + if ('href' in test) is(url.href, test.href, "href"); 1.265 + if ('origin' in test) is(url.origin, test.origin, "origin"); 1.266 + if ('protocol' in test) is(url.protocol, test.protocol, "protocol"); 1.267 + if ('username' in test) is(url.username, test.username, "username"); 1.268 + if ('password' in test) is(url.password, test.password, "password"); 1.269 + if ('host' in test) is(url.host, test.host, "host"); 1.270 + if ('hostname' in test) is(test.hostname, url.hostname, "hostname"); 1.271 + if ('port' in test) is(test.port, url.port, "port"); 1.272 + if ('pathname' in test) is(test.pathname, url.pathname, "pathname"); 1.273 + if ('search' in test) is(test.search, url.search, "search"); 1.274 + if ('hash' in test) is(test.hash, url.hash, "hash"); 1.275 + 1.276 + if ('href' in test) is (test.href, url + '', 'stringify works'); 1.277 + } 1.278 + 1.279 + </script> 1.280 + 1.281 + <script> 1.282 + /** Test for Bug 991471 **/ 1.283 + var url = new URL("http://localhost/"); 1.284 + url.hostname = ""; 1.285 + url.username = "tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"; 1.286 + url.hostname = "www.mozilla.org"; 1.287 + url.username = ""; 1.288 + url.hostname = "www.mozilla.org"; 1.289 + is(url.href, "http://www.mozilla.org/", "No parsing error with empty host"); 1.290 + </script> 1.291 + 1.292 + <script> 1.293 + /** Test for Bug 996055 **/ 1.294 + var url = new URL("http://localhost/"); 1.295 + url.hostname = ""; 1.296 + is(url.href, "http://localhost/", "Empty hostname is ignored"); 1.297 + </script> 1.298 +</body> 1.299 +</html>