tor-browser

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

self-origin.sub.html (3976B)


      1 <!DOCTYPE HTML>
      2 <meta charset=utf-8>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <div id=log></div>
      6 <iframe></iframe>
      7 <iframe id="blob-test"></iframe> <!-- will get blob: URI -->
      8 <iframe src="javascript:'javascript'"></iframe>
      9 <iframe srcdoc="srcdoc"></iframe>
     10 <!-- Use the non-default HTTP port so we can make sure it gets included in
     11     self.origin -->
     12 <iframe src="http://{{domains[www1]}}:{{ports[http][1]}}{{location[path]}}/../resources/self-origin-subframe.html"></iframe>
     13 <!-- Using the Unicode version on purpose, we expect to get back the Punycode
     14     version in self.origin -->
     15 <iframe src="http://élève.{{domains[]}}:{{ports[http][1]}}{{location[path]}}/../resources/self-origin-subframe.html"></iframe>
     16 <iframe src="resources/self-origin-subframe.html" sandbox="allow-scripts"></iframe>
     17 <script type="application/javascript">
     18 test(function() {
     19  var blob = new Blob(['blob']);
     20  var url = URL.createObjectURL(blob);
     21  document.getElementById("blob-test").src = url;
     22 }, "Assigning blob url");
     23 
     24 /* Each message test is a four things: window to send message to, message to
     25   send, expected response, async test to use. */
     26 var messageTests = [
     27  [ frames[4], "getOrigin", "http://{{domains[www1]}}:{{ports[http][1]}}",
     28    async_test("Should have the right origin for cross-origin subframe") ],
     29  [ frames[4], "setDomainAndGetOrigin", "http://{{domains[www1]}}:{{ports[http][1]}}",
     30    async_test("Should have the right origin for cross-origin subframe after setting document.domain") ],
     31  [ frames[5], "getOrigin", "http://xn--lve-6lad.{{domains[]}}:{{ports[http][1]}}",
     32    async_test("Should have the right origin for IDN subframe") ],
     33  [ frames[5], "setDomainAndGetOrigin", "http://xn--lve-6lad.{{domains[]}}:{{ports[http][1]}}",
     34    async_test("Should have the right origin for IDN subframe after setting document.domain") ],
     35  [ frames[6], "getOrigin", "null",
     36    async_test("Should have the right origin for sandboxed iframe") ],
     37 ];
     38 
     39 var curTest = 0;
     40 function nextMessageTest() {
     41  if (curTest == messageTests.length) {
     42    return;
     43  }
     44 
     45  var testData = messageTests[curTest];
     46  testData[0].postMessage(testData[1], "*");
     47 }
     48 
     49 window.onmessage = function(e) {
     50  var testData = messageTests[curTest++];
     51  testData[3].step(function() {
     52    assert_equals(e.data, testData[2])
     53  });
     54  testData[3].done();
     55  nextMessageTest();
     56 }
     57 
     58 addEventListener("load", nextMessageTest);
     59 
     60 test(function() {
     61  assert_equals(self.origin, "http://{{location[host]}}");
     62 }, "We should have the right origin for our page");
     63 
     64 var t1 = async_test("about:blank subframe origins");
     65 addEventListener("load", t1.step_func_done(function() {
     66  assert_equals(frames[0].location.origin, "null",
     67                "Should have the right location origin for about:blank iframe");
     68  assert_equals(frames[0].origin, "http://{{location[host]}}",
     69                "Should have the right origin for about:blank iframe");
     70 }));
     71 
     72 var t2 = async_test("blob: subframe origins");
     73 addEventListener("load", t2.step_func_done(function() {
     74  assert_equals(frames[1].location.origin, "http://{{location[host]}}",
     75                "Should have the right location origin for blob: iframe");
     76  assert_equals(frames[1].origin, "http://{{location[host]}}",
     77                "Should have the right origin for blob: iframe");
     78 }));
     79 
     80 var t3 = async_test("javascript: subframe origins");
     81 addEventListener("load", t3.step_func_done(function() {
     82  assert_equals(frames[2].origin, "http://{{location[host]}}",
     83                "Should have the right origin for javascript: iframe");
     84 }));
     85 
     86 var t4 = async_test("srcdoc subframe origins");
     87 addEventListener("load", t4.step_func_done(function() {
     88  assert_equals(frames[3].location.origin, "null",
     89                "Should have the right location origin for srcdoc iframe");
     90  assert_equals(frames[3].origin, "http://{{location[host]}}",
     91                "Should have the right origin for srcdoc iframe");
     92 }));
     93 </script>