tor-browser

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

resource-selection-invoke-in-sync-event.html (1195B)


      1 <!doctype html>
      2 <title>await a stable state and sync event handlers</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <div id=log></div>
      6 <video></video>
      7 <script>
      8 var v;
      9 var t = async_test(function(t) {
     10  v = document.querySelector('video');
     11  var a = document.createElement('a');
     12  a.onclick = t.step_func(function() {
     13    v.setAttribute('src', '#'); // invokes media load which invokes resource selection
     14    assert_equals(v.networkState, v.NETWORK_NO_SOURCE, 'networkState in onclick handler');
     15  });
     16  a.click(); // sync fires click, so sets src
     17  // now we should still await a stable state because the script hasn't
     18  // finished, the event handler has just returned
     19  assert_equals(v.networkState, v.NETWORK_NO_SOURCE, 'networkState after click()');
     20  v.removeAttribute('src');
     21 });
     22 </script>
     23 <!-- now resource selection will continue its sync section (the </script> tag below provides a stable state) -->
     24 <!-- will find neither src nor source, so sets networkState to NETWORK_EMPTY -->
     25 <script>
     26 t.step(function() {
     27  assert_equals(v.networkState, v.NETWORK_EMPTY, 'networkState after src removed');
     28  t.done();
     29 });
     30 </script>