tor-browser

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

test_lock_orientation_with_pending_fullscreen.html (3508B)


      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1744288
      5 -->
      6 <head>
      7 <meta charset="utf-8">
      8 <title>Test for Bug 1744288</title>
      9 <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=174488">Mozilla Bug 1744288</a>
     14 <script>
     15 const kIsWin = navigator.platform.indexOf("Win") == 0;
     16 
     17 add_task(async function test_pending_fullscreen_request() {
     18  if (kIsWin) {
     19    // CI won't run on Windows tablet mode.
     20    ok(true, "Skip on Windows");
     21    return;
     22  }
     23 
     24  await SpecialPowers.pushPrefEnv({
     25    set: [["dom.screenorientation.allow-lock", true]]
     26  });
     27 
     28  SpecialPowers.wrap(document.documentElement).requestFullscreen();
     29  let gotException = false;
     30  try {
     31    await window.screen.orientation.lock("any");
     32  } catch (e) {
     33    gotException = true;
     34  }
     35  ok(!gotException, "No exception even if fullscreen request is pending.");
     36 
     37  window.screen.orientation.unlock();
     38  try {
     39    await document.exitFullscreen();
     40  } catch (e) {
     41  }
     42 });
     43 
     44 // Gecko doesn't allow orientation lock without fullscreen by default
     45 add_task(async function test_no_fullscreen_request() {
     46  if (kIsWin) {
     47    // CI won't run on Windows tablet mode.
     48    ok(true, "Skip on Windows");
     49    return;
     50  }
     51 
     52  await SpecialPowers.pushPrefEnv({
     53    set: [["dom.screenorientation.allow-lock", true]]
     54  });
     55 
     56  let gotException = false;
     57  try {
     58    await window.screen.orientation.lock("any");
     59  } catch (e) {
     60    gotException = true;
     61  }
     62  ok(gotException, "Should throw an exception when fullscreen request is nothing.");
     63 });
     64 
     65 // Gecko doesn't allow orientation lock after fullscreen request is canceled
     66 add_task(async function test_cancel_pending_fullscreen_request() {
     67  if (kIsWin) {
     68    // CI won't run on Windows tablet mode.
     69    ok(true, "Skip on Windows");
     70    return;
     71  }
     72 
     73  await SpecialPowers.pushPrefEnv({
     74    set: [["dom.screenorientation.allow-lock", true]]
     75  });
     76 
     77  const element = document.createElement("div");
     78  document.body.appendChild(element);
     79  const promiseFullscree = SpecialPowers.wrap(element).requestFullscreen().then(() => {
     80    ok(false, "Fullscreen request should be canceled.");
     81  }, () => {
     82    ok(true, "Fullscreen request is canceled.");
     83  });
     84  let gotException = false;
     85  try {
     86    const promise = window.screen.orientation.lock("any");
     87    // Removing element causes that fullscreen request is canceled.
     88    document.body.removeChild(element);
     89    await promise;
     90  } catch (e) {
     91    gotException = true;
     92  }
     93  ok(gotException, "Should throw an exception when pending fullscreen request is canceled.");
     94  await promiseFullscree;
     95 
     96  try {
     97    window.screen.orientation.unlock();
     98    await document.exitFullscreen();
     99  } catch (e) {
    100  }
    101 });
    102 
    103 add_task(async function test_dont_leak_memory_with_pending_fullscreen_request() {
    104  await SpecialPowers.pushPrefEnv({
    105    set: [["dom.screenorientation.allow-lock", true]]
    106  });
    107 
    108  const iframe = document.createElement("iframe");
    109  iframe.setAttribute("allowFullScreen", "");
    110  iframe.src = "file_lock_orientation_with_pending_fullscreen.html";
    111 
    112  const promise = new Promise(resolve => {
    113    window.addEventListener("message", function handler(e) {
    114      if (e.data === "pending") {
    115        document.body.removeChild(iframe);
    116        window.removeEventListener("message", handler);
    117        resolve();
    118      }
    119    });
    120  });
    121 
    122  document.body.appendChild(iframe);
    123  await promise;
    124 });
    125 </script>
    126 </body>
    127 </html>