Backed out changeset ddccd40117a0 (bug 1853271) for causing bug 1854769. CLOSED TREE
[gecko.git] / dom / media / test / test_play_promise_15.html
blobb8bce48651216a5e155db48c58b4ef7cda23654f
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Media test: promise-based play() method</title>
5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
7 <script type="text/javascript" src="manifest.js"></script>
8 </head>
9 <body>
10 <pre id="test">
12 <script>
13 // Name: loadAlgorithmRejectPromisesWhenPausing
14 // Case: step1: create an element with its paused member to be fause and networkState to be NETWORK_NO_SOURCE.
15 // stpe2: invoke load() on the element and the load() rejects the pending promise.
16 // Expected result: reject the pending promise with AbortError DOM exception.
18 let manager = new MediaTestManager;
20 function initTest(test, token) {
21 manager.started(token);
23 let element = document.createElement(getMajorMimeType(test.type));
24 // Invoke play() -> (1) the promise will be left pending.
25 // (2) invoke load() -> (1) set the networkState to be NETWORK_NO_SOURCE.
26 // (2) queue a task to run resouce selection algorithm.
27 element.play().then(
28 (result) => {
29 ok(false, `${token} is resolved with ${result}.`);
31 (error) => {
32 if (error.name == "AbortError") {
33 ok(true, `${token} is rejected with ${error.name}.`);
34 } else {
35 ok(false, `${token} is rejected with ${error.name}.`);
38 ).then( () => { manager.finished(token); } );
40 ok(element.networkState == HTMLMediaElement.NETWORK_NO_SOURCE);
42 // Invoke load() again and since the networkState is NETWORK_NO_SOURCE, the load() rejects the pending promise.
43 element.src = test.name;
45 // Since the networkState is not NETWORK_EMPTY, the load() sets paused to be true.
46 ok(element.paused, `loadAlgorithmRejectPromisesWhenPausing(${token}).paused should be true.`);
49 manager.runTests(gSmallTests, initTest);
51 </script>