tor-browser

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

load-error-events-helpers.js (1654B)


      1 "use strict";
      2 // Helper functions to be used from load-error-events*.html tests.
      3 
      4 function event_test(name, load_to_be_fired, error_to_be_fired) {
      5  return {
      6      test: async_test(name),
      7      executed: false,
      8      load_event_to_be_fired: load_to_be_fired,
      9      error_event_to_be_fired: error_to_be_fired
     10  };
     11 }
     12 
     13 // Should be used as load/error event handlers of script tags,
     14 // with |t| = the object returned by event_test().
     15 function onLoad(t) {
     16    t.test.step(function() {
     17        if (t.load_event_to_be_fired) {
     18            assert_true(t.executed,
     19                'Load event should be fired after script execution');
     20            // Delay done() a little so that if an error event happens
     21            // the assert_unreached is reached and fails the test.
     22            t.test.step_timeout(() => t.test.done(), 100);
     23        } else {
     24            assert_unreached('Load event should not be fired.');
     25        }
     26    });
     27 };
     28 function onError(t) {
     29    t.test.step(function() {
     30        if (t.error_event_to_be_fired) {
     31            assert_false(t.executed);
     32            // Delay done() a little so that if a load event happens
     33            // the assert_unreached is reached and fails the test.
     34            t.test.step_timeout(() => t.test.done(), 100);
     35        } else {
     36            assert_unreached('Error event should not be fired.');
     37        }
     38    });
     39 };
     40 
     41 // To be called from inline scripts, which expect no load/error events.
     42 function onExecute(t) {
     43    t.executed = true;
     44    // Delay done() a little so that if a load/error event happens
     45    // the assert_unreached is reached and fails the test.
     46    t.test.step_timeout(() => t.test.done(), 100);
     47 }