tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

failure.html (2339B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>Test URL parser failure consistency</title>
      4 <meta name=timeout content=long>
      5 <script src=/resources/testharness.js></script>
      6 <script src=/resources/testharnessreport.js></script>
      7 <div id=log></div>
      8 <script>
      9 promise_test(() => Promise.all([
     10  fetch("resources/urltestdata.json").then(res => res.json()),
     11  fetch("resources/urltestdata-javascript-only.json").then(res => res.json()),
     12 ]).then((tests) => tests.flat()).then(runTests), "Loading data…");
     13 
     14 function runTests(testData) {
     15  for (const test of testData) {
     16 
     17    // skip comments, inputs we expect to pass and relative URLs
     18    if (typeof test === "string" || !test.failure || test.base !== null) {
     19      continue;
     20    }
     21 
     22    const name = test.input + " should throw"
     23 
     24    self.test(() => {
     25      // URL's constructor's first argument is tested by url-constructor.html
     26      // If a URL fails to parse with any valid base, it must also fail to parse with no base, i.e.
     27      // when used as a base URL itself.
     28      assert_throws_js(TypeError, () => new URL("about:blank", test.input));
     29    }, "URL's constructor's base argument: " + name)
     30 
     31    self.test(() => {
     32      const url = new URL("about:blank")
     33      assert_throws_js(TypeError, () => url.href = test.input)
     34    }, "URL's href: " + name)
     35 
     36    // The following use cases resolve the URL input relative to the current
     37    // document's URL. If this test input could be construed as a valid URL
     38    // when resolved against a base URL, skip these cases.
     39    if (test.relativeTo === undefined) {
     40      self.test(() => {
     41        const client = new XMLHttpRequest()
     42        assert_throws_dom("SyntaxError", () => client.open("GET", test.input))
     43      }, "XHR: " + name)
     44 
     45      self.test(() => {
     46        assert_throws_js(TypeError, () => self.navigator.sendBeacon(test.input))
     47      }, "sendBeacon(): " + name)
     48 
     49      self.test(t => {
     50        const frame = document.body.appendChild(document.createElement("iframe"));
     51        t.add_cleanup(() => frame.remove());
     52        assert_throws_dom("SyntaxError", frame.contentWindow.DOMException, () => frame.contentWindow.location = test.input);
     53      }, "Location's href: " + name);
     54 
     55      self.test(() => {
     56        assert_throws_dom("SyntaxError", () => self.open(test.input).close())
     57      }, "window.open(): " + name)
     58    }
     59  }
     60 }
     61 </script>