Bug 1301426 part 14 - test case 13; r?jwwang draft
authorKaku Kuo <kaku@mozilla.com>
Tue, 11 Oct 2016 15:27:40 +0800
changeset 448133 a83ac9c4a441d27c373f10e532c46e23dd8211e9
parent 448132 569a25e413aa06df7dac2a161033e32ae6a23032
child 448134 69ddb2aa9bc74d2eeb8467bea6359f4469e60751
push id38269
push userbmo:kaku@mozilla.com
push dateFri, 09 Dec 2016 07:05:38 +0000
reviewersjwwang
bugs1301426
milestone53.0a1
Bug 1301426 part 14 - test case 13; r?jwwang Case: re-invoke the load() on an element which had dispatched a task to resolve a promise. Expected result: the already dispatched promise should still be resolved. MozReview-Commit-ID: CGthPmPeaif
dom/media/test/mochitest.ini
dom/media/test/test_play_promise_13.html
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -817,16 +817,18 @@ tags=promise-play
 [test_play_promise_9.html]
 tags=promise-play
 [test_play_promise_10.html]
 tags=promise-play
 [test_play_promise_11.html]
 tags=promise-play
 [test_play_promise_12.html]
 tags=promise-play
+[test_play_promise_13.html]
+tags=promise-play
 [test_play_twice.html]
 # Seamonkey: Bug 598252
 skip-if = appname == "seamonkey"
 [test_playback.html]
 [test_playback_errors.html]
 [test_playback_rate.html]
 [test_playback_rate_playpause.html]
 [test_playback_reactivate.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_play_promise_13.html
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Media test: promise-based play() method</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <script type="text/javascript" src="manifest.js"></script>
+</head>
+<body>
+<pre id="test">
+
+<script>
+// Name: loadAlgorithmDoesNotCancelTasks
+// Case: re-invoke the load() on an element which had dispatched a task to resolve a promise.
+// Expected result: the already dispatched promise should still be resolved with undefined.
+
+let manager = new MediaTestManager;
+
+function initTest(test, token) {
+  manager.started(token);
+
+  let element = document.createElement(getMajorMimeType(test.type));
+  element.preload = "auto";
+  element.src = test.name;
+
+  // We must wait for "canplay" event; otherwise, invoke play() will lead to a
+  // pending promise and will then be rejected by the following load().
+  once(element, "canplay").then(() => {
+    // The play() promise will be queued to be resolved immediately, which means
+    // the promise is not in the pending list.
+    element.play().then(
+      (result) => {
+        if (result == undefined) {
+          ok(true, `${token} is resolved with ${result}.`);
+        } else {
+          ok(false, `${token} is resolved with ${result}.`);
+        }
+      },
+      (error) => {
+        ok(false, `${token} is rejected with ${error.name}.`);
+      }
+    ).then( () => { manager.finished(token); } );
+    element.src = test.name; // Re-invoke the load algorithm again.
+  });
+}
+
+manager.runTests(gSmallTests, initTest);
+
+</script>
\ No newline at end of file