tor-browser

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

orientation-reading.html (3794B)


      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 "use strict";
     10 import {
     11  makeCleanup,
     12  getOppositeOrientation,
     13 } from "./resources/orientation-utils.js";
     14 
     15 test(() => {
     16  assert_true("type" in screen.orientation, ".type must be present");
     17  assert_true("angle" in screen.orientation, ".angle must be present");
     18 }, "screen.orientation attributes are present");
     19 
     20 async function testExpectedOrientationAngles(expectedAngles) {
     21  for (const [orientation, expectedAngle] of Object.entries(expectedAngles)) {
     22    try {
     23      if (screen.orientation.type !== orientation) {
     24        await screen.orientation.lock(orientation);
     25      }
     26      assert_equals(
     27        screen.orientation.angle,
     28        expectedAngle,
     29        `Orientation angle for '${orientation}' must be ${expectedAngle} degrees`
     30      );
     31    } catch (err) {
     32      // implementation might not support locking to this orientation
     33    }
     34  }
     35 }
     36 
     37 promise_test(async (t) => {
     38  t.add_cleanup(makeCleanup());
     39  await test_driver.bless("request full screen");
     40  await document.documentElement.requestFullscreen();
     41 
     42  const expectedAnglesPortrait = {
     43    "portrait-primary": 0,
     44    "landscape-primary": 90,
     45    "portrait-secondary": 180,
     46    "landscape-secondary": 270,
     47  };
     48 
     49  await testExpectedOrientationAngles(expectedAnglesPortrait);
     50 }, "Test the orientations and associated angles when the natural orientation is 'portrait'");
     51 
     52 promise_test(async (t) => {
     53  t.add_cleanup(makeCleanup());
     54  await test_driver.bless("request full screen");
     55  await document.documentElement.requestFullscreen();
     56 
     57  const expectedAnglesLandscape = {
     58    "landscape-primary": 0,
     59    "portrait-primary": 90,
     60    "landscape-secondary": 180,
     61    "portrait-secondary": 270,
     62  };
     63 
     64  await testExpectedOrientationAngles(expectedAnglesLandscape);
     65 }, "Test the orientations and associated angles when the natural orientation is 'landscape'");
     66 
     67 test(() => {
     68  const { angle, type } = screen.orientation;
     69 
     70  assert_throws_js(
     71    TypeError,
     72    () => {
     73      screen.orientation.type = "foo";
     74    },
     75    "throws when setting ScreenOrientation.type to a string in strict mode"
     76  );
     77  assert_throws_js(
     78    TypeError,
     79    () => {
     80      screen.orientation.angle = 42;
     81    },
     82    "throws when setting ScreenOrientation.angle to a number in strict mode"
     83  );
     84 
     85  assert_equals(screen.orientation.type, type);
     86  assert_equals(screen.orientation.angle, angle);
     87 }, "Test that ScreenOrientation properties are not writable");
     88 
     89 test(() => {
     90  assert_equals(screen.orientation, screen.orientation);
     91 }, "Test that ScreenOrientation is always the same object");
     92 
     93 promise_test(async (t) => {
     94  t.add_cleanup(makeCleanup());
     95  await test_driver.bless("request full screen");
     96  await document.documentElement.requestFullscreen();
     97  const initialType = screen.orientation.type;
     98  const initialAngle = screen.orientation.angle;
     99  const orientationWatcher = new EventWatcher(t, screen.orientation, "change");
    100  const newOrientationType = getOppositeOrientation();
    101 
    102  // change event is fired before resolving promise by lock.
    103  const event = await Promise.race([
    104    orientationWatcher.wait_for("change"),
    105    screen.orientation.lock(newOrientationType),
    106  ]);
    107  assert_true(event instanceof Event, "expected event");
    108  assert_not_equals(
    109    screen.orientation.type,
    110    initialType,
    111    ".type must change"
    112  );
    113  assert_not_equals(
    114    screen.orientation.angle,
    115    initialAngle,
    116    ".angle must change"
    117  );
    118 }, "Test that ScreenOrientation's attribute values change after 'change' event fires");
    119 </script>