forked from kdashg/gecko-cinn
-
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.
Bug 1885722 [wpt PR 45145] - Coalesce selectionchange events per w3c/…
…selection-api#170, a=testonly Automatic update from web-platform-tests Coalesce selectionchange events per w3c/selection-api#170 (#45145) -- wpt-commits: fd3510de36638b07103738b9ff2bfa9ede340797 wpt-pr: 45145
- Loading branch information
1 parent
234caba
commit 68731b3
Showing
3 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
testing/web-platform/tests/selection/onselectionchange-on-distinct-text-controls.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,47 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<link rel="help" href="https://w3c.github.io/selection-api/#selectionchange-event"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<input id="input1" value="hello"> | ||
<input id="input2" value="world"> | ||
<textarea id="textarea1">hello</textarea> | ||
<textarea id="textarea2">world</textarea> | ||
<script> | ||
|
||
promise_test(() => { | ||
return (async function() { | ||
let selectionChangeCount1 = 0; | ||
let selectionChangeCount2 = 0; | ||
input1.addEventListener("selectionchange", () => ++selectionChangeCount1); | ||
input2.addEventListener("selectionchange", () => ++selectionChangeCount2); | ||
input1.setSelectionRange(1, 2); | ||
input1.setSelectionRange(2, 3); | ||
input2.setSelectionRange(1, 3); | ||
assert_equals(selectionChangeCount1, 0); | ||
assert_equals(selectionChangeCount2, 0); | ||
await new Promise(setTimeout); | ||
assert_equals(selectionChangeCount1, 1); | ||
assert_equals(selectionChangeCount2, 1); | ||
})(); | ||
}, "selectionchange event on each input element fires independently"); | ||
|
||
promise_test(() => { | ||
return (async function() { | ||
let selectionChangeCount1 = 0; | ||
let selectionChangeCount2 = 0; | ||
textarea1.addEventListener("selectionchange", () => ++selectionChangeCount1); | ||
textarea2.addEventListener("selectionchange", () => ++selectionChangeCount2); | ||
textarea1.setSelectionRange(1, 2); | ||
textarea1.setSelectionRange(2, 3); | ||
textarea2.setSelectionRange(1, 3); | ||
assert_equals(selectionChangeCount1, 0); | ||
assert_equals(selectionChangeCount2, 0); | ||
await new Promise(setTimeout); | ||
assert_equals(selectionChangeCount1, 1); | ||
assert_equals(selectionChangeCount2, 1); | ||
})(); | ||
}, "selectionchange event on each textarea element fires independently"); | ||
|
||
</script> |
73 changes: 73 additions & 0 deletions
73
testing/web-platform/tests/selection/onselectionchange-on-document.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,73 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<link rel="help" href="https://w3c.github.io/selection-api/#selectionchange-event"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<div id="container"><br><br></div> | ||
<script> | ||
|
||
promise_test(() => { | ||
return new Promise(resolve => { | ||
let didFireSelectionChangeEvent = false; | ||
document.addEventListener("selectionchange", () => { didFireSelectionChangeEvent = true; resolve(); }, {once: true}); | ||
getSelection().setPosition(container, 0); | ||
assert_false(didFireSelectionChangeEvent); | ||
}); | ||
}, "selectionchange event on document fires"); | ||
|
||
promise_test(() => { | ||
return (async function() { | ||
let selectionChangeCount = 0; | ||
document.addEventListener("selectionchange", () => ++selectionChangeCount); | ||
container.innerHTML = '<span><br></span><span><br></span>'; | ||
getSelection().setPosition(container, 0); | ||
assert_equals(selectionChangeCount, 0); | ||
getSelection().setPosition(container, 2); | ||
assert_equals(selectionChangeCount, 0); | ||
await new Promise(setTimeout); | ||
assert_equals(selectionChangeCount, 1); | ||
})(); | ||
}, "selectionchange event on document fires once"); | ||
|
||
promise_test(() => { | ||
return (async function() { | ||
let selectionChangeCount = 0; | ||
document.addEventListener("selectionchange", () => ++selectionChangeCount); | ||
container.innerHTML = '<span><br></span><span><br></span>'; | ||
getSelection().setPosition(container, 0); | ||
assert_equals(selectionChangeCount, 0); | ||
getSelection().setPosition(container, 2); | ||
assert_equals(selectionChangeCount, 0); | ||
await new Promise(setTimeout); | ||
assert_equals(selectionChangeCount, 1); | ||
getSelection().setPosition(container, 0); | ||
assert_equals(selectionChangeCount, 1); | ||
getSelection().setPosition(container, 2); | ||
assert_equals(selectionChangeCount, 1); | ||
await new Promise(setTimeout); | ||
assert_equals(selectionChangeCount, 2); | ||
})(); | ||
}, "task to fire selectionchange event gets queued each time selection is mutated"); | ||
|
||
promise_test(() => { | ||
return (async function() { | ||
let selectionChangeCount = 0; | ||
document.addEventListener("selectionchange", () => { | ||
if (!selectionChangeCount) { | ||
getSelection().setPosition(container, 2); | ||
getSelection().setPosition(container, 0); | ||
} | ||
++selectionChangeCount; | ||
}); | ||
container.innerHTML = '<b><br></b><b><br></b>'; | ||
getSelection().setPosition(container, 0); | ||
assert_equals(selectionChangeCount, 0); | ||
await new Promise(setTimeout); | ||
assert_equals(selectionChangeCount, 1); | ||
await new Promise(setTimeout); | ||
assert_equals(selectionChangeCount, 2); | ||
})(); | ||
}, "has scheduled selectionchange event is set to false at the beginning of a task to fire selectionchange event"); | ||
|
||
</script> |
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