Bug 1394683 - mochitest for fullscreen video orientation lock/unlock. r?ralin draft
authorJohn Lin <jolin@mozilla.com>
Wed, 30 Aug 2017 16:53:44 +0800
changeset 656347 1505c87421f41528db74ef2060cf89c4c487d331
parent 656346 04b6be50a2526c7a26a63715f441c47e1aa1f9be
child 729108 569eceb7b19e58567269afc7b7b72979297f3ded
push id77178
push userbmo:jolin@mozilla.com
push dateThu, 31 Aug 2017 03:05:33 +0000
reviewersralin
bugs1394683
milestone57.0a1
Bug 1394683 - mochitest for fullscreen video orientation lock/unlock. r?ralin MozReview-Commit-ID: 8VV6TApPSFV
toolkit/content/tests/widgets/mochitest.ini
toolkit/content/tests/widgets/test_videocontrols_orientation.html
--- a/toolkit/content/tests/widgets/mochitest.ini
+++ b/toolkit/content/tests/widgets/mochitest.ini
@@ -44,8 +44,10 @@ skip-if = toolkit == 'android' # bug 107
 [test_videocontrols_video_direction.html]
 skip-if = os == 'win'
 [test_videocontrols_video_noaudio.html]
 skip-if = toolkit == 'android'
 [test_bug1319301.html]
 skip-if = toolkit == 'android'
 [test_bug898940.html]
 [test_videocontrols_error.html]
+[test_videocontrols_orientation.html]
+skip-if = toolkit != 'android'
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/widgets/test_videocontrols_orientation.html
@@ -0,0 +1,62 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Video controls test</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<p id="display"></p>
+
+<div id="content">
+  <video id="video" controls mozNoDynamicControls preload="metadata"></video>
+</div>
+
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+var video = document.getElementById("video");
+
+let onLoaded = event => {
+  SpecialPowers.pushPrefEnv(
+    {"set": [["full-screen-api.allow-trusted-requests-only", false]]},
+    startMediaLoad);
+}
+window.addEventListener("load", onLoaded);
+
+let startMediaLoad = () => {
+  // Kick off test once video has loaded, in its canplaythrough event handler.
+  video.src = "video.ogg";
+  video.addEventListener("canplaythrough", runTest);
+}
+
+function runTest() {
+  is(document.fullscreenElement, null, "should not be in fullscreen initially");
+  isnot(window.screen.orientation.type, "landscape-primary", "should not be in landscape");
+  isnot(window.screen.orientation.type, "landscape-secondary", "should not be in landscape");
+
+  let originalOnChange = window.screen.orientation.onchange;
+
+  window.screen.orientation.onchange = () => {
+    is(document.fullscreenElement, video);
+    ok(window.screen.orientation.type === "landscape-primary" ||
+       window.screen.orientation.type === "landscape-secondary", "should be in landscape");
+
+    window.screen.orientation.onchange = () => {
+      window.screen.orientation.onchange = originalOnChange;
+      isnot(window.screen.orientation.type, "landscape-primary", "should not be in landscape");
+      isnot(window.screen.orientation.type, "landscape-secondary", "should not be in landscape");
+      SimpleTest.finish();
+    };
+    document.mozCancelFullScreen();
+  };
+
+  video.mozRequestFullScreen();
+}
+
+</script>
+</pre>
+</body>
+</html>