tor-browser

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

IdnaTestV2.window.js (897B)


      1 promise_test(() => fetch("resources/IdnaTestV2.json").then(res => res.json()).then(runTests), "Loading data…");
      2 
      3 function runTests(idnaTests) {
      4  for (const idnaTest of idnaTests) {
      5    if (typeof idnaTest === "string") {
      6      continue // skip comments
      7    }
      8    if (idnaTest.input === "") {
      9      continue // cannot test empty string input through new URL()
     10    }
     11 
     12    test(() => {
     13      if (idnaTest.output === null) {
     14        assert_throws_js(TypeError, () => new URL(`https://${idnaTest.input}/x`));
     15      } else {
     16        const url = new URL(`https://${idnaTest.input}/x`);
     17        assert_equals(url.host, idnaTest.output);
     18        assert_equals(url.hostname, idnaTest.output);
     19        assert_equals(url.pathname, "/x");
     20        assert_equals(url.href, `https://${idnaTest.output}/x`);
     21      }
     22    }, `ToASCII("${idnaTest.input}")${idnaTest.comment ? " " + idnaTest.comment : ""}`);
     23  }
     24 }