Truly independent web browser
Tests/LibWeb: Import WPT test for click events on checked radio buttons
Andreas Kling2f824b1c46b0
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/radio-click-events.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/radio-click-events.txtnew file mode 100644index 00000000000..71696846775--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/radio-click-events.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 4 tests++3 Pass+1 Fail+Pass radio input emits click, input, change events in order after synthetic click+Pass radio input emits click, input, change events in order after dispatching click event+Fail checked radio input emits only click event on click+Pass radio input synthetic click respects cancelling behaviour\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/radio-click-events.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/radio-click-events.htmlnew file mode 100644index 00000000000..3b00c6cf2cd--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/radio-click-events.html@@ -0,0 +1,116 @@+<!DOCTYPE HTML>+<title>Radio input cancel behavior reverts state</title>+<link rel="author" title="jeffcarp" href="mailto:[email protected]">+<link rel="help" href="https://html.spec.whatwg.org/#radio-button-state-(type=radio)">++<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>++<body>+<script>+"use strict";++test(() => {+ const input = document.createElement("input");+ input.type = "radio";+ document.body.appendChild(input);+ const events = [];++ input.addEventListener("change", () => {+ events.push("change");+ });+ input.addEventListener("click", () => {+ events.push("click");+ });+ input.addEventListener("input", () => {+ events.push("input");+ });++ assert_false(input.checked);++ input.click();++ assert_true(input.checked);+ assert_array_equals(events, ["click", "input", "change"]);++}, "radio input emits click, input, change events in order after synthetic click");++test(() => {+ const input = document.createElement("input");+ input.type = "radio";+ document.body.appendChild(input);+ const events = [];++ input.addEventListener("change", () => {+ events.push("change");+ });+ input.addEventListener("click", () => {+ events.push("click");+ });+ input.addEventListener("input", () => {+ events.push("input");+ });++ assert_false(input.checked);++ const event = new MouseEvent("click", { bubbles: true, cancelable: true });+ input.dispatchEvent(event);++ assert_true(input.checked);+ assert_array_equals(events, ["click", "input", "change"]);++}, "radio input emits click, input, change events in order after dispatching click event");++test(() => {+ const input = document.createElement("input");+ input.type = "radio";+ input.checked = true;+ document.body.appendChild(input);+ const events = [];++ input.addEventListener("change", () => {+ events.push("change");+ });+ input.addEventListener("click", () => {+ events.push("click");+ });+ input.addEventListener("input", () => {+ events.push("input");+ });++ input.click();++ assert_array_equals(events, ["click"]);++}, "checked radio input emits only click event on click ");++test(() => {+ const input = document.createElement("input");+ input.type = "radio";+ document.body.appendChild(input);+ const events = [];++ input.addEventListener("change", () => {+ events.push("change");+ });+ input.addEventListener("click", e => {+ // cancel click event+ e.preventDefault();+ events.push("click");+ });+ input.addEventListener("input", () => {+ events.push("input");+ });++ assert_false(input.checked);++ input.click();++ assert_false(input.checked);++ // only click event called+ assert_array_equals(events, ["click"]);++}, "radio input synthetic click respects cancelling behaviour");++</script>