summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/resources/load-error-events-helpers.js
diff options
context:
space:
mode:
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.js47
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);
+}