tor-browser

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

location-protocol-setter-with-colon.sub.html (2173B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title></title>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 <div id=log></div>
      7 <iframe id="existing" src="resources/post-your-protocol.html?existing"></iframe>
      8 <iframe id="http-and-gunk" src="resources/post-your-protocol.html?http-and-gunk"></iframe>
      9 <!-- iframe id="https-and-gunk" src="resources/post-your-protocol.html?https-and-gunk"></iframe -->
     10 <script>
     11 // NOTE: we do not listen to message events until our load event fires, so we
     12 // only get them for the things we actually care about.
     13 var wrapper_test = async_test("General setup");
     14 var tests = {
     15  "existing": { test: async_test("Set location.protocol = location.protocol"),
     16                result: location.protocol },
     17  "http-and-gunk": { test:  async_test("Set location.protocol to http:gunk"),
     18                     result: "http:" },
     19  // We should really test the "https:gunk" case too, and assert that it ends up
     20  // with a protocol of "https:", but can't.  See comments below for why.
     21 };
     22 
     23 function messageListener(e) {
     24  var data = e.data;
     25  var id = data.id;
     26  var t = tests[id].test;
     27  t.step(function() {
     28    assert_equals(data.protocol, tests[id].result, "Protocol should match");
     29  })
     30  t.done();
     31 }
     32 
     33 addEventListener("load", wrapper_test.step_func_done(function() {
     34  addEventListener("message", messageListener);
     35 
     36  tests["existing"].test.step(function() {
     37    var loc = document.getElementById("existing").contentWindow.location;
     38    loc.protocol = loc.protocol;
     39  });
     40  tests["http-and-gunk"].test.step(function() {
     41    var loc = document.getElementById("http-and-gunk").contentWindow.location;
     42    loc.protocol = "http:gunk";
     43  });
     44  // I wish we could test the https bit, but can't figure out a non-racy way to
     45  // do it, because we need to change both protocol (to https) _and_ port to
     46  // {{ports[https][0]}} to get a successful load unless we're running on the
     47  // default http port, but the setter uses the current value, which doesn't get
     48  // updated sync, as the url to start with for the set.  Oh, and there's no
     49  // good way to detect when the port set is "done" either.
     50 }));
     51 
     52 </script>