Bug 1317570 - Add a mochitest to test 'ended' fires only once when seeking to the end. r=cpearce
authorJW Wang <jwwang@mozilla.com>
Tue, 15 Nov 2016 10:41:42 +0800
changeset 439704 d282d9e8232adadbf9664f2aa2cc18ceeb0b35af
parent 439703 1f9d289e8272f27659bf980528b6d89f61f7ac87
child 439705 163281db1563a70e3e9c15669c67d478d2223991
push id36064
push userrthijssen@mozilla.com
push dateWed, 16 Nov 2016 13:38:27 +0000
reviewerscpearce
bugs1317570
milestone53.0a1
Bug 1317570 - Add a mochitest to test 'ended' fires only once when seeking to the end. r=cpearce MozReview-Commit-ID: KRm1shND6lL
dom/media/test/mochitest.ini
dom/media/test/test_seek-14.html
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -833,16 +833,17 @@ skip-if = true # bug 1021673
 [test_seek-6.html]
 [test_seek-7.html]
 [test_seek-8.html]
 [test_seek-9.html]
 [test_seek-10.html]
 [test_seek-11.html]
 [test_seek-12.html]
 [test_seek-13.html]
+[test_seek-14.html]
 [test_seekable1.html]
 [test_seekLies.html]
 [test_seekToNextFrame.html]
 tags=seektonextframe
 [test_source.html]
 [test_source_media.html]
 [test_source_null.html]
 [test_source_write.html]
copy from dom/media/test/test_seek-13.html
copy to dom/media/test/test_seek-14.html
--- a/dom/media/test/test_seek-13.html
+++ b/dom/media/test/test_seek-14.html
@@ -6,67 +6,38 @@
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <script type="text/javascript" src="manifest.js"></script>
   <script type="text/javascript" src="seek_support.js"></script>
 </head>
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
-// The data being used in these tests is specified in manifest.js.
-// The functions to build the test array and to run a specific test are in
-//      seek_support.js.
+const SEEK_TEST_NUMBER = 14;
 
-const SEEK_TEST_NUMBER = 13;
-
-function test_seek13(v, seekTime, is, ok, finish) {
-var completed = false;
+function test_seek14(v, seekTime, is, ok, finish) {
+  var completed = false;
 
-function startTest() {
-  if (completed)
-    return;
-  ok(!v.seeking, "seeking should default to false");
-  v.currentTime = v.duration;
-  is(v.currentTime, v.duration, "currentTime must report seek target immediately");
-  is(v.seeking, true, "seeking flag on start should be true");
-}
-
-function seekStarted() {
-  if (completed)
-    return;
-  //is(v.currentTime, v.duration, "seeking: currentTime must be duration");
-  ok(Math.abs(v.currentTime - v.duration) < 0.01,
-     "seeking: currentTime (" + v.currentTime + ") must be duration (" + v.duration + ")");
-}
+  function startTest() {
+    v.play();
+    v.currentTime = v.duration;
+  }
 
-function seekEnded() {
-  if (completed)
-    return;
-  //is(v.currentTime, v.duration, "seeked: currentTime must be duration");
-  ok(Math.abs(v.currentTime - v.duration) < 0.01,
-     "seeked: currentTime (" + v.currentTime + ") must be duration (" + v.duration + ")");
-  is(v.seeking, false, "seeking flag on end should be false");
-}
+  function playbackEnded() {
+    if (completed) {
+      ok(false, "'ended' should only fire once.");
+      return;
+    }
+    completed = true;
+    // Finish the test after 700ms. We should receive only one 'ended' event.
+    setTimeout(finish, 700);
+  }
 
-function playbackEnded() {
-  if (completed)
-    return;
-  completed = true;
-  //is(v.currentTime, v.duration, "ended: currentTime must be duration");
-  ok(Math.abs(v.currentTime - v.duration) < 0.01,
-     "ended: currentTime (" + v.currentTime + ") must be duration (" + v.duration + ")");
-  is(v.seeking, false, "seeking flag on end should be false");
-  is(v.ended, true, "ended must be true");
-  finish();
-}
-
-v.addEventListener("loadedmetadata", startTest, false);
-v.addEventListener("seeking", seekStarted, false);
-v.addEventListener("seeked", seekEnded, false);
-v.addEventListener("ended", playbackEnded, false);
+  v.addEventListener("loadedmetadata", startTest, false);
+  v.addEventListener("ended", playbackEnded, false);
 }
 
 manager.runTests(createTestArray(), startTest);
 
 </script>
 </pre>
 </body>
 </html>