forked from LadybirdBrowser/ladybird
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibWeb: Implement <input type=checkbox switch> experimentally
In conformance with the requirements of the spec PR at whatwg/html#9546, this change adds support for the “switch” attribute for type=checkbox “input” elements — which is shipping in Safari (since Safari 17.4). This change also implements support for exposing it to AT users with role=switch.
- Loading branch information
1 parent
68164aa
commit fd32c93
Showing
16 changed files
with
270 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
Tests/LibWeb/Text/expected/wpt-import/html-aam/roles-dynamic-switch.tentative.window.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Harness status: OK | ||
|
||
Found 6 tests | ||
|
||
6 Pass | ||
Pass Disconnected <input type=checkbox switch> | ||
Pass Connected <input type=checkbox switch> | ||
Pass Connected <input type=checkbox switch>: adding switch attribute | ||
Pass Connected <input type=checkbox switch>: removing switch attribute | ||
Pass Connected <input type=checkbox switch>: removing type attribute | ||
Pass Connected <input type=checkbox switch>: adding type attribute |
7 changes: 7 additions & 0 deletions
7
...rt/html/semantics/forms/the-input-element/input-type-checkbox-switch.tentative.window.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Harness status: OK | ||
|
||
Found 2 tests | ||
|
||
2 Pass | ||
Pass switch IDL attribute, setter | ||
Pass switch IDL attribute, getter |
11 changes: 11 additions & 0 deletions
11
...import/html/semantics/selectors/pseudo-classes/input-checkbox-switch.tentative.window.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Harness status: OK | ||
|
||
Found 6 tests | ||
|
||
6 Pass | ||
Pass Switch control does not match :indeterminate | ||
Pass Checkbox that is no longer a switch control does match :indeterminate | ||
Pass Checkbox that becomes a switch control does not match :indeterminate | ||
Pass Parent of a checkbox that becomes a switch control does not match :has(:indeterminate) | ||
Pass Parent of a switch control that becomes a checkbox continues to match :has(:checked) | ||
Pass A switch control that becomes a checkbox in a roundabout way |
10 changes: 10 additions & 0 deletions
10
Tests/LibWeb/Text/input/wpt-import/html-aam/roles-dynamic-switch.tentative.window.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
|
||
<script src="../resources/testharness.js"></script> | ||
<script src="../resources/testharnessreport.js"></script> | ||
<script src="../resources/testdriver.js"></script> | ||
<script src="../resources/testdriver-vendor.js"></script> | ||
<script src="../resources/testdriver-actions.js"></script> | ||
<div id=log></div> | ||
<script src="../html-aam/roles-dynamic-switch.tentative.window.js"></script> |
71 changes: 71 additions & 0 deletions
71
Tests/LibWeb/Text/input/wpt-import/html-aam/roles-dynamic-switch.tentative.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// META: script=/resources/testdriver.js | ||
// META: script=/resources/testdriver-vendor.js | ||
// META: script=/resources/testdriver-actions.js | ||
|
||
promise_test(async () => { | ||
const control = document.createElement("input"); | ||
control.type = "checkbox"; | ||
control.switch = true; | ||
const role = await test_driver.get_computed_role(control); | ||
assert_equals(role, ""); | ||
}, `Disconnected <input type=checkbox switch>`); | ||
|
||
promise_test(async t => { | ||
const control = document.createElement("input"); | ||
t.add_cleanup(() => control.remove()); | ||
control.type = "checkbox"; | ||
control.switch = true; | ||
document.body.append(control); | ||
const role = await test_driver.get_computed_role(control); | ||
assert_equals(role, "switch"); | ||
}, `Connected <input type=checkbox switch>`); | ||
|
||
promise_test(async t => { | ||
const control = document.createElement("input"); | ||
t.add_cleanup(() => control.remove()); | ||
control.type = "checkbox"; | ||
document.body.append(control); | ||
let role = await test_driver.get_computed_role(control); | ||
assert_equals(role, "checkbox"); | ||
control.switch = true; | ||
role = await test_driver.get_computed_role(control); | ||
assert_equals(role, "switch"); | ||
}, `Connected <input type=checkbox switch>: adding switch attribute`); | ||
|
||
promise_test(async t => { | ||
const control = document.createElement("input"); | ||
t.add_cleanup(() => control.remove()); | ||
control.type = "checkbox"; | ||
control.switch = true; | ||
document.body.append(control); | ||
let role = await test_driver.get_computed_role(control); | ||
assert_equals(role, "switch"); | ||
control.switch = false; | ||
role = await test_driver.get_computed_role(control); | ||
assert_equals(role, "checkbox"); | ||
}, `Connected <input type=checkbox switch>: removing switch attribute`); | ||
|
||
promise_test(async t => { | ||
const control = document.createElement("input"); | ||
t.add_cleanup(() => control.remove()); | ||
control.type = "checkbox"; | ||
document.body.append(control); | ||
control.switch = true; | ||
let role = await test_driver.get_computed_role(control); | ||
assert_equals(role, "switch"); | ||
control.removeAttribute("type"); | ||
role = await test_driver.get_computed_role(control); | ||
assert_equals(role, "textbox"); | ||
}, `Connected <input type=checkbox switch>: removing type attribute`); | ||
|
||
promise_test(async t => { | ||
const control = document.createElement("input"); | ||
t.add_cleanup(() => control.remove()); | ||
control.switch = true; | ||
document.body.append(control); | ||
let role = await test_driver.get_computed_role(control); | ||
assert_equals(role, "textbox"); | ||
control.type = "checkbox"; | ||
role = await test_driver.get_computed_role(control); | ||
assert_equals(role, "switch"); | ||
}, `Connected <input type=checkbox switch>: adding type attribute`); |
8 changes: 8 additions & 0 deletions
8
...t/html/semantics/forms/the-input-element/input-type-checkbox-switch.tentative.window.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/semantics/forms/the-input-element/input-type-checkbox-switch.tentative.window.js"></script> |
19 changes: 19 additions & 0 deletions
19
...ort/html/semantics/forms/the-input-element/input-type-checkbox-switch.tentative.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
test(t => { | ||
const input = document.createElement("input"); | ||
input.switch = true; | ||
|
||
assert_true(input.hasAttribute("switch")); | ||
assert_equals(input.getAttribute("switch"), ""); | ||
assert_equals(input.type, "text"); | ||
}, "switch IDL attribute, setter"); | ||
|
||
test(t => { | ||
const container = document.createElement("div"); | ||
container.innerHTML = "<input type=checkbox switch>"; | ||
const input = container.firstChild; | ||
|
||
assert_true(input.hasAttribute("switch")); | ||
assert_equals(input.getAttribute("switch"), ""); | ||
assert_equals(input.type, "checkbox"); | ||
assert_true(input.switch); | ||
}, "switch IDL attribute, getter"); |
8 changes: 8 additions & 0 deletions
8
...mport/html/semantics/selectors/pseudo-classes/input-checkbox-switch.tentative.window.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/semantics/selectors/pseudo-classes/input-checkbox-switch.tentative.window.js"></script> |
75 changes: 75 additions & 0 deletions
75
...-import/html/semantics/selectors/pseudo-classes/input-checkbox-switch.tentative.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
test(t => { | ||
const input = document.body.appendChild(document.createElement("input")); | ||
t.add_cleanup(() => input.remove()); | ||
input.type = "checkbox"; | ||
input.switch = true; | ||
input.indeterminate = true; | ||
|
||
assert_false(input.matches(":indeterminate")); | ||
}, "Switch control does not match :indeterminate"); | ||
|
||
test(t => { | ||
const input = document.body.appendChild(document.createElement("input")); | ||
t.add_cleanup(() => input.remove()); | ||
input.type = "checkbox"; | ||
input.switch = true; | ||
input.indeterminate = true; | ||
|
||
assert_false(input.matches(":indeterminate")); | ||
|
||
input.switch = false; | ||
assert_true(input.matches(":indeterminate")); | ||
}, "Checkbox that is no longer a switch control does match :indeterminate"); | ||
|
||
test(t => { | ||
const input = document.body.appendChild(document.createElement("input")); | ||
t.add_cleanup(() => input.remove()); | ||
input.type = "checkbox"; | ||
input.indeterminate = true; | ||
|
||
assert_true(input.matches(":indeterminate")); | ||
|
||
input.setAttribute("switch", "blah"); | ||
assert_false(input.matches(":indeterminate")); | ||
}, "Checkbox that becomes a switch control does not match :indeterminate"); | ||
|
||
test(t => { | ||
const input = document.body.appendChild(document.createElement("input")); | ||
t.add_cleanup(() => input.remove()); | ||
input.type = "checkbox"; | ||
input.indeterminate = true; | ||
|
||
assert_true(document.body.matches(":has(:indeterminate)")); | ||
|
||
input.switch = true; | ||
assert_false(document.body.matches(":has(:indeterminate)")); | ||
}, "Parent of a checkbox that becomes a switch control does not match :has(:indeterminate)"); | ||
|
||
test(t => { | ||
const input = document.body.appendChild(document.createElement("input")); | ||
t.add_cleanup(() => input.remove()); | ||
input.type = "checkbox"; | ||
input.switch = true | ||
input.checked = true; | ||
|
||
assert_true(document.body.matches(":has(:checked)")); | ||
|
||
input.switch = false; | ||
assert_true(document.body.matches(":has(:checked)")); | ||
|
||
input.checked = false; | ||
assert_false(document.body.matches(":has(:checked)")); | ||
}, "Parent of a switch control that becomes a checkbox continues to match :has(:checked)"); | ||
|
||
test(t => { | ||
const input = document.body.appendChild(document.createElement("input")); | ||
t.add_cleanup(() => input.remove()); | ||
input.type = "checkbox"; | ||
input.switch = true; | ||
input.indeterminate = true; | ||
assert_false(input.matches(":indeterminate")); | ||
input.type = "text"; | ||
input.removeAttribute("switch"); | ||
input.type = "checkbox"; | ||
assert_true(input.matches(":indeterminate")); | ||
}, "A switch control that becomes a checkbox in a roundabout way"); |