mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 04:52:06 +02:00
LibWeb: Align Navigable::reload() with the specification
This commit is contained in:
committed by
Shannon Booth
parent
dc649a7e46
commit
5060a61081
Notes:
github-actions[bot]
2026-02-14 19:23:15 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/5060a610815 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7875 Reviewed-by: https://github.com/shannonbooth ✅
@@ -0,0 +1,40 @@
|
||||
<!doctype html>
|
||||
<script src="../../resources/testharness.js"></script>
|
||||
<script src="../../resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="../../common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
const navState1 = { key: "value" };
|
||||
const navState2 = { key2: "value2" };
|
||||
const navInfo = { infoKey: "infoValue" };
|
||||
i.contentWindow.navigation.navigate("#1", { state: navState1 }).committed.then(t.step_func(() => {
|
||||
// Make sure that state setting worked
|
||||
assert_equals(i.contentWindow.navigation.currentEntry.getState().key, "value", "initial state setup");
|
||||
assert_not_equals(i.contentWindow.navigation.currentEntry.getState(), navState1);
|
||||
|
||||
let start_url = i.contentWindow.location.href;
|
||||
let start_key = i.contentWindow.navigation.currentEntry.key;
|
||||
let start_id = i.contentWindow.navigation.currentEntry.id;
|
||||
let onnavigate_called = false;
|
||||
let promise_settled = false;
|
||||
i.contentWindow.navigation.onnavigate = t.step_func(e => {
|
||||
e.intercept();
|
||||
onnavigate_called = true;
|
||||
assert_equals(e.info, navInfo);
|
||||
assert_equals(e.navigationType, "reload");
|
||||
assert_equals(e.destination.getState().key2, "value2", "navigate event for the reload()");
|
||||
assert_not_equals(e.destination.getState(), navState2);
|
||||
});
|
||||
i.contentWindow.navigation.reload({ info: navInfo, state: navState2 }).committed.then(t.step_func_done(() => {
|
||||
assert_true(onnavigate_called);
|
||||
assert_equals(i.contentWindow.location.href, start_url);
|
||||
assert_equals(i.contentWindow.navigation.currentEntry.key, start_key);
|
||||
assert_equals(i.contentWindow.navigation.currentEntry.id, start_id);
|
||||
assert_equals(i.contentWindow.navigation.currentEntry.getState().key2, "value2", "currentEntry.getState() after the reload");
|
||||
assert_not_equals(i.contentWindow.navigation.currentEntry.getState(), navState2);
|
||||
}));
|
||||
}));
|
||||
});
|
||||
}, "reload() variant with info and new state");
|
||||
</script>
|
||||
@@ -0,0 +1,39 @@
|
||||
<!doctype html>
|
||||
<script src="../../resources/testharness.js"></script>
|
||||
<script src="../../resources/testharnessreport.js"></script>
|
||||
<iframe id="i" src="../../common/blank.html"></iframe>
|
||||
<script>
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
const navState = { key: "value" };
|
||||
const navInfo = { infoKey: "infoValue" };
|
||||
i.contentWindow.navigation.navigate("#1", { state: navState }).committed.then(t.step_func(() => {
|
||||
// Make sure that state setting worked
|
||||
assert_equals(i.contentWindow.navigation.currentEntry.getState().key, "value");
|
||||
assert_not_equals(i.contentWindow.navigation.currentEntry.getState(), navState);
|
||||
|
||||
let start_url = i.contentWindow.location.href;
|
||||
let start_key = i.contentWindow.navigation.currentEntry.key;
|
||||
let start_id = i.contentWindow.navigation.currentEntry.id;
|
||||
let onnavigate_called = false;
|
||||
let promise_settled = false;
|
||||
i.contentWindow.navigation.onnavigate = t.step_func(e => {
|
||||
e.intercept();
|
||||
onnavigate_called = true;
|
||||
assert_equals(e.info, navInfo);
|
||||
assert_equals(e.navigationType, "reload");
|
||||
assert_equals(e.destination.getState().key, "value", "destination.getState()");
|
||||
assert_not_equals(e.destination.getState(), navState);
|
||||
});
|
||||
i.contentWindow.navigation.reload({ info: navInfo, state: undefined }).committed.then(t.step_func_done(() => {
|
||||
assert_true(onnavigate_called);
|
||||
assert_equals(i.contentWindow.location.href, start_url);
|
||||
assert_equals(i.contentWindow.navigation.currentEntry.key, start_key);
|
||||
assert_equals(i.contentWindow.navigation.currentEntry.id, start_id);
|
||||
assert_equals(i.contentWindow.navigation.currentEntry.getState().key, "value", "destination.getState()");
|
||||
assert_not_equals(i.contentWindow.navigation.currentEntry.getState(), navState);
|
||||
}));
|
||||
}));
|
||||
});
|
||||
}, "reload() variant with info and state: undefined counts the same as not present (because of Web IDL dictionary semantics), so preserves the state");
|
||||
</script>
|
||||
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<script src="../../../resources/testharness.js"></script>
|
||||
<script src="../../../resources/testharnessreport.js"></script>
|
||||
<script src="resources/helpers.js"></script>
|
||||
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
const err = new Error("boo!");
|
||||
const promise = Promise.reject(err);
|
||||
promise.catch(() => {}); // prevent unhandled rejection testharness.js errors
|
||||
navigation.onnavigate = e => e.intercept({ handler: () => promise });
|
||||
|
||||
const result = navigation.reload();
|
||||
|
||||
await assertCommittedFulfillsFinishedRejectsExactly(t, result, navigation.currentEntry, err);
|
||||
}, "reload() and intercept() with a rejected promise");
|
||||
</script>
|
||||
@@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<script src="../../../resources/testharness.js"></script>
|
||||
<script src="../../../resources/testharnessreport.js"></script>
|
||||
<script src="resources/helpers.js"></script>
|
||||
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
navigation.onnavigate = e => e.intercept({ handler: () => Promise.resolve({ abc: 'def' }) });
|
||||
|
||||
const result = navigation.reload();
|
||||
|
||||
await assertBothFulfill(t, result, navigation.currentEntry);
|
||||
}, "reload() and intercept() with a fulfilled promise");
|
||||
</script>
|
||||
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<script src="../../../resources/testharness.js"></script>
|
||||
<script src="../../../resources/testharnessreport.js"></script>
|
||||
<script src="resources/helpers.js"></script>
|
||||
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
navigation.onnavigate = e => e.preventDefault();
|
||||
|
||||
await assertBothRejectDOM(t, navigation.reload(), "AbortError");
|
||||
}, "reload() when the onnavigate handler calls preventDefault()");
|
||||
</script>
|
||||
Reference in New Issue
Block a user