diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/back-204-205-download.html b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/back-204-205-download.html new file mode 100644 index 0000000000000..5bedbf21e8681 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/back-204-205-download.html @@ -0,0 +1,52 @@ + + + + + + + + diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/navigate-204-205-download.html b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/navigate-204-205-download.html new file mode 100644 index 0000000000000..f1e89b694057a --- /dev/null +++ b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/navigate-204-205-download.html @@ -0,0 +1,42 @@ + + + + + + + diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/resources/204-205-download-on-second-visit.py b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/resources/204-205-download-on-second-visit.py new file mode 100644 index 0000000000000..c18b0dec3dc6a --- /dev/null +++ b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/resources/204-205-download-on-second-visit.py @@ -0,0 +1,24 @@ +def main(request, response): + key = request.GET[b"id"] + + # If hit with a POST with ?action=X, store X in the stash + if request.method == "POST": + action = request.GET[b"action"] + request.server.stash.put(key, action) + + return (204, [], "") + + # If hit with a GET, either return a normal initial page, or the abnormal requested response + elif request.method == "GET": + action = request.server.stash.take(key) + + if action is None: + return (200, [("Content-Type", "text/html"), ("Cache-Control", "no-store")], "initial page") + if action == b"204": + return (204, [], "") + if action == b"205": + return (205, [], "") + if action == b"download": + return (200, [("Content-Type", "text/plain"), ("Content-Disposition", "attachment")], "some text to download") + + return (400, [], "") diff --git a/testing/web-platform/tests/navigation-api/ordering-and-transition/navigate-204-205-download-then-same-document.html b/testing/web-platform/tests/navigation-api/ordering-and-transition/navigate-204-205-download-then-same-document.html new file mode 100644 index 0000000000000..b7b6283fa70b9 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/ordering-and-transition/navigate-204-205-download-then-same-document.html @@ -0,0 +1,66 @@ + + + + + diff --git a/testing/web-platform/tests/navigation-api/ordering-and-transition/navigate-cross-document-double.html b/testing/web-platform/tests/navigation-api/ordering-and-transition/navigate-cross-document-double.html index 353cfa1b4e4b5..147b8d55ef150 100644 --- a/testing/web-platform/tests/navigation-api/ordering-and-transition/navigate-cross-document-double.html +++ b/testing/web-platform/tests/navigation-api/ordering-and-transition/navigate-cross-document-double.html @@ -2,22 +2,48 @@ - diff --git a/testing/web-platform/tests/navigation-api/ordering-and-transition/resources/helpers.mjs b/testing/web-platform/tests/navigation-api/ordering-and-transition/resources/helpers.mjs index 359774de4f72c..341befc10565d 100644 --- a/testing/web-platform/tests/navigation-api/ordering-and-transition/resources/helpers.mjs +++ b/testing/web-platform/tests/navigation-api/ordering-and-transition/resources/helpers.mjs @@ -7,6 +7,9 @@ export function hasVariant(name) { export class Recorder { #events = []; #errors = []; + #navigationAPI; + #domExceptionConstructor; + #location; #skipCurrentChange; #finalExpectedEvent; #finalExpectedEventCount; @@ -15,16 +18,20 @@ export class Recorder { #readyToAssertResolve; #readyToAssertPromise = new Promise(resolve => { this.#readyToAssertResolve = resolve; }); - constructor({ skipCurrentChange = false, finalExpectedEvent, finalExpectedEventCount = 1 }) { + constructor({ window = self, skipCurrentChange = false, finalExpectedEvent, finalExpectedEventCount = 1 }) { assert_equals(typeof finalExpectedEvent, "string", "Must pass a string for finalExpectedEvent"); + this.#navigationAPI = window.navigation; + this.#domExceptionConstructor = window.DOMException; + this.#location = window.location; + this.#skipCurrentChange = skipCurrentChange; this.#finalExpectedEvent = finalExpectedEvent; this.#finalExpectedEventCount = finalExpectedEventCount; } setUpNavigationAPIListeners() { - navigation.addEventListener("navigate", e => { + this.#navigationAPI.addEventListener("navigate", e => { this.record("navigate"); e.signal.addEventListener("abort", () => { @@ -32,26 +39,26 @@ export class Recorder { }); }); - navigation.addEventListener("navigateerror", e => { + this.#navigationAPI.addEventListener("navigateerror", e => { this.recordWithError("navigateerror", e.error); - navigation.transition?.finished.then( + this.#navigationAPI.transition?.finished.then( () => this.record("transition.finished fulfilled"), err => this.recordWithError("transition.finished rejected", err) ); }); - navigation.addEventListener("navigatesuccess", () => { + this.#navigationAPI.addEventListener("navigatesuccess", () => { this.record("navigatesuccess"); - navigation.transition?.finished.then( + this.#navigationAPI.transition?.finished.then( () => this.record("transition.finished fulfilled"), err => this.recordWithError("transition.finished rejected", err) ); }); if (!this.#skipCurrentChange) { - navigation.addEventListener("currententrychange", () => this.record("currententrychange")); + this.#navigationAPI.addEventListener("currententrychange", () => this.record("currententrychange")); } } @@ -68,12 +75,12 @@ export class Recorder { } record(name) { - const transitionProps = navigation.transition === null ? null : { - from: navigation.transition.from, - navigationType: navigation.transition.navigationType + const transitionProps = this.#navigationAPI.transition === null ? null : { + from: this.#navigationAPI.transition.from, + navigationType: this.#navigationAPI.transition.navigationType }; - this.#events.push({ name, location: location.hash, transitionProps }); + this.#events.push({ name, location: this.#location.hash, transitionProps }); if (name === this.#finalExpectedEvent && ++this.#currentFinalEventCount === this.#finalExpectedEventCount) { this.#readyToAssertResolve(); @@ -169,7 +176,7 @@ export class Recorder { // Assume assert() has been called so all error objects are the same. const { errorObject } = this.#errors[0]; - assert_throws_dom("AbortError", () => { throw errorObject; }); + assert_throws_dom("AbortError", this.#domExceptionConstructor, () => { throw errorObject; }); } assertErrorsAre(expectedErrorObject) {