diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/html/semantics/scripting-1/the-script-element/resources/load-error-events-helpers.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/semantics/scripting-1/the-script-element/resources/load-error-events-helpers.js')
-rw-r--r-- | testing/web-platform/tests/html/semantics/scripting-1/the-script-element/resources/load-error-events-helpers.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/resources/load-error-events-helpers.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/resources/load-error-events-helpers.js new file mode 100644 index 0000000000..bbd6b09c6c --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/resources/load-error-events-helpers.js @@ -0,0 +1,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); +} |