test_play_promise_15.html (1877B)
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"> 11 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. 17 18 let manager = new MediaTestManager; 19 20 function initTest(test, token) { 21 manager.started(token); 22 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}.`); 30 }, 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}.`); 36 } 37 } 38 ).then( () => { manager.finished(token); } ); 39 40 ok(element.networkState == HTMLMediaElement.NETWORK_NO_SOURCE); 41 42 // Invoke load() again and since the networkState is NETWORK_NO_SOURCE, the load() rejects the pending promise. 43 element.src = test.name; 44 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.`); 47 } 48 49 manager.runTests(gSmallTests, initTest); 50 51 </script>