Skip to content

Truly independent web browser

Tests/LibWeb: Import WPT tests for event handler compile errors

Andreas Klingc59e67758b54
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-late.window.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-late.window.txt
new file mode 100644
index 00000000000..50189f52107
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-late.window.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail Invalid uncompiled raw handlers should only be compiled when about to call them
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-once.window.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-once.window.txt
new file mode 100644
index 00000000000..46673440006
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-once.window.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail Invalid uncompiled raw handlers should only be compiled once
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-keeps-position.window.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-keeps-position.window.txt
new file mode 100644
index 00000000000..f96a7074987
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-keeps-position.window.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Fail
+Fail Compiling invalid uncompiled raw handlers should keep the position in event listener list
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/processing-model-2/compile-error-in-attribute.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/processing-model-2/compile-error-in-attribute.txt
new file mode 100644
index 00000000000..59a3fe39d39
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/scripting/processing-model-2/compile-error-in-attribute.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Fail
+Fail window.onerror - compile error in attribute
+Fail window.onerror - compile error in attribute (column)
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-late.window.html b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-late.window.html
new file mode 100644
index 00000000000..d05a6fbc82c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-late.window.html
@@ -0,0 +1,8 @@
+<!doctype html>
+<meta charset=utf-8>
+
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+
+<div id=log></div>
+<script src="../../../../html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-late.window.js"></script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-late.window.js b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-late.window.js
new file mode 100644
index 00000000000..2892a4c3ab9
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-late.window.js
@@ -0,0 +1,16 @@
+setup({ allow_uncaught_exception: true });
+
+test(function() {
+ var events = [];
+ window.onerror = function() {
+ events.push("error");
+ };
+
+ var div = document.createElement("div");
+ div.addEventListener("click", function (e) { events.push("click 1") });
+ div.setAttribute("onclick", "}");
+ div.addEventListener("click", function (e) { events.push("click 2") });
+ div.dispatchEvent(new Event("click"));
+ assert_equals(div.onclick, null);
+ assert_array_equals(events, ["click 1", "error", "click 2"]);
+}, "Invalid uncompiled raw handlers should only be compiled when about to call them");
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-once.window.html b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-once.window.html
new file mode 100644
index 00000000000..fa049eb6d97
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-once.window.html
@@ -0,0 +1,8 @@
+<!doctype html>
+<meta charset=utf-8>
+
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+
+<div id=log></div>
+<script src="../../../../html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-once.window.js"></script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-once.window.js b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-once.window.js
new file mode 100644
index 00000000000..b39b54b0e9c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-compiled-once.window.js
@@ -0,0 +1,14 @@
+setup({ allow_uncaught_exception: true });
+
+var errors = 0;
+window.onerror = function() {
+ errors++;
+};
+
+test(function() {
+ var e = document.body;
+ e.setAttribute("onclick", "window.open(");
+ assert_equals(e.onclick, null);
+ assert_equals(e.onclick, null);
+ assert_equals(errors, 1);
+}, "Invalid uncompiled raw handlers should only be compiled once");
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-keeps-position.window.html b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-keeps-position.window.html
new file mode 100644
index 00000000000..c3d9958bc7e
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-keeps-position.window.html
@@ -0,0 +1,8 @@
+<!doctype html>
+<meta charset=utf-8>
+
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+
+<div id=log></div>
+<script src="../../../../html/webappapis/scripting/events/invalid-uncompiled-raw-handler-keeps-position.window.js"></script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-keeps-position.window.js b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-keeps-position.window.js
new file mode 100644
index 00000000000..f9443bf99a0
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/events/invalid-uncompiled-raw-handler-keeps-position.window.js
@@ -0,0 +1,20 @@
+setup({ allow_uncaught_exception: true });
+
+test(function() {
+ var events = [];
+ window.onerror = function() {
+ events.push("error");
+ };
+
+ var div = document.createElement("div");
+ div.addEventListener("click", function (e) { events.push("click 1"); });
+ div.setAttribute("onclick", "}");
+ div.addEventListener("click", function (e) { events.push("click 3"); });
+ assert_equals(div.onclick, null);
+ assert_array_equals(events, ["error"]);
+
+ events = [];
+ div.onclick = function (e) { events.push("click 2"); };
+ div.dispatchEvent(new Event("click"));
+ assert_array_equals(events, ["click 1", "click 2", "click 3"]);
+}, "Compiling invalid uncompiled raw handlers should keep the position in event listener list");
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/processing-model-2/compile-error-in-attribute.html b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/processing-model-2/compile-error-in-attribute.html
new file mode 100644
index 00000000000..2af80111dbb
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/webappapis/scripting/processing-model-2/compile-error-in-attribute.html
@@ -0,0 +1,39 @@
+<!doctype html>
+<html>
+ <head>
+ <title>window.onerror - compile error in attribute</title>
+ <script src="../../../../resources/testharness.js"></script>
+ <script src="../../../../resources/testharnessreport.js"></script>
+ </head>
+ <body>
+ <div id=log></div>
+ <script>
+ setup({allow_uncaught_exception:true});
+ var t = async_test();
+ var t_col = async_test(document.title+' (column)');
+ var ran = false;
+ var col_value;
+ window.onerror = t.step_func(function(a, b, c, d){
+ ran = true;
+ col_value = d;
+ assert_equals(typeof a, 'string', 'first arg');
+ assert_equals(b, location.href, 'second arg');
+ assert_equals(typeof c, 'number', 'third arg');
+ });
+ </script>
+ <p onclick="{"></p>
+ <script>
+ t.step(function(){
+ var ev = document.createEvent('Event');
+ ev.initEvent('click', false, false);
+ document.querySelector('p').dispatchEvent(ev);
+ assert_true(ran, 'ran');
+ t.done();
+ });
+ t_col.step(function(){
+ assert_equals(typeof col_value, 'number', 'fourth arg');
+ t_col.done();
+ });
+ </script>
+ </body>
+</html>
\ No newline at end of file