tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_play_promise_14.html (2220B)


      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: loadAlgorithmKeepPromisesPendingWhenNotPausing
     14 // Case: step1: create an element with its paused member to be fause and networkState to be NETWORK_EMPTY.
     15 //       stpe2: invoke load() on the element and the load() leaves the promise pending.
     16 // Expected result: the pending promise should finally be resolved.
     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      if (result == undefined) {
     30        ok(true, `${token} is resolved with ${result}.`);
     31      } else {
     32        ok(false, `${token} is resolved with ${result}.`);
     33      }
     34    },
     35    (error) => {
     36      ok(false, `${token} is rejected with ${error.name}.`);
     37    }
     38  ).then( () => { manager.finished(token); } );
     39 
     40  once(element, "play").then(() => {
     41    // The resouce selection algorithm has been done.
     42    // -> set the networkState to be NETWORK_EMPTY because there is no valid resource to load.
     43    ok(element.networkState == HTMLMediaElement.NETWORK_EMPTY);
     44 
     45    // Invoke load() again and since the networkState is NETWORK_EMPTY, the load() does not reject the pending promise.
     46    // The load() will queue a task to run resouce selection algorithm which will change the readyState and finally resolve the pending promise.
     47    element.src = test.name;
     48 
     49    // Since the networkState is NETWORK_EMPTY, the load() does not set paused to be true.
     50    ok(!element.paused, `loadAlgorithmKeepPromisesPendingWhenNotPausing(${token}).paused should be false.`);
     51  });
     52 }
     53 
     54 manager.runTests(gSmallTests, initTest);
     55 
     56 </script>