Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 type="application/javascript" 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">
17 </div>
18 <pre id="test">
19 <script type="application/javascript">
21 /** Tests for Screen Orientation API **/
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.
27 function unexpectedEvent(event) {
28 ok(false, "No unexpected orientation change events received");
29 }
31 window.screen.addEventListener("mozorientationchange", unexpectedEvent);
32 try {
33 const allowedOrientations = ["portrait-primary", "portrait-secondary",
34 "landscape-primary", "landscape-secondary"];
36 var initialOrientation = window.screen.mozOrientation;
38 // Sanity tests
39 isnot(allowedOrientations.indexOf(initialOrientation), -1,
40 "mozOrientation is valid (value=" + initialOrientation + ")");
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");
46 ok(!window.screen.mozLockOrientation(""), "Cannot lock to an empty string");
47 is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
49 ok(!window.screen.mozLockOrientation(["Foobar", "Bazbam"]), "Cannot lock to an invalid string");
50 is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
52 ok(!window.screen.mozLockOrientation(["foo"]), "Cannot lock to an invalid string");
53 is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
55 ok(!window.screen.mozLockOrientation([""]), "Cannot lock to an empty string");
56 is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
58 ok(!window.screen.mozLockOrientation(42), "Cannot lock to a number");
59 is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
61 ok(!window.screen.mozLockOrientation(undefined), "Cannot lock to undefined");
62 is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
64 ok(!window.screen.mozLockOrientation(null), "Cannot lock to null");
65 is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
67 ok(!window.screen.mozLockOrientation({}), "Cannot lock to a non-Array object");
68 is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
70 ok(!window.screen.mozLockOrientation(["Foobar", 42]), "Cannot lock to a number");
71 is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
73 ok(!window.screen.mozLockOrientation(["Foobar", null]), "Cannot lock to null");
74 is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged");
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>