tor-browser

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

iframe-allowfullscreen.html (4640B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>Check how allowfullscreen affects fullscreen enabled flag</title>
      4 <link rel="author" title="Xidorn Quan" href="https://www.upsuper.org">
      5 <link rel="author" title="Mozilla" href="https://www.mozilla.org">
      6 <link rel="help" href="https://html.spec.whatwg.org/multipage/browsing-the-web.html#initialise-the-document-object">
      7 <link rel="help" href="https://fullscreen.spec.whatwg.org/#fullscreen-enabled-flag">
      8 <script src="/resources/testharness.js"></script>
      9 <script src="/resources/testharnessreport.js"></script>
     10 
     11 <div id="log"></div>
     12 <script>
     13  // This returns a data URL (cross-origin with the containing document) which
     14  // advances a counter, and reports the counter value together with the
     15  // document's fullscreenEnabled state, every time it receives a postMessage.
     16  function getSourceForCrossOriginPage(initial_count) {
     17    var page_contents = "<html><body><script>var count="+initial_count+";window.addEventListener('message',function(){parent.postMessage({'count':count++,'fullscreenEnabled':document.fullscreenEnabled},'*');});</scr"+"ipt></body></html>";
     18    return "data:text/html;base64,"+btoa(page_contents);
     19  }
     20 
     21  async_test(function(t) {
     22    var iframe = document.createElement("iframe");
     23    iframe.src = "support/blank.htm";
     24    var eventWatcher = new EventWatcher(t, iframe, "load");
     25    document.body.appendChild(iframe);
     26    t.add_cleanup(function() {
     27      document.body.removeChild(iframe);
     28    });
     29 
     30    assert_true(document.fullscreenEnabled, "Top level document has fullscreen enabled flag set");
     31    eventWatcher.wait_for("load").then(t.step_func_done(function() {
     32      assert_true(iframe.contentDocument.fullscreenEnabled, "Document inside same-origin iframe without allowfullscreen attribute should still have fullscreen enabled flag set");
     33    }));
     34  }, "iframe-same-origin-allowfullscreen");
     35 
     36  async_test(function(t) {
     37    var iframe = document.createElement("iframe");
     38    iframe.src = getSourceForCrossOriginPage(0);
     39 
     40    iframe.addEventListener('load', function() {
     41      // Request the fullscreenEnabled state whenever the frame loads
     42      iframe.contentWindow.postMessage(true,"*");
     43    });
     44 
     45    window.addEventListener('message', this.step_func(function(msg) {
     46      if (msg.data.count == 0) {
     47        assert_false(msg.data.fullscreenEnabled, "Document inside cross-origin iframe without allowfullscreen attribute should not have fullscreen enabled flag set");
     48        iframe.setAttribute("allowfullscreen", "");
     49        iframe.contentWindow.postMessage(true,"*"); // Request state again
     50      } else if (msg.data.count == 1) {
     51        assert_false(msg.data.fullscreenEnabled, "Fullscreen should be denied when allowfullscreen attribute is added, before reload");
     52        iframe.src = getSourceForCrossOriginPage(2); // Reload the frame
     53      } else if (msg.data.count == 2) {
     54        assert_true(msg.data.fullscreenEnabled, "Fullscreen should be allowed when allowfullscreen attribute is added, after reload");
     55        iframe.removeAttribute("allowfullscreen");
     56        iframe.contentWindow.postMessage(true,"*"); // Request state again
     57      } else if (msg.data.count == 3) {
     58        assert_true(msg.data.fullscreenEnabled, "Fullscreen should be allowed when allowfullscreen attribute is removed, before reload");
     59        iframe.src = getSourceForCrossOriginPage(4); // Reload the frame
     60      } else if (msg.data.count == 4) {
     61        assert_false(msg.data.fullscreenEnabled, "Fullscreen should be denied when allowfullscreen attribute is removed, after reload");
     62        t.done();
     63      }
     64    }));
     65 
     66    document.body.appendChild(iframe);
     67    t.add_cleanup(function() {
     68      document.body.removeChild(iframe);
     69    });
     70  }, "iframe-cross-origin-allowfullscreen");
     71 
     72  /* Fullscreen enabled flag with about:blank */
     73 
     74  function test_allowfullscreen_noload(setup_iframe, check) {
     75    var iframe = document.createElement("iframe");
     76    setup_iframe(iframe);
     77    document.body.appendChild(iframe);
     78    check(iframe.contentDocument);
     79    document.body.removeChild(iframe);
     80  }
     81 
     82  test(function() {
     83    test_allowfullscreen_noload(function() {}, function(doc) {
     84      assert_true(doc.fullscreenEnabled, "Fullscreen should still be enabled in same-origin document without allowfullscreen attribute");
     85    });
     86  }, "iframe-noload-noallowfullscreen");
     87 
     88  test(function() {
     89    test_allowfullscreen_noload(function(iframe) {
     90      iframe.setAttribute("allowfullscreen", true);
     91    }, function(doc) {
     92      assert_true(doc.fullscreenEnabled, "Fullscreen should be enabled with allowfullscreen attribute");
     93    });
     94  }, "iframe-noload-allowfullscreen");
     95 </script>