tor-browser

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

no-browsing-context.window.js (2418B)


      1 test(() => {
      2  const frame = document.body.appendChild(document.createElement("iframe")),
      3        win = frame.contentWindow,
      4        loc = win.location;
      5  frame.remove();
      6  assert_equals(win.location, loc);
      7 }, "Window and Location are 1:1 after browsing context removal");
      8 
      9 function bcLessLocation() {
     10  const frame = document.body.appendChild(document.createElement("iframe")),
     11        win = frame.contentWindow,
     12        loc = win.location;
     13  frame.remove();
     14  return loc;
     15 }
     16 
     17 [
     18  {
     19    "property": "href",
     20    "expected": "about:blank",
     21    "values": ["https://example.com/", "/", "http://test:test/", "test test", "test:test", "chrome:fail"]
     22  },
     23  {
     24    "property": "protocol",
     25    "expected": "about:",
     26    "values": ["http", "about", "test"]
     27  },
     28  {
     29    "property": "host",
     30    "expected": "",
     31    "values": ["example.com", "test test", "()"]
     32  },
     33  {
     34    "property": "hostname",
     35    "expected": "",
     36    "values": ["example.com"]
     37  },
     38  {
     39    "property": "port",
     40    "expected": "",
     41    "values": ["80", "", "443", "notaport"]
     42  },
     43  {
     44    "property": "pathname",
     45    "expected": "blank",
     46    "values": ["/", "x"]
     47  },
     48  {
     49    "property": "search",
     50    "expected": "",
     51    "values": ["test"]
     52  },
     53  {
     54    "property": "hash",
     55    "expected": "",
     56    "values": ["test", "#"]
     57  }
     58 ].forEach(testSetup => {
     59  testSetup.values.forEach(value => {
     60  	test(() => {
     61  	  const loc = bcLessLocation();
     62  	  loc[testSetup.property] = value;
     63  	  assert_equals(loc[testSetup.property], testSetup.expected);
     64  	}, "Setting `" + testSetup.property + "` to `" + value + "` of a `Location` object sans browsing context is a no-op");
     65  });
     66 });
     67 
     68 test(() => {
     69  const loc = bcLessLocation();
     70  assert_equals(loc.origin, "null");
     71 }, "Getting `origin` of a `Location` object sans browsing context should be \"null\"");
     72 
     73 ["assign", "replace", "reload"].forEach(method => {
     74  ["about:blank", "https://example.com/", "/", "http://test:test/", "test test", "test:test", "chrome:fail"].forEach(value => {
     75    test(() => {
     76      const loc = bcLessLocation();
     77      loc[method](value);
     78      assert_equals(loc.href, "about:blank");
     79    }, "Invoking `" + method + "` with `" + value + "` on a `Location` object sans browsing context is a no-op");
     80  });
     81 });
     82 
     83 test(() => {
     84  const loc = bcLessLocation();
     85  assert_array_equals(loc.ancestorOrigins, []);
     86 }, "Getting `ancestorOrigins` of a `Location` object sans browsing context should be []");