1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/test/test_screen_orientation.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=760735 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Test for Screen Orientation API</title> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=760735">Screen Orientation API</a> 1.17 +<p id="display"></p> 1.18 +<div id="content" style="display: none"> 1.19 + 1.20 +</div> 1.21 +<pre id="test"> 1.22 +<script type="application/javascript"> 1.23 + 1.24 +/** Tests for Screen Orientation API **/ 1.25 + 1.26 +// Screen Orientation API testing is problematic in that not every platform 1.27 +// supports orientation-locking, and locking requires running in full-screen. 1.28 +// So for now, only negative/sanity testing is done here, as that works globally. 1.29 + 1.30 +function unexpectedEvent(event) { 1.31 + ok(false, "No unexpected orientation change events received"); 1.32 +} 1.33 + 1.34 +window.screen.addEventListener("mozorientationchange", unexpectedEvent); 1.35 +try { 1.36 + const allowedOrientations = ["portrait-primary", "portrait-secondary", 1.37 + "landscape-primary", "landscape-secondary"]; 1.38 + 1.39 + var initialOrientation = window.screen.mozOrientation; 1.40 + 1.41 + // Sanity tests 1.42 + isnot(allowedOrientations.indexOf(initialOrientation), -1, 1.43 + "mozOrientation is valid (value=" + initialOrientation + ")"); 1.44 + 1.45 + // Negative tests 1.46 + ok(!window.screen.mozLockOrientation("Foobar-Bazbam"), "Cannot lock to an invalid string"); 1.47 + is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged"); 1.48 + 1.49 + ok(!window.screen.mozLockOrientation(""), "Cannot lock to an empty string"); 1.50 + is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged"); 1.51 + 1.52 + ok(!window.screen.mozLockOrientation(["Foobar", "Bazbam"]), "Cannot lock to an invalid string"); 1.53 + is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged"); 1.54 + 1.55 + ok(!window.screen.mozLockOrientation(["foo"]), "Cannot lock to an invalid string"); 1.56 + is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged"); 1.57 + 1.58 + ok(!window.screen.mozLockOrientation([""]), "Cannot lock to an empty string"); 1.59 + is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged"); 1.60 + 1.61 + ok(!window.screen.mozLockOrientation(42), "Cannot lock to a number"); 1.62 + is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged"); 1.63 + 1.64 + ok(!window.screen.mozLockOrientation(undefined), "Cannot lock to undefined"); 1.65 + is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged"); 1.66 + 1.67 + ok(!window.screen.mozLockOrientation(null), "Cannot lock to null"); 1.68 + is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged"); 1.69 + 1.70 + ok(!window.screen.mozLockOrientation({}), "Cannot lock to a non-Array object"); 1.71 + is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged"); 1.72 + 1.73 + ok(!window.screen.mozLockOrientation(["Foobar", 42]), "Cannot lock to a number"); 1.74 + is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged"); 1.75 + 1.76 + ok(!window.screen.mozLockOrientation(["Foobar", null]), "Cannot lock to null"); 1.77 + is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged"); 1.78 + 1.79 + ok(!window.screen.mozLockOrientation(["Foobar", undefined]), "Cannot lock to undefined"); 1.80 + is(window.screen.mozOrientation, initialOrientation, "Orientation is unchanged"); 1.81 +} catch (e) { 1.82 + ok(false, "Got unexpected exception: " + e); 1.83 +} finally { 1.84 + window.screen.removeEventListener("mozorientationchange", unexpectedEvent); 1.85 +} 1.86 +</script> 1.87 +</pre> 1.88 +</body> 1.89 +</html>