Lightpanda: the headless browser designed for AI and automation
tests: fail a test script that throws after an expect passed
Jay Hemnanif0f0f4a9e217
diff --git a/src/browser/tests/custom_elements/clone_upgrade.html b/src/browser/tests/custom_elements/clone_upgrade.htmlindex 09418daa1..736161d62 100644--- a/src/browser/tests/custom_elements/clone_upgrade.html+++ b/src/browser/tests/custom_elements/clone_upgrade.html@@ -124,6 +124,7 @@</script><script id=failed_clone_upgrade_keeps_the_copied_node>+ testing.expectUncaughtErrors();{let cloning = false;let constructed;diff --git a/src/browser/tests/custom_elements/constructor.html b/src/browser/tests/custom_elements/constructor.htmlindex acef48756..316dfff54 100644--- a/src/browser/tests/custom_elements/constructor.html+++ b/src/browser/tests/custom_elements/constructor.html@@ -91,6 +91,7 @@<div id=clone_container></div><script id=clone>+ testing.expectUncaughtErrors();{let calls = 0;class MyCloneElementA extends HTMLElement {@@ -110,6 +111,7 @@<div id=clone_siblings_container></div><script id=clone_self_appending_siblings>+ testing.expectUncaughtErrors();{// Two trailing constructors append into the list being cloned.let calls = 0;@@ -134,6 +136,7 @@<div id=fragment_clone_container></div><script id=clone_fragment>+ testing.expectUncaughtErrors();{let calls = 0;class MyFragmentCloneElement extends HTMLElement {@@ -160,6 +163,7 @@<div id=range_clone_container></div><script id=clone_range>+ testing.expectUncaughtErrors();{let calls = 0;class MyRangeCloneElement extends HTMLElement {diff --git a/src/browser/tests/custom_elements/context_element_not_reconstructed.html b/src/browser/tests/custom_elements/context_element_not_reconstructed.htmlindex ac9495af7..abe77856c 100644--- a/src/browser/tests/custom_elements/context_element_not_reconstructed.html+++ b/src/browser/tests/custom_elements/context_element_not_reconstructed.html@@ -2,6 +2,7 @@<script src="../testing.js"></script><script id="constructor_sets_innerhtml">+ testing.expectUncaughtErrors();{// A custom element whose constructor sets innerHTML. The innerHTML// setter fragment-parses with this element as the parsing context.diff --git a/src/browser/tests/custom_elements/create_element_post_conditions.html b/src/browser/tests/custom_elements/create_element_post_conditions.htmlindex c4f1477ad..8f988eed0 100644--- a/src/browser/tests/custom_elements/create_element_post_conditions.html+++ b/src/browser/tests/custom_elements/create_element_post_conditions.html@@ -1,5 +1,6 @@<!DOCTYPE html><script src="../testing.js"></script>+<script>testing.expectUncaughtErrors();</script><script id="uses_constructor_return_value">{diff --git a/src/browser/tests/custom_elements/error_reporting.html b/src/browser/tests/custom_elements/error_reporting.htmlindex 0b608c671..9ab2d8d0b 100644--- a/src/browser/tests/custom_elements/error_reporting.html+++ b/src/browser/tests/custom_elements/error_reporting.html@@ -1,5 +1,6 @@<!DOCTYPE html><script src="../testing.js"></script>+<script>testing.expectUncaughtErrors();</script><script id="create_element_reports_thrown_exception">{diff --git a/src/browser/tests/custom_elements/registry.html b/src/browser/tests/custom_elements/registry.htmlindex 7bc89a551..7bc5afce2 100644--- a/src/browser/tests/custom_elements/registry.html+++ b/src/browser/tests/custom_elements/registry.html@@ -120,6 +120,7 @@</script><script id="constructor_self_insert_foster_parent">+testing.expectUncaughtErrors();{// Regression: custom element constructor inserting itself (via appendChild) during// innerHTML parsing. When the element is not valid table content, the HTML5 parserdiff --git a/src/browser/tests/element/html/script/load_event.html b/src/browser/tests/element/html/script/load_event.htmlindex 74a5ab559..9e0f09191 100644--- a/src/browser/tests/element/html/script/load_event.html+++ b/src/browser/tests/element/html/script/load_event.html@@ -1,6 +1,7 @@<!DOCTYPE html><head></head><script src="../../../testing.js"></script>+<script>testing.expectUncaughtErrors();</script><!--A <script> fires load/error at its own element only when it is "from andiff --git a/src/browser/tests/event/report_error.html b/src/browser/tests/event/report_error.htmlindex d2aaa13dc..ade46af9b 100644--- a/src/browser/tests/event/report_error.html+++ b/src/browser/tests/event/report_error.html@@ -1,5 +1,6 @@<!DOCTYPE html><script src="../testing.js"></script>+<script>testing.expectUncaughtErrors();</script><script id=onerrorFiveArguments>let called = false;diff --git a/src/browser/tests/events.html b/src/browser/tests/events.htmlindex 3b451a90c..542921e48 100644--- a/src/browser/tests/events.html+++ b/src/browser/tests/events.html@@ -811,6 +811,7 @@<div id=throw_host><div id=throw_mid><span id=throw_leaf></span></div></div><script id=listenerThrowDoesNotHaltDispatch>+ testing.expectUncaughtErrors();// Per DOM §2.9 step 4 substep 8 "Inner invoke", a listener callback that// throws must have its exception reported, not propagated — subsequent// listeners on the same target and the rest of the propagation path must@@ -846,6 +847,7 @@<div id=throw_capture_host><div id=throw_capture_mid><span id=throw_capture_leaf></span></div></div><script id=listenerThrowDuringCapturePhase>+ testing.expectUncaughtErrors();// Capture-phase variant: a throwing capture listener on an ancestor must// not skip the rest of the capture walk, the at-target listener, or the// bubble walk.@@ -876,6 +878,7 @@</script><script id=listenerThrowOnWindowTarget>+ testing.expectUncaughtErrors();// Direct-dispatch variant (non-DOM target — Window). Same contract: a// throwing listener must not stop later listeners from running.{diff --git a/src/browser/tests/sanitizer.html b/src/browser/tests/sanitizer.htmlindex e11a37d17..80babac13 100644--- a/src/browser/tests/sanitizer.html+++ b/src/browser/tests/sanitizer.html@@ -121,7 +121,7 @@{// Allowing every data attribute subsumes any named individually, and the// config has to stay valid.- const s = new Sanitizer({attributes: ['data-x', 'id'], elements: [{name: 'div', attributes: ['data-y']}]});+ const s = new Sanitizer({attributes: ['data-x', 'id'], elements: [{name: 'div', attributes: ['data-y']}], dataAttributes: false});testing.expectEqual(true, s.setDataAttributes(true));testing.expectEqual([{name: 'id', namespace: null}], s.get().attributes);testing.expectEqual([], s.get().elements[0].attributes);diff --git a/src/browser/tests/testing.js b/src/browser/tests/testing.jsindex f53ea30ad..31860bc03 100644--- a/src/browser/tests/testing.js+++ b/src/browser/tests/testing.js@@ -11,6 +11,34 @@// runner will wait until this is empty (or timeout)let async_pending = new Set();+ // tests that throw uncaught errors on purpose, see expectUncaughtErrors+ let uncaught_errors_page = false;+ let uncaught_errors_scripts = new Set();++ // A script that throws after an expect* passed would otherwise count as ok.+ window.addEventListener('error', (e) => {+ const script_id = _currentScriptId();+ if (uncaught_errors_page || uncaught_errors_scripts.has(script_id)) {+ return;+ }+ failed = true;+ if (script_id) {+ observed_ids[script_id] = 'fail';+ }+ console.error(`uncaught error: ${e.message}\n script_id: ${script_id}`);+ });++ // Allows uncaught errors from the calling <script id=...>, or from the whole+ // page when called from a script without an id.+ function expectUncaughtErrors() {+ const script_id = _currentScriptId();+ if (script_id) {+ uncaught_errors_scripts.add(script_id);+ } else {+ uncaught_errors_page = true;+ }+ }+function expectTrue(actual) {expectEqual(true, actual);}@@ -159,6 +187,7 @@expectEqual: expectEqual,expectError: expectError,withError: withError,+ expectUncaughtErrors: expectUncaughtErrors,printTimeoutState: printTimeoutState,onload: onload,IS_TEST_RUNNER: IS_TEST_RUNNER,@@ -231,15 +260,6 @@}observed_ids[script_id] = status;-- if (document.currentScript != null) {- if (document.currentScript.onerror === null) {- document.currentScript.onerror = function() {- observed_ids[document.currentScript.id] = 'fail';- failed = true;- }- }- }}function _currentScriptId() {diff --git a/src/browser/tests/window/onerror.html b/src/browser/tests/window/onerror.htmlindex d07ba190d..827bfd0d6 100644--- a/src/browser/tests/window/onerror.html+++ b/src/browser/tests/window/onerror.html@@ -1,5 +1,6 @@<!DOCTYPE html><script src="../testing.js"></script>+<script>testing.expectUncaughtErrors();</script><script id=onerrorBasicCallback>{diff --git a/src/browser/tests/window/report_error.html b/src/browser/tests/window/report_error.htmlindex 298b2e6cd..55d3ffa2f 100644--- a/src/browser/tests/window/report_error.html+++ b/src/browser/tests/window/report_error.html@@ -1,5 +1,6 @@<!DOCTYPE html><script src="../testing.js"></script>+<script>testing.expectUncaughtErrors();</script><script id=reportErrorBasic>{