Bug 690208 - Test to instrument video controls when viewing a standalone video. r=dolske
☠☠ backed out by e9152e5f0708 ☠ ☠
authorJared Wein <jwein@mozilla.com>
Mon, 03 Oct 2011 20:47:14 -0700
changeset 78720 d9ff4a720e19a88a690e217e17ebc4b6ae8ce596
parent 78719 00060b8e57f76bfdf56a936465f68fb37fff8f84
child 78721 d46033973d0d92b1e20b9ac046a9b5110da821c4
push id506
push userclegnitto@mozilla.com
push dateWed, 09 Nov 2011 02:03:18 +0000
treeherdermozilla-aurora@63587fc7bb93 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs690208
milestone10.0a1
Bug 690208 - Test to instrument video controls when viewing a standalone video. r=dolske
toolkit/content/tests/widgets/Makefile.in
toolkit/content/tests/widgets/test_videocontrols_standalone.html
--- a/toolkit/content/tests/widgets/Makefile.in
+++ b/toolkit/content/tests/widgets/Makefile.in
@@ -51,16 +51,17 @@ include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES =	\
                 test_contextmenu_nested.xul \
 		test_tree_column_reorder.xul \
 		tree_shared.js \
 		test_mousecapture_area.html \
 		popup_shared.js \
                 test_videocontrols.html \
+                test_videocontrols_standalone.html \
 		test_videocontrols_video_direction.html \
 		test_videocontrols_audio_direction.html \
 		videocontrols_direction-1-ref.html \
 		videocontrols_direction-1a.html \
 		videocontrols_direction-1b.html \
 		videocontrols_direction-1c.html \
 		videocontrols_direction-1d.html \
 		videocontrols_direction-1e.html \
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/widgets/test_videocontrols_standalone.html
@@ -0,0 +1,112 @@
+<!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">
+</div>
+
+<pre id="test">
+<script type="text/javascript" src="use_large_cache.js"></script>
+<script class="testbody" type="text/javascript">
+
+/*
+ * Positions of the  UI elements, relative to the upper-left corner of the
+ * <video> box.
+ */
+const videoWidth = 320;
+const videoHeight = 240;
+const videoDuration = 3.8329999446868896;
+
+const playButtonWidth = 28;
+const playButtonHeight = 28;
+const muteButtonWidth = 33;
+const muteButtonHeight = 28;
+const durationWidth = 34;
+const scrubberWidth = videoWidth - playButtonWidth - muteButtonWidth - durationWidth;
+const scrubberHeight = 28;
+
+// Play button is on the bottom-left
+const playButtonCenterX = 0 + Math.round(playButtonWidth / 2);
+const playButtonCenterY = videoHeight - Math.round(playButtonHeight / 2);
+// Mute button is on the bottom-right
+const muteButtonCenterX = videoWidth - Math.round(muteButtonWidth / 2);
+const muteButtonCenterY = videoHeight - Math.round(muteButtonHeight / 2);
+// Scrubber bar is between the play and mute buttons. We don't need it's
+// X center, just the offset of its box.
+const scrubberOffsetX = 0 + playButtonWidth;
+const scrubberCenterY = videoHeight - Math.round(scrubberHeight / 2);
+
+function runTest(event) {
+  if (event.type == "canplaythrough")
+    return;
+
+  ok(true, "----- test #" + testnum + " -----");
+
+  switch (testnum) {
+    /*
+     * Check operation of play/pause via clicking on the video.
+     */
+    case 1:
+      // Check initial state upon load
+      is(event.type, "play", "checking event type");
+      is(video.paused, false, "checking video play state");
+      is(video.muted, false, "checking video mute state");
+
+      // Click the pause button
+      synthesizeMouse(video, playButtonCenterX, playButtonCenterY, { }, standaloneVideoWindow);
+      break;
+
+    case 2:
+      is(event.type, "pause",  "checking event type");
+      is(video.paused, true, "checking video play state");
+      is(video.muted, false,  "checking video mute state");
+
+      // Click the play button
+      synthesizeMouse(video, playButtonCenterX, playButtonCenterY, { }, standaloneVideoWindow);
+      break;
+
+    case 3:
+      is(event.type, "play", "checking event type");
+      is(video.paused, false,  "checking video play state");
+      is(video.muted, false,  "checking video mute state");
+
+      standaloneVideoWindow.close();
+      SimpleTest.finish();
+      break;
+
+    default:
+      throw "unexpected test #" + testnum + " w/ event " + event.type;
+  }
+
+  testnum++;
+}
+
+var video;
+function loadevent(event) {
+  video = standaloneVideoWindow.document.getElementsByTagName("video")[0];
+
+  // Events expected by the test.
+  video.addEventListener("play",  runTest, false);
+  video.addEventListener("pause", runTest, false);
+}
+
+var testnum = 1;
+
+var standaloneVideoWindow = window.open("video.ogg", null, "innerWidth=320,innerHeight=240");
+
+// Kick off test once video has loaded.
+standaloneVideoWindow.addEventListener("load",  loadevent, false);
+
+SimpleTest.waitForExplicitFinish();
+
+</script>
+</pre>
+</body>
+</html>