Skip to content

Commit

Permalink
Bug 1858096 [wpt PR 42449] - HTML: tests for <input type=checkbox swi…
Browse files Browse the repository at this point in the history
…tch>, a=testonly

Automatic update from web-platform-tests
HTML: tentative tests for <input type=checkbox switch>

For whatwg/html#9546.

Co-authored-by: lilyspiniolas <119537181+lilyspiniolasusers.noreply.github.com>
--

wpt-commits: 3a893e3c94d4bf08065f32537f714bc047eaf128
wpt-pr: 42449

UltraBlame original commit: 36f32a5db15421b182dc403c087fd80d4a9daeae
  • Loading branch information
marco-c committed Nov 21, 2023
1 parent 48cc098 commit e92b085
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 0 deletions.
@@ -0,0 +1,71 @@




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`);
26 changes: 26 additions & 0 deletions testing/web-platform/tests/html-aam/roles.tentative.html
@@ -0,0 +1,26 @@
<!doctype html>
<html>
<head>
<title>HTML-AAM Role Verification Tests</title>
<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>
<script src="/wai-aria/scripts/aria-utils.js"></script>
</head>
<body>


<p>Tests the computedrole mappings defined in <a href="https://w3c.github.io/html-aam/">HTML-AAM</a>. Most test names correspond to a unique ID defined in the spec.<p>

<p>These should remain in alphabetical order, and include all HTML tagnames. If a tag is not tested here, include a pointer to the file where it is tested, such as: <code>&lt;!-- caption -&gt; ./table-roles.html --&gt;</code></p>

<input type="checkbox" switch data-testname="el-input-checkbox-switch" data-expectedrole="switch" class="ex">

<script>
AriaUtils.verifyRolesBySelector(".ex");
</script>

</body>
</html>
@@ -0,0 +1,2 @@
<!doctype html>
<input type=checkbox switch>
@@ -0,0 +1,7 @@
<!doctype html>
<title>Checkbox with switch attribute set does not render differently when the indeterminate attribute is set</title>
<link rel=match href="input-checkbox-switch-indeterminate-ref.html">
<input id="input" type=checkbox switch>
<script>
input.indeterminate = true;
</script>
@@ -0,0 +1,4 @@
<!doctype html>
<input type=checkbox>
<input type=checkbox>
<input type=checkbox switch>
@@ -0,0 +1,4 @@
<!doctype html>
<input type=checkbox switch>
<input type=checkbox switch>
<input type=checkbox>
@@ -0,0 +1,14 @@
<!doctype html>
<html class="reftest-wait">
<title>Checkbox with switch attribute set renders differently than a checkbox without switch attribute</title>
<link rel=match href="input-checkbox-switch-ref.html">
<link rel=mismatch href="input-checkbox-switch-notref.html">
<input type=checkbox switch>
<input id='input2' type=checkbox>
<input id='input3' type=checkbox switch>
<script>
input2.setAttribute('switch','');
input3.removeAttribute('switch');
document.documentElement.classList.remove("reftest-wait");
</script>
</html>
@@ -0,0 +1,16 @@
test(t => {
const input = document.body.appendChild(document.createElement("input"));
t.add_cleanup(() => input.remove());
input.type = "checkbox";
input.switch = true;
assert_equals(getComputedStyle(input).appearance, "auto");
}, "Default appearance value");

test(t => {
const input = document.body.appendChild(document.createElement("input"));
t.add_cleanup(() => input.remove());
input.type = "checkbox";
input.switch = true;
input.style.appearance = "none";
assert_equals(getComputedStyle(input).appearance, "none");
}, "appearance:none should work");
@@ -0,0 +1,62 @@
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)");

0 comments on commit e92b085

Please sign in to comment.