dom/base/test/test_screen_orientation.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial