mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
Merge pull request #1875 from lightpanda-io/history_test_stability
Try to improve stability of history test
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
33
src/browser/tests/support/history.html
Normal file
33
src/browser/tests/support/history.html
Normal 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>
|
||||||
|
|
||||||
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user