tor-browser

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

test_fullscreen-api.html (5224B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for Bug 545812</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      7  <script src="/tests/SimpleTest/EventUtils.js"></script>
      8  <script type="application/javascript" src="file_fullscreen-utils.js"></script>
      9  <style>
     10  body {
     11    background-color: black;
     12  }
     13  </style>
     14 </head>
     15 <body>
     16 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=545812">Mozilla Bug 545812</a>
     17 <p id="display"></p>
     18 <div id="content" style="display: none">
     19 
     20 </div>
     21 <pre id="test">
     22 <script type="application/javascript">
     23 
     24 /** Tests for Bug 545812 */
     25 SimpleTest.requestFlakyTimeout("untriaged");
     26 
     27 // Run the tests which go full-screen in new windows, as mochitests normally
     28 // run in an iframe, which by default will not have the allowfullscreen
     29 // attribute set, so full-screen won't work.
     30 var gTestWindows = [
     31  { test: "file_fullscreen-single.html" },
     32  { test: "file_fullscreen-multiple.html",
     33    prefs: [["full-screen-api.exit-on.windowRaise", false],
     34            ["full-screen-api.exit-on.windowOpen", false]] },
     35  { test: "file_fullscreen-rollback.html" },
     36  { test: "file_fullscreen-esc-exit.html" },
     37  { test: "file_fullscreen-denied.html" },
     38  { test: "file_fullscreen-api.html" },
     39  { test: "file_fullscreen-hidden.html" },
     40  { test: "file_fullscreen-focus.html" },
     41  { test: "file_fullscreen-svg-element.html" },
     42  { test: "file_fullscreen-navigation.html" },
     43  { test: "file_fullscreen-scrollbar.html" },
     44  { test: "file_fullscreen-selector.html" },
     45  { test: "file_fullscreen-shadowdom.html" },
     46  { test: "file_fullscreen-top-layer.html" },
     47  { test: "file_fullscreen-backdrop.html" },
     48  { test: "file_fullscreen-nested.html" },
     49  { test: "file_fullscreen-prefixed.html" },
     50  { test: "file_fullscreen-lenient-setters.html" },
     51  { test: "file_fullscreen-table.html" },
     52  { test: "file_fullscreen-event-order.html" },
     53  { test: "file_fullscreen-featurePolicy.html",
     54    prefs: [["dom.security.featurePolicy.header.enabled", true],
     55            ["dom.security.featurePolicy.webidl.enabled", true]] },
     56  { test: "file_fullscreen-async.html" },
     57  { test: "file_fullscreen-sub-iframe.html" },
     58  { test: "file_fullscreen-with-full-zoom.html" },
     59  { test: "file_fullscreen-resize.html" },
     60 ];
     61 
     62 var testWindow = null;
     63 var gTestIndex = 0;
     64 
     65 function finish() {
     66  SimpleTest.finish();
     67 }
     68 
     69 function nextTest() {
     70  if (testWindow) {
     71    info("Waiting for focus to return to main window");
     72    window.addEventListener("focus", function() {
     73      info("main window focused, starting next test");
     74      SimpleTest.executeSoon(runNextTest);
     75    }, {once: true});
     76    info("testWindow.close()");
     77    testWindow.close();
     78  } else {
     79    SimpleTest.executeSoon(runNextTest);
     80  }
     81 }
     82 
     83 function waitForEvent(eventTarget, eventName, checkFn, callback) {
     84  eventTarget.addEventListener(eventName, function listener(event) {
     85    if (checkFn && !checkFn(event)) {
     86      return;
     87    }
     88    eventTarget.removeEventListener(eventName, listener);
     89    callback();
     90  });
     91 }
     92 
     93 function runNextTest() {
     94  if (gTestIndex < gTestWindows.length) {
     95    let test = gTestWindows[gTestIndex];
     96    let promise = ("prefs" in test)
     97                    ? SpecialPowers.pushPrefEnv({"set": test.prefs})
     98                    : Promise.resolve();
     99    promise.then(function() {
    100      info(`Run test ${test.test}`);
    101      testWindow = window.open(test.test, "", "width=500,height=500,scrollbars=yes");
    102      // We'll wait for the window to load, then make sure our window is refocused
    103      // before starting the test, which will get kicked off on "focus".
    104      // This ensures that we're essentially back on the primary "desktop" on
    105      // OS X Lion before we run the test.
    106      waitForLoadAndPaint(testWindow, function() {
    107        SimpleTest.waitForFocus(function() {
    108          info("Were focused");
    109          // For the platforms that support reporting occlusion state (e.g. Mac),
    110          // we should wait until the docshell has been activated again,
    111          // otherwise, the fullscreen request might be denied.
    112          if (testWindow.document.hidden) {
    113            info("Waiting for document to unhide");
    114            waitForEvent(testWindow.document, "visibilitychange", () => {
    115              return !testWindow.document.hidden;
    116            }, testWindow.begin);
    117            return;
    118          }
    119          testWindow.begin();
    120        }, testWindow);
    121      });
    122    });
    123    gTestIndex++;
    124  } else {
    125    SimpleTest.finish();
    126  }
    127 }
    128 
    129 try {
    130  window.fullScreen = true;
    131 } catch (e) {
    132 }
    133 is(window.fullScreen, false, "Shouldn't be able to set window fullscreen from content");
    134 // Ensure the full-screen api is enabled, and will be disabled on test exit.
    135 // Disable the requirement for trusted contexts only, so the tests are easier
    136 // to write
    137 addLoadEvent(function() {
    138  SpecialPowers.pushPrefEnv({
    139      "set": [
    140        ["full-screen-api.enabled", true],
    141        ["full-screen-api.allow-trusted-requests-only", false],
    142        ["full-screen-api.transition-duration.enter", "0 0"],
    143        ["full-screen-api.transition-duration.leave", "0 0"]
    144      ]}, nextTest);
    145 });
    146 SimpleTest.waitForExplicitFinish();
    147 </script>
    148 </pre>
    149 </body>
    150 </html>