-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fire toggle events using a microtask
Instead of firing the async popover toggle events using a regular task, they should be fired at microtask timing to be faster. As suggested in the issue, this patch also uses microtasks for the dialog element's close event and the details element's toggle event: whatwg/html#9046 Bug: 1485980 Change-Id: I70569a36e6447283a5101117693d235020ebb4a6
- Loading branch information
1 parent
a230a40
commit 7fd6bd7
Showing
9 changed files
with
110 additions
and
26 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
29 changes: 29 additions & 0 deletions
29
.../semantics/interactive-elements/the-details-element/toggle-event-microtask.tentative.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,29 @@ | ||
<!DOCTYPE html> | ||
<link rel=author href="mailto:[email protected]"> | ||
<link rel=help href="https://github.com/whatwg/html/issues/9046"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<details>hello</details> | ||
|
||
<script> | ||
promise_test(async () => { | ||
// Toggling details elements during parsing may have special behavior. | ||
await new Promise(resolve => window.onload = resolve); | ||
|
||
const details = document.querySelector('details'); | ||
let gotToggleEvent = false; | ||
details.ontoggle = () => gotToggleEvent = true; | ||
|
||
// Asserting inside the microtask callback causes a timeout, so pull the | ||
// value out instead. | ||
const gotToggleEventInTime = await new Promise(resolve => { | ||
details.open = true; | ||
queueMicrotask(() => { | ||
resolve(gotToggleEvent); | ||
}); | ||
}); | ||
|
||
assert_true(gotToggleEventInTime); | ||
}, '<details> toggle events should be fired at microtask timing.'); | ||
</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
27 changes: 27 additions & 0 deletions
27
html/semantics/interactive-elements/the-dialog-element/close-event-microtask.tentative.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,27 @@ | ||
<!DOCTYPE html> | ||
<link rel=author href="mailto:[email protected]"> | ||
<link rel=help href="https://github.com/whatwg/html/issues/9046"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<dialog>dialog</dialog> | ||
|
||
<script> | ||
promise_test(async () => { | ||
const dialog = document.querySelector('dialog'); | ||
dialog.showModal(); | ||
|
||
let gotClose = false; | ||
dialog.addEventListener('close', () => gotClose = true); | ||
|
||
// Asserting inside the microtask callback causes a timeout, so pull the | ||
// value out instead. | ||
const gotCloseInTime = await new Promise(resolve => { | ||
dialog.close(); | ||
queueMicrotask(() => { | ||
resolve(gotClose); | ||
}); | ||
}); | ||
assert_true(gotCloseInTime); | ||
}, '<dialog> close events should be fired at microtask timing.'); | ||
</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
37 changes: 37 additions & 0 deletions
37
html/semantics/popovers/toggle-event-microtask.tentative.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,37 @@ | ||
<!DOCTYPE html> | ||
<link rel=author href="mailto:[email protected]"> | ||
<link rel=help href="https://github.com/whatwg/html/issues/9046"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<div popover=auto>popover</div> | ||
|
||
<script> | ||
promise_test(async () => { | ||
const popover = document.querySelector('div'); | ||
|
||
let gotToggle = false; | ||
popover.addEventListener('toggle', () => gotToggle = true); | ||
|
||
// Asserting inside the microtask callback causes a timeout, so pull the | ||
// value out instead. | ||
let gotToggleInTime = await new Promise(resolve => { | ||
popover.showPopover(); | ||
queueMicrotask(() => { | ||
resolve(gotToggle); | ||
}); | ||
}); | ||
assert_true(gotToggleInTime, 'opening toggle'); | ||
|
||
gotToggle = false; | ||
gotToggleInTime = false; | ||
|
||
gotToggleInTime = await new Promise(resolve => { | ||
popover.hidePopover(); | ||
queueMicrotask(() => { | ||
resolve(gotToggle); | ||
}); | ||
}); | ||
assert_true(gotToggleInTime, 'closing toggle'); | ||
}, 'popover toggle events should be fired at microtask timing.'); | ||
</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
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