mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-16 16:28:58 +00:00
fix navigation and related tests
This commit is contained in:
@@ -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>
|
||||
|
||||
6
src/tests/html/history2.html
Normal file
6
src/tests/html/history2.html
Normal file
@@ -0,0 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<script src="../testing.js"></script>
|
||||
|
||||
<script id=history2>
|
||||
testing.expectEqual(true, history.state && history.state.testInProgress);
|
||||
</script>
|
||||
@@ -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>
|
||||
|
||||
8
src/tests/html/navigation2.html
Normal file
8
src/tests/html/navigation2.html
Normal 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>
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user