tor-browser

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

onchange-event.html (1897B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8" />
      3 <meta viewport="width=device-width, initial-scale=1" />
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/resources/testdriver.js"></script>
      7 <script src="/resources/testdriver-vendor.js"></script>
      8 <script type="module">
      9 import { makeCleanup } from "./resources/orientation-utils.js";
     10 promise_test(async t => {
     11  t.add_cleanup(makeCleanup());
     12  await test_driver.bless("request full screen");
     13  await document.documentElement.requestFullscreen();
     14  const type = screen.orientation.type.startsWith("portrait") ? "portrait" : "landscape";
     15  screen.orientation.onchange = t.unreached_func("change event should not be fired");
     16  await screen.orientation.lock(type);
     17  assert_true(screen.orientation.type.startsWith(type));
     18 }, "Test that orientationchange event is not fired when the orientation does not change.");
     19 
     20 promise_test(async t => {
     21  t.add_cleanup(makeCleanup());
     22  await test_driver.bless("request full screen");
     23  await document.documentElement.requestFullscreen();
     24  let orientations = [
     25    'portrait',
     26    'landscape',
     27  ];
     28  if (screen.orientation.type.startsWith('portrait')) {
     29    orientations = orientations.reverse();
     30  }
     31  const orientationWatcher = new EventWatcher(t, screen.orientation, 'change');
     32 
     33  for (const orientation of orientations) {
     34    // change event is fired before resolving promise by lock.
     35    let lockPromise = screen.orientation.lock(orientation);
     36    const result = await Promise.race([
     37      lockPromise,
     38      orientationWatcher.wait_for('change'),
     39    ]);
     40    assert_true(result instanceof Event, "The event must be fired first.");
     41    assert_true(screen.orientation.type.startsWith(orientation), "The orientation must match");
     42    await lockPromise;
     43  }
     44 }, "Test that orientationchange event is fired when the orientation changes.");
     45 </script>