tor-browser

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

test_screen_orientation.html (3590B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=760735
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Screen Orientation API</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=760735">Screen Orientation API</a>
     14 <p id="display"></p>
     15 <div id="content" style="display: none">
     16 
     17 </div>
     18 <pre id="test">
     19 <script type="application/javascript">
     20 
     21 /** Tests for Screen Orientation API */
     22 
     23 // Screen Orientation API testing is problematic in that not every platform
     24 // supports orientation-locking, and locking requires running in full-screen.
     25 // So for now, only negative/sanity testing is done here, as that works globally.
     26 
     27 function unexpectedEvent(event) {
     28  ok(false, "No unexpected orientation change events received");
     29 }
     30 
     31 window.screen.addEventListener("mozorientationchange", unexpectedEvent);
     32 try {
     33  const allowedOrientations = ["portrait-primary", "portrait-secondary",
     34                               "landscape-primary", "landscape-secondary"];
     35 
     36  var initialOrientation = window.screen.mozOrientation;
     37 
     38  // Sanity tests
     39  isnot(allowedOrientations.indexOf(initialOrientation), -1,
     40        "mozOrientation is valid (value=" + initialOrientation + ")");
     41 
     42  // Negative tests
     43  ok(!window.screen.mozLockOrientation("Foobar-Bazbam"), "Cannot lock to an invalid string");
     44  is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
     45 
     46  ok(!window.screen.mozLockOrientation(""), "Cannot lock to an empty string");
     47  is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
     48 
     49  ok(!window.screen.mozLockOrientation(["Foobar", "Bazbam"]), "Cannot lock to an invalid string");
     50  is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
     51 
     52  ok(!window.screen.mozLockOrientation(["foo"]), "Cannot lock to an invalid string");
     53  is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
     54 
     55  ok(!window.screen.mozLockOrientation([""]), "Cannot lock to an empty string");
     56  is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
     57 
     58  ok(!window.screen.mozLockOrientation(42), "Cannot lock to a number");
     59  is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
     60 
     61  ok(!window.screen.mozLockOrientation(undefined), "Cannot lock to undefined");
     62  is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
     63 
     64  ok(!window.screen.mozLockOrientation(null), "Cannot lock to null");
     65  is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
     66 
     67  ok(!window.screen.mozLockOrientation({}), "Cannot lock to a non-Array object");
     68  is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
     69 
     70  ok(!window.screen.mozLockOrientation(["Foobar", 42]), "Cannot lock to a number");
     71  is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
     72 
     73  ok(!window.screen.mozLockOrientation(["Foobar", null]), "Cannot lock to null");
     74  is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
     75 
     76  ok(!window.screen.mozLockOrientation(["Foobar", undefined]), "Cannot lock to undefined");
     77  is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
     78 } catch (e) {
     79  ok(false, "Got unexpected exception: " + e);
     80 } finally {
     81  window.screen.removeEventListener("mozorientationchange", unexpectedEvent);
     82 }
     83 </script>
     84 </pre>
     85 </body>
     86 </html>