summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/resources/load-error-events-helpers.js
blob: bbd6b09c6cf811855cb1fa299855b9cee55a66c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict";
// Helper functions to be used from load-error-events*.html tests.

function event_test(name, load_to_be_fired, error_to_be_fired) {
  return {
      test: async_test(name),
      executed: false,
      load_event_to_be_fired: load_to_be_fired,
      error_event_to_be_fired: error_to_be_fired
  };
}

// Should be used as load/error event handlers of script tags,
// with |t| = the object returned by event_test().
function onLoad(t) {
    t.test.step(function() {
        if (t.load_event_to_be_fired) {
            assert_true(t.executed,
                'Load event should be fired after script execution');
            // Delay done() a little so that if an error event happens
            // the assert_unreached is reached and fails the test.
            t.test.step_timeout(() => t.test.done(), 100);
        } else {
            assert_unreached('Load event should not be fired.');
        }
    });
};
function onError(t) {
    t.test.step(function() {
        if (t.error_event_to_be_fired) {
            assert_false(t.executed);
            // Delay done() a little so that if a load event happens
            // the assert_unreached is reached and fails the test.
            t.test.step_timeout(() => t.test.done(), 100);
        } else {
            assert_unreached('Error event should not be fired.');
        }
    });
};

// To be called from inline scripts, which expect no load/error events.
function onExecute(t) {
    t.executed = true;
    // Delay done() a little so that if a load/error event happens
    // the assert_unreached is reached and fails the test.
    t.test.step_timeout(() => t.test.done(), 100);
}