mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-07 19:57:45 +03:00
Tests: Add tests for navigation.navigate()
This commit is contained in:
parent
19e802d09c
commit
682a6d5882
Notes:
sideshowbarker
2024-07-17 03:59:29 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/682a6d5882 Pull-request: https://github.com/SerenityOS/serenity/pull/22850
@ -0,0 +1,7 @@
|
||||
Initial history length is 1
|
||||
NavigateEvent for Push navigation-navigate-iframe.html#1 (Same document? true) with info: 42
|
||||
currententrychange for change to navigation-navigate-iframe.html#1 of type Push from navigation-navigate-iframe.html
|
||||
Committed to navigation to navigation-navigate-iframe.html#1
|
||||
Finished navigation to navigation-navigate-iframe.html#1
|
||||
History length after navigate is 2
|
||||
DONE
|
@ -0,0 +1,83 @@
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
function filename(path) {
|
||||
url = new URL(path)
|
||||
return url.pathname.split('/').pop() + url.hash
|
||||
}
|
||||
asyncTest(async done => {
|
||||
if (window.self === window.top) {
|
||||
test(() => {});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
parent.postMessage(`Initial history length is ${navigation.entries().length}`, "*");
|
||||
|
||||
navigation.oncurrententrychange = (e) => {
|
||||
parent.postMessage(`${e.type} for change to ${filename(navigation.currentEntry.url)} of type ${e.navigationType} from ${filename(e.from.url)}`, "*");
|
||||
}
|
||||
|
||||
navigation.onnavigate = (e) => {
|
||||
parent.postMessage(`NavigateEvent for ${e.navigationType} ${filename(e.destination.url)} (Same document? ${e.destination.sameDocument}) with info: ${e.info}`, "*")
|
||||
}
|
||||
|
||||
// Navigate to fragment
|
||||
let a = navigation.navigate("navigation-navigate-iframe.html#1", { info: 42, history: "push" });
|
||||
|
||||
await a.committed.then((f) => {
|
||||
parent.postMessage(`Committed to navigation to ${filename(f.url)}`, "*");
|
||||
},
|
||||
(e) => {
|
||||
parent.postMessage("ERROR:" + e, "*", "*");
|
||||
})
|
||||
|
||||
await a.finished.then((f) => {
|
||||
parent.postMessage(`Finished navigation to ${filename(f.url)}`, "*");
|
||||
},
|
||||
(e) => {
|
||||
parent.postMessage("ERROR:" + e, "*");
|
||||
})
|
||||
|
||||
parent.postMessage(`History length after navigate is ${navigation.entries().length}`, "*");
|
||||
|
||||
// FIXME: Enable these tests 😅
|
||||
// Navigate backwards
|
||||
// let b = navigation.back()
|
||||
// await b.committed.then((f) => {
|
||||
// parent.postMessage(`Committed to back navigation to ${filename(f.url)}`, "*");
|
||||
// },
|
||||
// (e) => {
|
||||
// parent.postMessage("ERROR:" + e, "*", "*");
|
||||
// })
|
||||
// await b.finished.then((f) => {
|
||||
// parent.postMessage(`Finished back navigation to ${filename(f.url)}`, "*");
|
||||
// },
|
||||
// (e) => {
|
||||
// parent.postMessage("ERROR:" + e, "*");
|
||||
// })
|
||||
|
||||
// parent.postMessage(`History length after back is ${navigation.entries().length}`, "*");
|
||||
|
||||
// Navigate forwards
|
||||
// let c = navigation.forward()
|
||||
// await c.committed.then((f) => {
|
||||
// parent.postMessage(`Committed to forward navigation to ${filename(f.url)}`, "*");
|
||||
// },
|
||||
// (e) => {
|
||||
// parent.postMessage("ERROR:" + e, "*", "*");
|
||||
// })
|
||||
// await c.finished.then((f) => {
|
||||
// parent.postMessage(`Finished forward navigation to ${filename(f.url)}`, "*");
|
||||
// },
|
||||
// (e) => {
|
||||
// parent.postMessage("ERROR:" + e, "*");
|
||||
// })
|
||||
|
||||
// parent.postMessage(`History length after forward is ${navigation.entries().length}`, "*");
|
||||
|
||||
} catch (e) {
|
||||
parent.postMessage("ERROR:" + e, "*");
|
||||
}
|
||||
parent.postMessage("DONE", "*");
|
||||
});
|
||||
</script>
|
24
Tests/LibWeb/Text/input/navigation/navigation-navigate.html
Normal file
24
Tests/LibWeb/Text/input/navigation/navigation-navigate.html
Normal file
@ -0,0 +1,24 @@
|
||||
<script src="../include.js"></script>
|
||||
<iframe id="testIframe" src="about:blank"></iframe>
|
||||
<script>
|
||||
asyncTest(async done => {
|
||||
const iframe = document.getElementById("testIframe");
|
||||
|
||||
function navigateIframe(src) {
|
||||
return new Promise(resolve => {
|
||||
iframe.addEventListener("load", () => {
|
||||
resolve();
|
||||
});
|
||||
iframe.src = src;
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener("message", event => {
|
||||
println(event.data);
|
||||
if (event.data === "DONE")
|
||||
done();
|
||||
});
|
||||
|
||||
await navigateIframe("./navigation-navigate-iframe.html");
|
||||
});
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user