fix navigation and related tests

This commit is contained in:
Muki Kiboigo
2025-10-10 04:02:42 -07:00
parent f97697535f
commit e9b08f19cf
14 changed files with 168 additions and 146 deletions

View File

@@ -11,10 +11,12 @@
testing.expectEqual('auto', history.scrollRestoration);
testing.expectEqual(null, history.state)
history.pushState({ testInProgress: true }, null, 'http://127.0.0.1:9582/xhr/json');
history.pushState({ testInProgress: true }, null, 'http://127.0.0.1:9582/src/tests/html/history2.html');
testing.expectEqual({ testInProgress: true }, history.state);
history.pushState({ testInProgress: false }, null, 'http://127.0.0.1:9582/xhr/json');
history.replaceState({ "new": "field", testComplete: true }, null);
let state = { "new": "field", testComplete: true };
testing.expectEqual(state, history.state);
@@ -31,10 +33,5 @@
testing.expectEqual(state, popstateEventState);
})
testing.onPageWait(() => {
testing.expectEqual(true, history.state && history.state.testComplete);
testing.expectEqual(state, history.state);
});
testing.expectEqual(undefined, history.go());
history.back();
</script>

View File

@@ -0,0 +1,6 @@
<!DOCTYPE html>
<script src="../testing.js"></script>
<script id=history2>
testing.expectEqual(true, history.state && history.state.testInProgress);
</script>

View File

@@ -1,5 +1,6 @@
<!DOCTYPE html>
<script src="../testing.js"></script>
<script id=navigation>
testing.expectEqual('object', typeof navigation);
testing.expectEqual('object', typeof navigation.currentEntry);
@@ -7,43 +8,11 @@
testing.expectEqual('string', typeof navigation.currentEntry.id);
testing.expectEqual('string', typeof navigation.currentEntry.key);
testing.expectEqual('string', typeof navigation.currentEntry.url);
testing.expectEqual(0, navigation.currentEntry.index);
testing.expectEqual(true, navigation.currentEntry.sameDocument);
let result = navigation.navigate('http://127.0.0.1:9582/xhr/json', {
state: { testInProgress: true }
});
testing.expectEqual('object', typeof result);
testing.expectEqual('object', typeof result.committed);
testing.expectEqual('object', typeof result.finished);
testing.expectEqual({ testInProgress: true }, navigation.currentEntry.getState());
testing.expectEqual(1, navigation.currentEntry.index);
testing.expectEqual(true, navigation.canGoBack);
testing.expectEqual(false, navigation.canGoForward);
testing.expectEqual(undefined, navigation.back());
testing.onPageWait(() => {
testing.expectEqual(0, navigation.currentEntry.index);
testing.expectEqual(true, navigation.canGoForward);
testing.expectEqual(undefined, navigation.forward());
});
testing.onPageWait(() => {
testing.expectEqual(1, navigation.currentEntry.index);
testing.expectEqual({ testInProgress: true }, navigation.currentEntry.getState());
let targetKey = navigation.currentEntry.key;
testing.expectEqual(undefined, navigation.traverseTo(targetKey));
});
navigation.updateCurrentEntry({ state: { updated: true, testComplete: true } });
testing.expectEqual({ updated: true, testComplete: true }, navigation.currentEntry.getState());
testing.onPageWait(() => {
testing.expectEqual(true, navigation.currentEntry.getState().testComplete);
});
const currentIndex = navigation.currentEntry.index;
navigation.navigate(
'http://127.0.0.1:9582/src/tests/html/navigation2.html',
{ state: { currentIndex: currentIndex, navTestInProgress: true } }
);
</script>

View File

@@ -0,0 +1,8 @@
<!DOCTYPE html>
<script src="../testing.js"></script>
<script id=navigation2>
const state = navigation.currentEntry.getState();
testing.expectEqual(true, state.navTestInProgress);
testing.expectEqual(state.currentIndex + 1, navigation.currentEntry.index);
</script>

View File

@@ -51,14 +51,6 @@
// if we're already in a fail state, return fail, nothing can recover this
if (testing._status === 'fail') return 'fail';
if (testing._isSecondWait) {
for (const pw of (testing._onPageWait)) {
testing._captured = pw[1];
pw[0]();
testing._captured = null;
}
}
// run any eventually's that we've captured
for (const ev of testing._eventually) {
testing._captured = ev[1];
@@ -101,18 +93,6 @@
_registerErrorCallback();
}
// Set expectations to happen on the next time that `page.wait` is executed.
//
// History specifically uses this as it queues navigation that needs to be checked
// when the next page is loaded.
function onPageWait(fn) {
// Store callbacks to run when page.wait() happens
testing._onPageWait.push([fn, {
script_id: document.currentScript.id,
stack: new Error().stack,
}]);
}
async function async(promise, cb) {
const script_id = document.currentScript ? document.currentScript.id : '<script id is unavailable in browsers>';
const stack = new Error().stack;
@@ -192,15 +172,12 @@
window.testing = {
_status: 'empty',
_eventually: [],
_onPageWait: [],
_executed_scripts: new Set(),
_captured: null,
_isSecondWait: false,
skip: skip,
async: async,
getStatus: getStatus,
eventually: eventually,
onPageWait: onPageWait,
expectEqual: expectEqual,
expectError: expectError,
withError: withError,