tor-browser

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

frameElement.sub.html (3453B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <meta charset="utf-8"/>
      5    <title>HTML Test: window.frameElement</title>
      6    <link rel="author" title="Intel" href="http://www.intel.com/" />
      7    <script src="/resources/testharness.js"></script>
      8    <script src="/resources/testharnessreport.js"></script>
      9  </head>
     10  <body>
     11    <!-- t1 (same-origin)-->
     12    <iframe id="iframe_0"></iframe>
     13    <iframe id="iframe_1" src="./resources/frameElement-nested-frame.html"></iframe>
     14    <object id="object_id" name="object_name" type="text/html" data="about:blank"></object>
     15    <embed id="embed_id" name="embed_name" type="image/svg+xml" src="/images/green.svg" />
     16 
     17    <!-- t2 (cross-origin) -->
     18    <iframe name="iframe_2" src="http://{{hosts[alt][]}}:{{ports[http][0]}}/html/browsers/windows/nested-browsing-contexts/resources/frameElement-nested-frame.html"></iframe>
     19 
     20    <!-- t3 (cross-origin) -->
     21    <iframe id="iframe_3" src="http://{{hosts[alt][]}}:{{ports[http][0]}}/html/browsers/windows/nested-browsing-contexts/resources/frameElement-window-post.html"></iframe>
     22 
     23    <script>
     24      test(function() {
     25        assert_equals(window.frameElement, null,
     26          "The frameElement attribute should be null.");
     27      }, "The window's frameElement attribute must return null if it is not a nested browsing context");
     28 
     29      var t1 = async_test("The window's frameElement attribute must return its container element if it is a nested browsing context");
     30      window.addEventListener("load", t1.step_func_done(function() {
     31        assert_equals(frames[0].frameElement, document.getElementById("iframe_0"),
     32          "The frameElement attribute should be the first iframe element.");
     33        assert_equals(window["object_name"].frameElement, document.getElementById("object_id"),
     34          "The frameElement attribute should be the object element.");
     35        assert_equals(window["embed_name"].frameElement, document.getElementById("embed_id"),
     36          "The frameElement attribute should be the embed element.");
     37        assert_equals(document.getElementById("iframe_1").contentWindow[0].frameElement,
     38          document.getElementById("iframe_1").contentDocument.getElementById("f1"),
     39          "The frameElement attribute should be the frame element in 'resources/frameElement-nested-frame.html'.");
     40      }));
     41 
     42      var t2 = async_test("The SecurityError must be thrown if the window accesses to frameElement attribute of a Window which does not have the same effective script origin");
     43      window.addEventListener("load", t2.step_func_done(function() {
     44        assert_throws_dom("SecurityError", function() {
     45            frames["iframe_2"].frameElement;
     46          },
     47          "The SecurityError exception should be thrown.");
     48      }));
     49 
     50      var t3 = async_test("The window's frameElement attribute must return null if the container's document does not have the same effective script origin");
     51      window.addEventListener("load", function() {
     52        window.addEventListener("message", function(event) {
     53          var data = JSON.parse(event.data);
     54          if (data.name == "testcase3") {
     55            t3.step(function() {
     56              assert_equals(data.result, "window.frameElement = null",
     57                "The frameElement attribute should be null.");
     58              t3.done();
     59            });
     60          }
     61        }, false);
     62        document.getElementById("iframe_3").contentWindow.postMessage(null, "*");
     63      })
     64    </script>
     65  </body>
     66 </html>