Merge pull request #1875 from lightpanda-io/history_test_stability

Try to improve stability of history test
This commit is contained in:
Karl Seguin
2026-03-17 12:21:29 +08:00
committed by GitHub
3 changed files with 46 additions and 34 deletions

View File

@@ -2,37 +2,17 @@
<script src="testing.js"></script> <script src="testing.js"></script>
<script id=history> <script id=history>
testing.expectEqual('auto', history.scrollRestoration); // This test is a bit wonky. But it's trying to test navigation, which is
// something we can't do in the main page (we can't navigate away from this
history.scrollRestoration = 'manual'; // page and still assertOk in the test runner).
testing.expectEqual('manual', history.scrollRestoration); // If support/history.html has a failed assertion, it'll log the error and
// stop the script. If it succeeds, it'll set support_history_completed
history.scrollRestoration = 'auto'; // which we can use here to assume everything passed.
testing.expectEqual('auto', history.scrollRestoration);
testing.expectEqual(null, history.state)
history.pushState({ testInProgress: true }, null, 'http://127.0.0.1:9582/src/browser/tests/history_after_nav.skip.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);
let popstateEventFired = false;
let popstateEventState = null;
window.addEventListener('popstate', (event) => {
popstateEventFired = true;
popstateEventState = event.state;
});
testing.eventually(() => { testing.eventually(() => {
testing.expectEqual(true, popstateEventFired); testing.expectEqual(true, window.support_history_completed);
testing.expectEqual({testInProgress: true }, popstateEventState); testing.expectEqual(true, window.support_history_popstateEventFired);
}) testing.expectEqual({testInProgress: true }, window.support_history_popstateEventState);
});
history.back();
</script> </script>
<iframe id=frame src="support/history.html"></iframe>

View File

@@ -0,0 +1,33 @@
<!DOCTYPE html>
<script src="../testing.js"></script>
<script id=history>
testing.expectEqual('auto', history.scrollRestoration);
history.scrollRestoration = 'manual';
testing.expectEqual('manual', history.scrollRestoration);
history.scrollRestoration = 'auto';
testing.expectEqual('auto', history.scrollRestoration);
testing.expectEqual(null, history.state)
history.pushState({ testInProgress: true }, null, testing.BASE_URL + 'history_after_nav.skip.html');
testing.expectEqual({ testInProgress: true }, history.state);
history.pushState({ testInProgress: false }, null, testing.ORIGIN + '/xhr/json');
history.replaceState({ "new": "field", testComplete: true }, null);
let state = { "new": "field", testComplete: true };
testing.expectEqual(state, history.state);
let popstateEventFired = false;
let popstateEventState = null;
window.top.support_history_completed = true;
window.addEventListener('popstate', (event) => {
window.top.window.support_history_popstateEventFired = true;
window.top.window.support_history_popstateEventState = event.state;
});
history.back();
</script>

View File

@@ -99,8 +99,7 @@
} }
} }
// our test runner sets this to true const IS_TEST_RUNNER = window.navigator.userAgent.startsWith("Lightpanda/");
const IS_TEST_RUNNER = window._lightpanda_skip_auto_assert === true;
window.testing = { window.testing = {
fail: fail, fail: fail,
@@ -118,7 +117,7 @@
BASE_URL: 'http://127.0.0.1:9582/src/browser/tests/', BASE_URL: 'http://127.0.0.1:9582/src/browser/tests/',
}; };
if (window.navigator.userAgent.startsWith("Lightpanda/") == false) { if (IS_TEST_RUNNER === false) {
// The page is running in a different browser. Probably a developer making sure // The page is running in a different browser. Probably a developer making sure
// a test is correct. There are a few tweaks we need to do to make this a // a test is correct. There are a few tweaks we need to do to make this a
// seemless, namely around adapting paths/urls. // seemless, namely around adapting paths/urls.