tor-browser

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

toascii.window.js (1846B)


      1 promise_test(() => fetch("resources/toascii.json").then(res => res.json()).then(runTests), "Loading data…");
      2 
      3 function makeURL(type, input) {
      4  input = "https://" + input + "/x"
      5  if(type === "url") {
      6    return new URL(input)
      7  } else {
      8    const url = document.createElement(type)
      9    url.href = input
     10    return url
     11  }
     12 }
     13 
     14 function runTests(tests) {
     15  for(var i = 0, l = tests.length; i < l; i++) {
     16    let hostTest = tests[i]
     17    if (typeof hostTest === "string") {
     18      continue // skip comments
     19    }
     20    const typeName = { "url": "URL", "a": "<a>", "area": "<area>" }
     21    ;["url", "a", "area"].forEach((type) => {
     22      test(() => {
     23        if(hostTest.output !== null) {
     24          const url = makeURL("url", hostTest.input)
     25          assert_equals(url.host, hostTest.output)
     26          assert_equals(url.hostname, hostTest.output)
     27          assert_equals(url.pathname, "/x")
     28          assert_equals(url.href, "https://" + hostTest.output + "/x")
     29        } else {
     30          if(type === "url") {
     31            assert_throws_js(TypeError, () => makeURL("url", hostTest.input))
     32          } else {
     33            const url = makeURL(type, hostTest.input)
     34            assert_equals(url.host, "")
     35            assert_equals(url.hostname, "")
     36            assert_equals(url.pathname, "")
     37            assert_equals(url.href, "https://" + hostTest.input + "/x")
     38          }
     39        }
     40      }, hostTest.input + " (using " + typeName[type] + ")")
     41      ;["host", "hostname"].forEach((val) => {
     42        test(() => {
     43          const url = makeURL(type, "x")
     44          url[val] = hostTest.input
     45          if(hostTest.output !== null) {
     46            assert_equals(url[val], hostTest.output)
     47          } else {
     48            assert_equals(url[val], "x")
     49          }
     50        }, hostTest.input + " (using " + typeName[type] + "." + val + ")")
     51      })
     52    })
     53  }
     54 }