tor-browser

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

test_play_promise_13.html (1599B)


      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: loadAlgorithmDoesNotCancelTasks
     14 // Case: re-invoke the load() on an element which had dispatched a task to resolve a promise.
     15 // Expected result: the already dispatched promise should still be resolved with undefined.
     16 
     17 let manager = new MediaTestManager;
     18 
     19 function initTest(test, token) {
     20  manager.started(token);
     21 
     22  let element = document.createElement(getMajorMimeType(test.type));
     23  element.preload = "auto";
     24  element.src = test.name;
     25 
     26  // We must wait for "canplay" event; otherwise, invoke play() will lead to a
     27  // pending promise and will then be rejected by the following load().
     28  once(element, "canplay").then(() => {
     29    // The play() promise will be queued to be resolved immediately, which means
     30    // the promise is not in the pending list.
     31    element.play().then(
     32      (result) => {
     33        if (result == undefined) {
     34          ok(true, `${token} is resolved with ${result}.`);
     35        } else {
     36          ok(false, `${token} is resolved with ${result}.`);
     37        }
     38      },
     39      (error) => {
     40        ok(false, `${token} is rejected with ${error.name}.`);
     41      }
     42    ).then( () => { manager.finished(token); } );
     43    element.src = test.name; // Re-invoke the load algorithm again.
     44  });
     45 }
     46 
     47 manager.runTests(gSmallTests, initTest);
     48 
     49 </script>