mirror of
https://github.com/lexmount/moli.git
synced 2026-11-22 16:02:34 +00:00
fix(history): preserve URL for empty state updates
This commit is contained in:
@@ -208,6 +208,47 @@ fn history_activity_is_checked_after_argument_conversion() {
|
||||
assert_eq!(result, ["SecurityError:1"; 6].join("|"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn history_mutation_empty_url_preserves_current_document_url() {
|
||||
let mut vm = new_storage_test_vm("https://example.com/path/page.html?query=value#initial");
|
||||
|
||||
let result = vm
|
||||
.eval(
|
||||
r#"
|
||||
(() => {
|
||||
const root = document.documentElement ||
|
||||
document.appendChild(document.createElement("html"));
|
||||
const head = document.head ||
|
||||
root.insertBefore(document.createElement("head"), root.firstChild);
|
||||
const base = document.createElement("base");
|
||||
base.href = "https://example.com/different/base/";
|
||||
head.appendChild(base);
|
||||
|
||||
const before = location.href;
|
||||
history.pushState({ kind: "push" }, "", "");
|
||||
const afterPush = location.href;
|
||||
history.replaceState({ kind: "replace" }, "", "");
|
||||
|
||||
return JSON.stringify({
|
||||
before,
|
||||
afterPush,
|
||||
afterReplace: location.href,
|
||||
baseURI: document.baseURI,
|
||||
length: history.length,
|
||||
state: history.state.kind,
|
||||
entryUrl: navigation.currentEntry.url
|
||||
});
|
||||
})()
|
||||
"#,
|
||||
)
|
||||
.expect("empty history URL should preserve the current document URL");
|
||||
|
||||
assert_eq!(
|
||||
result,
|
||||
r#"{"before":"https://example.com/path/page.html?query=value#initial","afterPush":"https://example.com/path/page.html?query=value#initial","afterReplace":"https://example.com/path/page.html?query=value#initial","baseURI":"https://example.com/different/base/","length":2,"state":"replace","entryUrl":"https://example.com/path/page.html?query=value#initial"}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn history_state_preserves_structured_clone_values_not_representable_as_json() {
|
||||
let mut vm = new_storage_test_vm("https://example.com/base");
|
||||
|
||||
Reference in New Issue
Block a user