Bug 1619792 [wpt PR 22075] - Add tests for input and change events on checkboxes and radios, a=testonly

Automatic update from web-platform-tests
Add tests for input and change events on checkboxes and radios

This follows @domenic's suggestion in https://github.com/whatwg/html/issues/5291

--

wpt-commits: 78f14c537b62447d64aeb65a30ede77c5d26db41
wpt-pr: 22075
This commit is contained in:
Joey Arhar 2020-03-05 21:35:45 +00:00 коммит произвёл moz-wptsync-bot
Родитель 05e552d46c
Коммит 0b08971690
2 изменённых файлов: 208 добавлений и 0 удалений

Просмотреть файл

@ -191,6 +191,24 @@ async_test(function(t) {
input.click()
}, "disconnected radio should be checked")
async_test(t => {
const input = document.createElement('input');
input.type = 'checkbox';
input.onclick = t.step_func_done(() => {
assert_true(input.checked);
});
input.dispatchEvent(new MouseEvent('click'));
}, `disconnected checkbox should be checked from dispatchEvent(new MouseEvent('click'))`);
async_test(t => {
const input = document.createElement('input');
input.type = 'radio';
input.onclick = t.step_func_done(() => {
assert_true(input.checked);
});
input.dispatchEvent(new MouseEvent('click'));
}, `disconnected radio should be checked from dispatchEvent(new MouseEvent('click'))`);
async_test(function(t) {
var form = document.createElement("form")
var didSubmit = false

Просмотреть файл

@ -0,0 +1,190 @@
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" title="Joey Arhar" href="mailto:jarhar@chromium.org">
<title>input and change events for detached checkbox and radio elements</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
test(() => {
const input = document.createElement('input');
input.type = 'checkbox';
let inputEventFired = false;
input.addEventListener('input', () => inputEventFired = true);
let changeEventFired = false;
input.addEventListener('change', () => changeEventFired = true);
input.click();
assert_false(inputEventFired);
assert_false(changeEventFired);
}, 'detached checkbox should not emit input or change events on click().');
test(() => {
const input = document.createElement('input');
input.type = 'radio';
let inputEventFired = false;
input.addEventListener('input', () => inputEventFired = true);
let changeEventFired = false;
input.addEventListener('change', () => changeEventFired = true);
input.click();
assert_false(inputEventFired);
assert_false(changeEventFired);
}, 'detached radio should not emit input or change events on click().');
test(() => {
const input = document.createElement('input');
input.type = 'checkbox';
let inputEventFired = false;
input.addEventListener('input', () => inputEventFired = true);
let changeEventFired = false;
input.addEventListener('change', () => changeEventFired = true);
input.dispatchEvent(new MouseEvent('click'));
assert_false(inputEventFired);
assert_false(changeEventFired);
}, `detached checkbox should not emit input or change events on dispatchEvent(new MouseEvent('click')).`);
test(() => {
const input = document.createElement('input');
input.type = 'radio';
let inputEventFired = false;
input.addEventListener('input', () => inputEventFired = true);
let changeEventFired = false;
input.addEventListener('change', () => changeEventFired = true);
input.dispatchEvent(new MouseEvent('click'));
assert_false(inputEventFired);
assert_false(changeEventFired);
}, `detached radio should not emit input or change events on dispatchEvent(new MouseEvent('click')).`);
test(() => {
const input = document.createElement('input');
input.type = 'checkbox';
document.body.appendChild(input);
let inputEventFired = false;
input.addEventListener('input', () => inputEventFired = true);
let changeEventFired = false;
input.addEventListener('change', () => changeEventFired = true);
input.click();
assert_true(inputEventFired);
assert_true(changeEventFired);
}, 'attached checkbox should emit input and change events on click().');
test(() => {
const input = document.createElement('input');
input.type = 'radio';
document.body.appendChild(input);
let inputEventFired = false;
input.addEventListener('input', () => inputEventFired = true);
let changeEventFired = false;
input.addEventListener('change', () => changeEventFired = true);
input.click();
assert_true(inputEventFired);
assert_true(changeEventFired);
}, 'attached radio should emit input and change events on click().');
test(() => {
const input = document.createElement('input');
input.type = 'checkbox';
document.body.appendChild(input);
let inputEventFired = false;
input.addEventListener('input', () => inputEventFired = true);
let changeEventFired = false;
input.addEventListener('change', () => changeEventFired = true);
input.dispatchEvent(new MouseEvent('click'));
assert_true(inputEventFired);
assert_true(changeEventFired);
}, `attached checkbox should emit input and change events on dispatchEvent(new MouseEvent('click')).`);
test(() => {
const input = document.createElement('input');
input.type = 'radio';
document.body.appendChild(input);
let inputEventFired = false;
input.addEventListener('input', () => inputEventFired = true);
let changeEventFired = false;
input.addEventListener('change', () => changeEventFired = true);
input.dispatchEvent(new MouseEvent('click'));
assert_true(inputEventFired);
assert_true(changeEventFired);
}, `attached radio should emit input and change events on dispatchEvent(new MouseEvent('click')).`);
test(() => {
const input = document.createElement('input');
input.type = 'checkbox';
const shadowHost = document.createElement('div');
document.body.appendChild(shadowHost);
const shadowRoot = shadowHost.attachShadow({mode: 'open'});
shadowRoot.appendChild(input);
let inputEventFired = false;
input.addEventListener('input', () => inputEventFired = true);
let changeEventFired = false;
input.addEventListener('change', () => changeEventFired = true);
input.click();
assert_true(inputEventFired);
assert_true(changeEventFired);
}, 'attached to shadow dom checkbox should emit input and change events on click().');
test(() => {
const input = document.createElement('input');
input.type = 'radio';
const shadowHost = document.createElement('div');
document.body.appendChild(shadowHost);
const shadowRoot = shadowHost.attachShadow({mode: 'open'});
shadowRoot.appendChild(input);
let inputEventFired = false;
input.addEventListener('input', () => inputEventFired = true);
let changeEventFired = false;
input.addEventListener('change', () => changeEventFired = true);
input.click();
assert_true(inputEventFired);
assert_true(changeEventFired);
}, 'attached to shadow dom radio should emit input and change events on click().');
test(() => {
const input = document.createElement('input');
input.type = 'checkbox';
const shadowHost = document.createElement('div');
document.body.appendChild(shadowHost);
const shadowRoot = shadowHost.attachShadow({mode: 'open'});
shadowRoot.appendChild(input);
let inputEventFired = false;
input.addEventListener('input', () => inputEventFired = true);
let changeEventFired = false;
input.addEventListener('change', () => changeEventFired = true);
input.dispatchEvent(new MouseEvent('click'));
assert_true(inputEventFired);
assert_true(changeEventFired);
}, `attached to shadow dom checkbox should emit input and change events on dispatchEvent(new MouseEvent('click')).`);
test(() => {
const input = document.createElement('input');
input.type = 'radio';
const shadowHost = document.createElement('div');
document.body.appendChild(shadowHost);
const shadowRoot = shadowHost.attachShadow({mode: 'open'});
shadowRoot.appendChild(input);
let inputEventFired = false;
input.addEventListener('input', () => inputEventFired = true);
let changeEventFired = false;
input.addEventListener('change', () => changeEventFired = true);
input.dispatchEvent(new MouseEvent('click'));
assert_true(inputEventFired);
assert_true(changeEventFired);
}, `attached to shadow dom radio should emit input and change events on dispatchEvent(new MouseEvent('click')).`);
</script>
</body>