forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App history: tweak and test event/promise ordering
By adding new exhaustive tests under ordering/, it was revealed that the ordering between navigatesuccess/navigateerror and the committed/finished promises was not always consistent: 1. Simply adding a currentchange event handler would cause microtasks to run during commit, which changed some ordering. 2. Calling transitionWhile() would take us from the zero-promise case to the 1+-promise case in ScriptPromise::All(). As the new comment explains, both the spec and implementation have an observably-different fast path for the 0-promise case which caused changes in ordering. In the course of fixing this, I found out that the did_finish_before_commit_ code in app_history_api_navigation.{h,cc} was actually not a mitigation for the case it stated, where promises passed to transitionWhile() would settle faster than the browser-process roundtrip for same-document traversals. That is in fact impossible, since we only fire the navigate event after the browser-process roundtrip has completed. Instead, they were a mitigation for (1). This commit then ensures consistent ordering, tested with new rather-exhaustive tests, in the following manner: * We move the firing of currentchange to before resolving the committed promise. This eliminates (1) and allows us to delete the did_finish_before_commit_ tracking. * We always ensure we pass 1+ promises to ScriptPromise::All(). This eliminates (2). A consequence of this is that we are now more likely to get rejected finished promises, in cases like await appHistory.navigate("#1").committed; await appHistory.navigate("#2").committed; Before, the finished promise for the #1 navigation would go through the fast path per (2), and fulfill before the navigation to #2 canceled it. Now that does not happen, so code like the above will give an unhandled promise rejection for #1's finished promise. To avoid this, we unconditionally mark finished promises as handled. This follows some web platform precedent, e.g. stream closed promises, where the promise is one of several information channels (in this case the developer might also find out via the AbortSignal or the navigateerror event). We do *not* do this for the committed promise though, as if a commit fails, that's probably something more deeply wrong, and cannot be ignored. All of these changes will require spec updates. For the tests, we introduce a new ordering/ directory which contains cross-cutting ordering tests, and we consolidate a few tests into the newly-introduced variant-driven exhaustive ones. A couple of other tests were affected by these changes too or fixed as a drive-by. Change-Id: I8a50ca28d009e0a8a2c94331cd17f29b0a8dc463 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3405377 Reviewed-by: Nate Chapin <japhet@chromium.org> Commit-Queue: Domenic Denicola <domenic@chromium.org> Cr-Commit-Position: refs/heads/main@{#963772}
- Loading branch information
1 parent
ed1f565
commit 3638c16
Showing
16 changed files
with
210 additions
and
75 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
30 changes: 0 additions & 30 deletions
30
app-history/navigate/navigate-same-document-event-order.html
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
app-history/navigate/navigate-transitionWhile-reject-event-order.html
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
# App history ordering tests | ||
|
||
These are meant to test the ordering between various events and promises; they | ||
don't fit into any particular sibling directory. | ||
|
||
Some of them test simple cases rather-exhaustively, and others test tricky cases | ||
(e.g. reentrancy or navigations aborting previous navigations) in a more focused | ||
way. | ||
|
||
Note: | ||
|
||
* Variants specifically exist for `currentchange` because an event listener | ||
existing for `currentchange` causes code to run, and thus microtasks to run, | ||
at a very specific point in the navigation-commit lifecycle. We want to test | ||
that it doesn't impact the ordering. | ||
* Similarly we test that `transitionWhile(Promise.resolve())` does not change | ||
the ordering compared to no `transitionWhile()` call, for same-document | ||
navigations. | ||
|
||
TODOs: | ||
|
||
* Also test `appHistory.transition.finished` when it is implemented. | ||
* Also test `popstate` and `hashchange` once | ||
<https://github.com/whatwg/html/issues/1792> is fixed. |
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,63 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<meta name="variant" content="?"> | ||
<meta name="variant" content="?transitionWhile"> | ||
<meta name="variant" content="?currentchange"> | ||
<meta name="variant" content="?transitionWhile¤tChange"> | ||
|
||
<script> | ||
const variants = new Set((new URLSearchParams(location.search)).keys()); | ||
|
||
promise_test(async t => { | ||
// Wait for after the load event so that the navigation doesn't get converted | ||
// into a replace navigation. | ||
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); | ||
|
||
await appHistory.navigate("#1").finished; | ||
|
||
const events = []; | ||
appHistory.addEventListener("navigatesuccess", () => events.push(`navigatesuccess ${location.hash}`)); | ||
appHistory.addEventListener("navigateerror", () => events.push(`navigateerror ${location.hash}`)); | ||
if (variants.has("currentchange")) { | ||
appHistory.addEventListener("currentchange", () => events.push(`currentchange ${location.hash}`)); | ||
} | ||
|
||
if (variants.has("transitionWhile")) { | ||
appHistory.addEventListener("navigate", e => { | ||
e.transitionWhile(Promise.resolve()); | ||
}); | ||
} | ||
|
||
const { committed, finished } = appHistory.back(); | ||
committed.then( | ||
() => events.push(`committed fulfilled ${location.hash}`), | ||
() => events.push(`committed rejected ${location.hash}`) | ||
); | ||
finished.then( | ||
() => events.push(`finished fulfilled ${location.hash}`), | ||
() => events.push(`finished rejected ${location.hash}`) | ||
); | ||
|
||
Promise.resolve().then(() => events.push(`promise microtask ${location.hash}`)); | ||
|
||
await finished; | ||
|
||
if (variants.has("currentchange")) { | ||
assert_array_equals(events, [ | ||
"promise microtask #1", | ||
"currentchange ", | ||
"committed fulfilled ", | ||
"navigatesuccess ", | ||
"finished fulfilled " | ||
]); | ||
} else { | ||
assert_array_equals(events, [ | ||
"promise microtask #1", | ||
"committed fulfilled ", | ||
"navigatesuccess ", | ||
"finished fulfilled " | ||
]); | ||
} | ||
}, "event and promise ordering for same-document appHistory.back()"); | ||
</script> |
File renamed without changes.
File renamed without changes.
57 changes: 57 additions & 0 deletions
57
app-history/ordering/navigate-same-document-transitionWhile-reject.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,57 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<meta name="variant" content="?"> | ||
<meta name="variant" content="?currentchange"> | ||
|
||
<script> | ||
const variants = new Set((new URLSearchParams(location.search)).keys()); | ||
|
||
promise_test(async t => { | ||
// Wait for after the load event so that the navigation doesn't get converted | ||
// into a replace navigation. | ||
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); | ||
|
||
const events = []; | ||
appHistory.addEventListener("navigatesuccess", () => events.push(`navigatesuccess ${location.hash}`)); | ||
appHistory.addEventListener("navigateerror", () => events.push(`navigateerror ${location.hash}`)); | ||
if (variants.has("currentchange")) { | ||
appHistory.addEventListener("currentchange", () => events.push(`currentchange ${location.hash}`)); | ||
} | ||
|
||
appHistory.addEventListener("navigate", e => { | ||
e.transitionWhile(Promise.reject()); | ||
}); | ||
|
||
const { committed, finished } = appHistory.navigate("#1"); | ||
committed.then( | ||
() => events.push(`committed fulfilled ${location.hash}`), | ||
() => events.push(`committed rejected ${location.hash}`) | ||
); | ||
finished.then( | ||
() => events.push(`finished fulfilled ${location.hash}`), | ||
() => events.push(`finished rejected ${location.hash}`) | ||
); | ||
|
||
Promise.resolve().then(() => events.push(`promise microtask ${location.hash}`)); | ||
|
||
await finished.catch(() => {}); | ||
|
||
if (variants.has("currentchange")) { | ||
assert_array_equals(events, [ | ||
"currentchange #1", | ||
"committed fulfilled #1", | ||
"promise microtask #1", | ||
"navigateerror #1", | ||
"finished rejected #1" | ||
]); | ||
} else { | ||
assert_array_equals(events, [ | ||
"committed fulfilled #1", | ||
"promise microtask #1", | ||
"navigateerror #1", | ||
"finished rejected #1" | ||
]); | ||
} | ||
}, "event and promise ordering for appHistory.navigate() with a rejected promise passed to transitionWhile()"); | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<meta name="variant" content="?"> | ||
<meta name="variant" content="?transitionWhile"> | ||
<meta name="variant" content="?currentchange"> | ||
<meta name="variant" content="?transitionWhile¤tChange"> | ||
|
||
<script> | ||
const variants = new Set((new URLSearchParams(location.search)).keys()); | ||
|
||
promise_test(async t => { | ||
// Wait for after the load event so that the navigation doesn't get converted | ||
// into a replace navigation. | ||
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); | ||
|
||
const events = []; | ||
appHistory.addEventListener("navigatesuccess", () => events.push(`navigatesuccess ${location.hash}`)); | ||
appHistory.addEventListener("navigateerror", () => events.push(`navigateerror ${location.hash}`)); | ||
if (variants.has("currentchange")) { | ||
appHistory.addEventListener("currentchange", () => events.push(`currentchange ${location.hash}`)); | ||
} | ||
|
||
if (variants.has("transitionWhile")) { | ||
appHistory.addEventListener("navigate", e => { | ||
e.transitionWhile(Promise.resolve()); | ||
}); | ||
} | ||
|
||
const { committed, finished } = appHistory.navigate("#1"); | ||
committed.then( | ||
() => events.push(`committed fulfilled ${location.hash}`), | ||
() => events.push(`committed rejected ${location.hash}`) | ||
); | ||
finished.then( | ||
() => events.push(`finished fulfilled ${location.hash}`), | ||
() => events.push(`finished rejected ${location.hash}`) | ||
); | ||
|
||
Promise.resolve().then(() => events.push(`promise microtask ${location.hash}`)); | ||
|
||
await finished; | ||
|
||
if (variants.has("currentchange")) { | ||
assert_array_equals(events, [ | ||
"currentchange #1", | ||
"committed fulfilled #1", | ||
"promise microtask #1", | ||
"navigatesuccess #1", | ||
"finished fulfilled #1" | ||
]); | ||
} else { | ||
assert_array_equals(events, [ | ||
"committed fulfilled #1", | ||
"promise microtask #1", | ||
"navigatesuccess #1", | ||
"finished fulfilled #1" | ||
]); | ||
} | ||
}, "event and promise ordering for same-document appHistory.navigate()"); | ||
</script> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.