mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
add history tests
This commit is contained in:
@@ -404,6 +404,13 @@ pub fn htmlRunner(file: []const u8) !void {
|
||||
try page.navigate(url, .{});
|
||||
_ = page.wait(2000);
|
||||
|
||||
const needs_second_wait = try js_context.exec("testing._onPageWait.length > 0", "check_onPageWait");
|
||||
if (needs_second_wait.value.toBool(page.main_context.isolate)) {
|
||||
// sets the isSecondWait flag in testing.
|
||||
_ = js_context.exec("testing._isSecondWait = true", "set_second_wait_flag") catch {};
|
||||
_ = page.wait(2000);
|
||||
}
|
||||
|
||||
@import("root").js_runner_duration += std.time.Instant.since(try std.time.Instant.now(), start);
|
||||
|
||||
const value = js_context.exec("testing.getStatus()", "testing.getStatus()") catch |err| {
|
||||
|
||||
@@ -2,30 +2,30 @@
|
||||
<script src="../testing.js"></script>
|
||||
|
||||
<script id=history>
|
||||
testing.expectEqual('auto', history.scrollRestoration);
|
||||
testing.expectEqual('auto', history.scrollRestoration);
|
||||
|
||||
history.scrollRestoration = 'manual';
|
||||
history.scrollRestoration = 'foo';
|
||||
testing.expectEqual('manual', history.scrollRestoration);
|
||||
history.scrollRestoration = 'manual';
|
||||
history.scrollRestoration = 'foo';
|
||||
testing.expectEqual('manual', history.scrollRestoration);
|
||||
|
||||
history.scrollRestoration = 'auto';
|
||||
testing.expectEqual('auto', history.scrollRestoration);
|
||||
history.scrollRestoration = 'auto';
|
||||
testing.expectEqual('auto', history.scrollRestoration);
|
||||
testing.expectEqual(null, history.state)
|
||||
|
||||
testing.expectEqual(null, history.state)
|
||||
history.pushState({ testInProgress: true }, null, 'http://127.0.0.1:9582/xhr/json');
|
||||
testing.expectEqual({ testInProgress: true }, history.state);
|
||||
|
||||
history.pushState({}, null, '');
|
||||
history.replaceState({}, null, '');
|
||||
history.replaceState({ "new": "field", testComplete: true }, null);
|
||||
let state = { "new": "field", testComplete: true };
|
||||
testing.expectEqual(state, history.state);
|
||||
|
||||
testing.expectEqual(undefined, history.go());
|
||||
testing.expectEqual(undefined, history.go(1));
|
||||
testing.expectEqual(undefined, history.go(-1));
|
||||
testing.expectEqual(undefined, history.forward());
|
||||
testing.expectEqual(undefined, history.back());
|
||||
</script>
|
||||
|
||||
<script id=history-states>
|
||||
testing.expectEqual(null, history.state)
|
||||
|
||||
history.pushState({}, { "abc": "def" }, '');
|
||||
testing.expectEqual({ "abc": "def"}, history.state);
|
||||
testing.expectEqual(undefined, history.back());
|
||||
testing.expectEqual(undefined, history.forward());
|
||||
|
||||
testing.onPageWait(() => {
|
||||
testing.expectEqual(true, history.state && history.state.testComplete);
|
||||
testing.expectEqual(state, history.state);
|
||||
});
|
||||
|
||||
testing.expectEqual(undefined, history.go());
|
||||
</script>
|
||||
|
||||
@@ -50,6 +50,15 @@
|
||||
function getStatus() {
|
||||
// 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];
|
||||
@@ -92,6 +101,18 @@
|
||||
_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;
|
||||
@@ -171,12 +192,15 @@
|
||||
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