tor-browser

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

a-element-origin.js (1391B)


      1 promise_test(() => Promise.all([
      2  fetch("resources/urltestdata.json").then(res => res.json()),
      3  fetch("resources/urltestdata-javascript-only.json").then(res => res.json()),
      4 ]).then((tests) => tests.flat()).then(runURLTests), "Loading data…");
      5 
      6 function setBase(base) {
      7  document.getElementById("base").href = base
      8 }
      9 
     10 function bURL(url, base) {
     11  setBase(base);
     12  const a = document.createElement("a");
     13  a.setAttribute("href", url);
     14  return a;
     15 }
     16 
     17 function runURLTests(urlTests) {
     18  for (const expected of urlTests) {
     19    // Skip comments and tests without "origin" expectation
     20    if (typeof expected === "string" || !("origin" in expected))
     21      continue;
     22 
     23    // Fragments are relative against "about:blank" (this might always be redundant due to requiring "origin" in expected)
     24    if (expected.base === null && expected.input.startsWith("#"))
     25      continue;
     26 
     27    // HTML special cases data: and javascript: URLs in <base>
     28    if (expected.base !== null && (expected.base.startsWith("data:") || expected.base.startsWith("javascript:")))
     29      continue;
     30 
     31    // We cannot use a null base for HTML tests
     32    const base = expected.base === null ? "about:blank" : expected.base;
     33 
     34    test(function() {
     35      var url = bURL(expected.input, base)
     36      assert_equals(url.origin, expected.origin, "origin")
     37    }, "Parsing origin: <" + expected.input + "> against <" + base + ">")
     38  }
     39 }