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, .{});
|
try page.navigate(url, .{});
|
||||||
_ = page.wait(2000);
|
_ = 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);
|
@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| {
|
const value = js_context.exec("testing.getStatus()", "testing.getStatus()") catch |err| {
|
||||||
|
|||||||
@@ -2,30 +2,30 @@
|
|||||||
<script src="../testing.js"></script>
|
<script src="../testing.js"></script>
|
||||||
|
|
||||||
<script id=history>
|
<script id=history>
|
||||||
testing.expectEqual('auto', history.scrollRestoration);
|
testing.expectEqual('auto', history.scrollRestoration);
|
||||||
|
|
||||||
history.scrollRestoration = 'manual';
|
history.scrollRestoration = 'manual';
|
||||||
history.scrollRestoration = 'foo';
|
history.scrollRestoration = 'foo';
|
||||||
testing.expectEqual('manual', history.scrollRestoration);
|
testing.expectEqual('manual', history.scrollRestoration);
|
||||||
|
|
||||||
history.scrollRestoration = 'auto';
|
history.scrollRestoration = 'auto';
|
||||||
testing.expectEqual('auto', history.scrollRestoration);
|
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({ "new": "field", testComplete: true }, null);
|
||||||
history.replaceState({}, null, '');
|
let state = { "new": "field", testComplete: true };
|
||||||
|
testing.expectEqual(state, history.state);
|
||||||
|
|
||||||
testing.expectEqual(undefined, history.go());
|
testing.expectEqual(undefined, history.back());
|
||||||
testing.expectEqual(undefined, history.go(1));
|
testing.expectEqual(undefined, history.forward());
|
||||||
testing.expectEqual(undefined, history.go(-1));
|
|
||||||
testing.expectEqual(undefined, history.forward());
|
testing.onPageWait(() => {
|
||||||
testing.expectEqual(undefined, history.back());
|
testing.expectEqual(true, history.state && history.state.testComplete);
|
||||||
</script>
|
testing.expectEqual(state, history.state);
|
||||||
|
});
|
||||||
<script id=history-states>
|
|
||||||
testing.expectEqual(null, history.state)
|
testing.expectEqual(undefined, history.go());
|
||||||
|
|
||||||
history.pushState({}, { "abc": "def" }, '');
|
|
||||||
testing.expectEqual({ "abc": "def"}, history.state);
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -50,6 +50,15 @@
|
|||||||
function getStatus() {
|
function getStatus() {
|
||||||
// if we're already in a fail state, return fail, nothing can recover this
|
// if we're already in a fail state, return fail, nothing can recover this
|
||||||
if (testing._status === 'fail') return 'fail';
|
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
|
// run any eventually's that we've captured
|
||||||
for (const ev of testing._eventually) {
|
for (const ev of testing._eventually) {
|
||||||
testing._captured = ev[1];
|
testing._captured = ev[1];
|
||||||
@@ -92,6 +101,18 @@
|
|||||||
_registerErrorCallback();
|
_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) {
|
async function async(promise, cb) {
|
||||||
const script_id = document.currentScript ? document.currentScript.id : '<script id is unavailable in browsers>';
|
const script_id = document.currentScript ? document.currentScript.id : '<script id is unavailable in browsers>';
|
||||||
const stack = new Error().stack;
|
const stack = new Error().stack;
|
||||||
@@ -171,12 +192,15 @@
|
|||||||
window.testing = {
|
window.testing = {
|
||||||
_status: 'empty',
|
_status: 'empty',
|
||||||
_eventually: [],
|
_eventually: [],
|
||||||
|
_onPageWait: [],
|
||||||
_executed_scripts: new Set(),
|
_executed_scripts: new Set(),
|
||||||
_captured: null,
|
_captured: null,
|
||||||
|
_isSecondWait: false,
|
||||||
skip: skip,
|
skip: skip,
|
||||||
async: async,
|
async: async,
|
||||||
getStatus: getStatus,
|
getStatus: getStatus,
|
||||||
eventually: eventually,
|
eventually: eventually,
|
||||||
|
onPageWait: onPageWait,
|
||||||
expectEqual: expectEqual,
|
expectEqual: expectEqual,
|
||||||
expectError: expectError,
|
expectError: expectError,
|
||||||
withError: withError,
|
withError: withError,
|
||||||
|
|||||||
Reference in New Issue
Block a user