Bug 1382303 - P1. Add mochitest. r=jwwang
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 20 Jul 2017 19:09:04 +0200
changeset 418943 6568f892a5c4c0f89b40d8a051f204100740da56
parent 418942 1f66a39c19f1e8889c7fb802001b4838436f85dd
child 418944 0c6a7835fef4b3d290de4db04a0fd3322b5ba1dc
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1382303
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1382303 - P1. Add mochitest. r=jwwang MozReview-Commit-ID: ENSiDzd2SmW
dom/media/mediasource/test/mochitest.ini
dom/media/mediasource/test/test_PlayEventsAutoPlaying.html
--- a/dom/media/mediasource/test/mochitest.ini
+++ b/dom/media/mediasource/test/mochitest.ini
@@ -100,16 +100,18 @@ skip-if = ((os == "win" && os_version ==
 [test_MediaSource_disabled.html]
 [test_MultipleInitSegments.html]
 [test_MultipleInitSegments_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_OnEvents.html]
 skip-if = android_version == '22' # bug 1359010
 [test_PlayEvents.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
+[test_PlayEventsAutoPlaying.html]
+skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_ResumeAfterClearing_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_SeekableAfterEndOfStream.html]
 [test_SeekableAfterEndOfStream_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
 [test_SeekableAfterEndOfStreamSplit.html]
 [test_SeekableAfterEndOfStreamSplit_mp4.html]
 skip-if = ((os == "win" && os_version == "5.1") || (toolkit == 'android')) # Not supported on xp and android 2.3
new file mode 100644
--- /dev/null
+++ b/dom/media/mediasource/test/test_PlayEventsAutoPlaying.html
@@ -0,0 +1,74 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>MSE: basic functionality</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="mediasource.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+// This test checks that readyState is properly set and the appropriate events are being fired accordingly:
+// 1. Ensure that play/playing aren't fired before any media data been added.
+// 2. Load 1.6s of data and ensure that canplay, play and playing events are fired.
+
+runWithMSE(function(ms, el) {
+  el.controls = true;
+  el.autoplay = true;
+  var eventCounts = { play: 0, playing: 0};
+  function ForbiddenEvents(e) {
+    var v = e.target;
+    ok(v.readyState >= v.HAVE_FUTURE_DATA, "Must not have received event too early");
+    is(eventCounts[e.type], 0, "event should have only be fired once");
+    eventCounts[e.type]++;
+  }
+  once(ms, 'sourceopen').then(function() {
+    // Log events for debugging.
+    var events = ["suspend", "play", "canplay", "canplaythrough", "loadstart", "loadedmetadata",
+                  "loadeddata", "playing", "ended", "error", "stalled", "emptied", "abort",
+                  "waiting", "pause", "durationchange", "seeking", "seeked"];
+    function logEvent(e) {
+      info("got " + e.type + " event");
+    }
+    events.forEach(function(e) {
+      el.addEventListener(e, logEvent);
+    });
+    el.addEventListener("play", ForbiddenEvents);
+    el.addEventListener("playing", ForbiddenEvents);
+
+    ok(true, "Receive a sourceopen event");
+    var videosb = ms.addSourceBuffer("video/mp4");
+    is(el.readyState, el.HAVE_NOTHING, "readyState is HAVE_NOTHING");
+    var promises = [];
+    promises.push(fetchAndLoad(videosb, 'bipbop/bipbop_video', ['init'], '.mp4'));
+    promises.push(once(el, 'loadedmetadata'));
+    Promise.all(promises)
+    .then(function() {
+       ok(true, "got loadedmetadata event");
+       var promises = [];
+       promises.push(once(el, 'loadeddata'));
+       promises.push(once(el, 'canplay'));
+       promises.push(once(el, 'play'));
+       promises.push(once(el, 'playing'));
+       promises.push(once(el, 'ended'));
+       // We're only adding 1.6s worth of data, not enough for readyState to change to HAVE_ENOUGH_DATA
+       // So we end the media source so that all the playable data is available.
+       promises.push(fetchAndLoad(videosb, 'bipbop/bipbop_video', range(1, 3), '.m4s')
+                     .then(() => ms.endOfStream()));
+       return Promise.all(promises);
+    })
+    .then(function() {
+      ok(true, "got all required event");
+      SimpleTest.finish();
+    })
+  });
+});
+
+</script>
+</pre>
+</body>
+</html>