diff options
Diffstat (limited to 'testing/web-platform/tests/navigation-api/navigation-methods/return-value/resources')
4 files changed, 195 insertions, 0 deletions
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 0000000000..c18b0dec3d --- /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/navigation-methods/return-value/resources/back-forward-opaque-origin-page.html b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/resources/back-forward-opaque-origin-page.html new file mode 100644 index 0000000000..ec63363952 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/resources/back-forward-opaque-origin-page.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="helpers.js"></script> +<!-- Put this page in a sandbox to give it an opaque origin --> + +<script> +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)); + + navigation.onnavigate = t.unreached_func("onnavigate should not be called"); + navigation.onnavigatesuccess = t.unreached_func("onnavigatesuccess should not be called"); + navigation.onnavigateerror = t.unreached_func("onnavigateerror should not be called"); + + location.hash = "#1"; + await new Promise(resolve => window.onhashchange = resolve); + location.hash = "#2"; + await new Promise(resolve => window.onhashchange = resolve); + history.back(); + await new Promise(resolve => window.onhashchange = resolve); + + assert_equals(location.hash, "#1"); + + await assertBothRejectDOM(t, navigation.back(), "InvalidStateError"); + await assertBothRejectDOM(t, navigation.forward(), "InvalidStateError"); +}, "navigation.back()/forward() in an opaque origin iframe"); +</script> diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/resources/helpers.js b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/resources/helpers.js new file mode 100644 index 0000000000..63d706ed28 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/resources/helpers.js @@ -0,0 +1,127 @@ +window.assertReturnValue = (result, w = window) => { + assert_equals(Object.getPrototypeOf(result), w.Object.prototype, "result object must be from the right realm"); + assert_array_equals(Reflect.ownKeys(result), ["committed", "finished"]); + assert_true(result.committed instanceof w.Promise); + assert_true(result.finished instanceof w.Promise); + assert_not_equals(result.committed, result.finished); +}; + +window.assertNeverSettles = (t, result, w = window) => { + assertReturnValue(result, w); + result.committed.then( + t.unreached_func("committed must not fulfill"), + t.unreached_func("committed must not reject") + ); + + result.finished.then( + t.unreached_func("finished must not fulfill"), + t.unreached_func("finished must not reject") + ); +}; + +window.assertBothFulfillEntryNotAvailable = async (t, result, w = window) => { + assertReturnValue(result, w); + + // Don't use await here so that we can catch out-of-order settlements. + let committedValue; + result.committed.then( + t.step_func(v => { committedValue = v;}), + t.unreached_func("committed must not reject") + ); + + const finishedValue = await result.finished; + + assert_not_equals(committedValue, undefined, "committed must fulfill before finished"); + assert_equals(finishedValue, committedValue, "committed and finished must fulfill with the same value"); + assert_true(finishedValue instanceof w.NavigationHistoryEntry, "fulfillment value must be a NavigationHistoryEntry"); +}; + +window.assertBothFulfill = async (t, result, expected, w = window) => { + assertReturnValue(result, w); + + // Don't use await here so that we can catch out-of-order settlements. + let committedValue; + result.committed.then( + t.step_func(v => { committedValue = v; }), + t.unreached_func("committed must not reject") + ); + + const finishedValue = await result.finished; + + assert_not_equals(committedValue, undefined, "committed must fulfill before finished"); + assert_equals(finishedValue, committedValue, "committed and finished must fulfill with the same value"); + assert_true(finishedValue instanceof w.NavigationHistoryEntry, "fulfillment value must be a NavigationHistoryEntry"); + assert_equals(finishedValue, expected); +}; + +window.assertCommittedFulfillsFinishedRejectsExactly = async (t, result, expectedEntry, expectedRejection, w = window) => { + assertReturnValue(result, w); + + // Don't use await here so that we can catch out-of-order settlements. + let committedValue; + result.committed.then( + t.step_func(v => { committedValue = v; }), + t.unreached_func("committed must not reject") + ); + + await promise_rejects_exactly(t, expectedRejection, result.finished); + + assert_not_equals(committedValue, undefined, "committed must fulfill before finished rejects"); + assert_true(committedValue instanceof w.NavigationHistoryEntry, "fulfillment value must be a NavigationHistoryEntry"); + assert_equals(committedValue, expectedEntry); +}; + +window.assertCommittedFulfillsFinishedRejectsDOM = async (t, result, expectedEntry, expectedDOMExceptionCode, w = window, domExceptionConstructor = w.DOMException, navigationHistoryEntryConstuctor = w.NavigationHistoryEntry) => { + assertReturnValue(result, w); + + let committedValue; + result.committed.then( + t.step_func(v => { committedValue = v; }), + t.unreached_func("committed must not reject") + ); + + await promise_rejects_dom(t, expectedDOMExceptionCode, domExceptionConstructor, result.finished); + + assert_not_equals(committedValue, undefined, "committed must fulfill before finished rejects"); + assert_true(committedValue instanceof navigationHistoryEntryConstuctor, "fulfillment value must be an NavigationHistoryEntry"); + assert_equals(committedValue, expectedEntry); +}; + +window.assertBothRejectExactly = async (t, result, expectedRejection, w = window) => { + assertReturnValue(result, w); + + let committedReason, finishedReason; + await Promise.all([ + result.committed.then( + t.unreached_func("committed must not fulfill"), + t.step_func(r => { committedReason = r; }) + ), + result.finished.then( + t.unreached_func("finished must not fulfill"), + t.step_func(r => { finishedReason = r; }) + ) + ]); + + assert_equals(committedReason, finishedReason, "committed and finished must reject with the same value"); + assert_equals(expectedRejection, committedReason); +}; + +window.assertBothRejectDOM = async (t, result, expectedDOMExceptionCode, w = window, domExceptionConstructor = w.DOMException) => { + assertReturnValue(result, w); + + // Don't use await here so that we can catch out-of-order settlements. + let committedReason, finishedReason; + await Promise.all([ + result.committed.then( + t.unreached_func("committed must not fulfill"), + t.step_func(r => { committedReason = r; }) + ), + result.finished.then( + t.unreached_func("finished must not fulfill"), + t.step_func(r => { finishedReason = r; }) + ) + ]); + + assert_equals(committedReason, finishedReason, "committed and finished must reject with the same value"); + assert_throws_dom(expectedDOMExceptionCode, domExceptionConstructor, () => { throw committedReason; }); +}; diff --git a/testing/web-platform/tests/navigation-api/navigation-methods/return-value/resources/navigate-opaque-origin-page.html b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/resources/navigate-opaque-origin-page.html new file mode 100644 index 0000000000..831eefdb61 --- /dev/null +++ b/testing/web-platform/tests/navigation-api/navigation-methods/return-value/resources/navigate-opaque-origin-page.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="helpers.js"></script> +<!-- Put this page in a sandbox to give it an opaque origin --> + +<script> +promise_test(async t => { + navigation.onnavigate = t.unreached_func("onnavigate should not be called"); + navigation.onnavigatesuccess = t.unreached_func("onnavigatesuccess should not be called"); + navigation.onnavigateerror = t.unreached_func("onnavigateerror should not be called"); + + const result = navigation.navigate("#1"); + assertNeverSettles(t, result); + await new Promise(resolve => t.step_timeout(resolve, 10)); +}, "navigation.navigate() in an opaque origin iframe"); +</script> |