Update web-platform-tests to revision b'1d9b01e2fad6af3a057d571b1e088e15fa9bc8e6'

This commit is contained in:
WPT Sync Bot 2023-04-07 01:27:34 +00:00
parent cfef75c99b
commit bb34f95b33
1683 changed files with 37170 additions and 4252 deletions

View file

@ -0,0 +1,25 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../navigation-methods/return-value/resources/helpers.js"></script>
<body>
<script>
promise_test(async t => {
navigation.addEventListener("navigate", e => e.intercept({ commit: "after-transition" }), { once: "true" });
let navigateerror_called = false;
navigation.onnavigateerror = t.step_func(() => {
navigateerror_called = true;
assert_equals(location.hash, "");
});
let promises_should_not_commit = navigation.navigate("#ShouldNotCommit");
let promises_fulfilled = navigation.navigate("#1");
await assertBothRejectDOM(t, promises_should_not_commit, "AbortError");
await assertBothFulfill(t, promises_fulfilled, navigation.currentEntry);
assert_equals(location.hash, "#1");
assert_true(navigateerror_called);
}, "Cancel a { commit: 'after-transition' } navigation before commit() by starting a new navigation");
</script>
</body>

View file

@ -0,0 +1,23 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../navigation-methods/return-value/resources/helpers.js"></script>
<script src="resources/after-transition-commit-helpers.js"></script>
<body>
<script>
let tests = [
{ mode: "rejectBeforeCommit", description: "{ commit: 'after-transition' } for a push navigation, reject before commit" },
{ mode: "rejectAfterCommit", description: "{ commit: 'after-transition' } for a push navigation, reject after commit" },
{ mode: "successExplicitCommit", description: "{ commit: 'after-transition' } for a push navigation, explicit commit()" },
{ mode: "successNoExplicitCommit", description: "{ commit: 'after-transition' } for a push navigation, commit when handler resolves" }
];
let onload_promise = new Promise(resolve => window.onload = resolve);
for (let test of tests) {
promise_test(async t => {
await onload_promise;
await testAfterTransitionCommit(t, "push", test.mode);
}, test.description);
}
</script>
</body>

View file

@ -0,0 +1,19 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../navigation-methods/return-value/resources/helpers.js"></script>
<script src="resources/after-transition-commit-helpers.js"></script>
<body>
<script>
let tests = [
{ mode: "rejectBeforeCommit", description: "{ commit: 'after-transition' } for a reload navigation, reject before commit" },
{ mode: "rejectAfterCommit", description: "{ commit: 'after-transition' } for a reload navigation, reject after commit" },
{ mode: "successExplicitCommit", description: "{ commit: 'after-transition' } for a reload navigation, explicit commit()" },
{ mode: "successNoExplicitCommit", description: "{ commit: 'after-transition' } for a reload navigation, commit when handler resolves" }
];
for (let test of tests) {
promise_test(t => testAfterTransitionCommit(t, "reload", test.mode), test.description);
}
</script>
</body>

View file

@ -0,0 +1,19 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../navigation-methods/return-value/resources/helpers.js"></script>
<script src="resources/after-transition-commit-helpers.js"></script>
<body>
<script>
let tests = [
{ mode: "rejectBeforeCommit", description: "{ commit: 'after-transition' } for a replace navigation, reject before commit" },
{ mode: "rejectAfterCommit", description: "{ commit: 'after-transition' } for a replace navigation, reject after commit" },
{ mode: "successExplicitCommit", description: "{ commit: 'after-transition' } for a replace navigation, explicit commit()" },
{ mode: "successNoExplicitCommit", description: "{ commit: 'after-transition' } for a replace navigation, commit when handler resolves" }
];
for (let test of tests) {
promise_test(t => testAfterTransitionCommit(t, "replace", test.mode), test.description);
}
</script>
</body>

View file

@ -0,0 +1,36 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../navigation-methods/return-value/resources/helpers.js"></script>
<body>
<script>
promise_test(async t => {
// Wait for after the load event so that the navigation doesn't get converted
// into a replace navigation.
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
await navigation.navigate("#1").finished;
let navigateerror_called = false;
navigation.onnavigateerror = t.step_func(() => {
navigateerror_called = true;
assert_equals(location.hash, "#1");
});
// Go back and wait for the navigate event to fire. This traversal will be deferred.
let promises_should_not_commit = assertBothRejectDOM(t, navigation.back(), "AbortError");
navigation.addEventListener("navigate", e => e.intercept({ commit: "after-transition", handler: () => new Promise(r => t.step_timeout(r, 1000)) }), { once: "true" });
await new Promise(resolve => navigation.addEventListener("navigate", resolve, { once: "true" }));
// While the traversal is deferred, start a new navigation and commit immediately.
navigation.addEventListener("navigate", e => e.intercept(), { once: "true" });
let promises_fulfilled = navigation.navigate("#2");
await promises_should_not_commit;
await assertBothFulfill(t, promises_fulfilled, navigation.currentEntry);
assert_equals(location.hash, "#2");
assert_true(navigateerror_called);
}, "Cancel a { commit: 'after-transition' } traversal before commit() by starting a new navigation");
</script>
</body>

View file

@ -0,0 +1,29 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../navigation-methods/return-value/resources/helpers.js"></script>
<script src="resources/after-transition-commit-helpers.js"></script>
<body>
<script>
let tests = [
{ mode: "rejectBeforeCommit", destinationIndex: 0, description: "{ commit: 'after-transition' } for a traverse navigation, reject before commit" },
{ mode: "rejectAfterCommit", destinationIndex: 1, description: "{ commit: 'after-transition' } for a traverse navigation, reject after commit" },
{ mode: "successExplicitCommit", destinationIndex: 2, description: "{ commit: 'after-transition' } for a traverse navigation, explicit commit()" },
{ mode: "successNoExplicitCommit", destinationIndex: 3, description: "{ commit: 'after-transition' } for a traverse navigation, commit when handler resolves" }
];
// Push a bunch of history entries so each test case can target a unique entry.
history.pushState("", "", "#1");
history.pushState("", "", "#2");
history.pushState("", "", "#3");
history.pushState("", "", "#4");
let onload_promise = new Promise(resolve => window.onload = resolve);
for (let test of tests) {
promise_test(async t => {
await onload_promise;
await testAfterTransitionCommit(t, "traverse", test.mode, test.destinationIndex);
}, test.description);
}
</script>
</body>

View file

@ -0,0 +1,23 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe id="i" src="/common/blank.html"></iframe>
<body>
<script>
promise_test(async t => {
// Wait for after the load event so that the navigation doesn't get converted
// into a replace navigation.
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
await i.contentWindow.navigation.navigate("#1").finished;
i.contentWindow.navigation.onnavigate = t.step_func(e => {
assert_false(e.cancelable);
// intercept() should throw with commit: "after-transition" because e.cancelable is false.
let iframe_constructor = i.contentWindow.DOMException;
assert_throws_dom("InvalidStateError", iframe_constructor, () => e.intercept({ commit: "after-transition" }));
});
await i.contentWindow.navigation.back().finished;
}, "{ commit: 'after-transition' } for an uncancelable traverse navigation");
</script>
</body>

View file

@ -0,0 +1,33 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../navigation-methods/return-value/resources/helpers.js"></script>
<body>
<script>
promise_test(async t => {
// Wait for after the load event because window.stop() hangs the test harness
// if called before the load event.
await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
navigation.onnavigate = e => {
e.intercept({ commit: "after-transition" });
};
navigation.onnavigatesuccess = t.unreached_func("navigatesuccess must not fire");
let navigateerror_called = false;
navigation.onnavigateerror = t.step_func(() => {
navigateerror_called = true;
assert_equals(location.hash, "");
});
let promises = navigation.navigate("#ShouldNotCommit");
assert_equals(location.hash, "");
window.stop();
await assertBothRejectDOM(t, promises, "AbortError");
assert_equals(location.hash, "");
assert_true(navigateerror_called);
}, " { commit: 'after-transition' } with window.stop() before commit");
</script>
</body>

View file

@ -0,0 +1,95 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
promise_test(async t => {
navigation.onnavigate = t.step_func(e => {
assert_throws_dom("InvalidStateError", () => e.commit());
});
await navigation.navigate("#").finished;
}, "commit() before intercept()");
promise_test(async t => {
navigation.onnavigate = t.step_func(e => {
e.intercept({ handler: t.step_func(() => {
assert_throws_dom("InvalidStateError", () => e.commit());
}) });
});
await navigation.navigate("#").finished;
}, "commit() without commit behavior specified");
promise_test(async t => {
navigation.onnavigate = t.step_func(e => {
e.intercept({
handler: t.step_func(() => {
assert_throws_dom("InvalidStateError", () => e.commit());
}),
commit: "immediate"
});
});
await navigation.navigate("#").finished;
}, "commit() with { commit: immediate }");
promise_test(async t => {
navigation.onnavigate = t.step_func(e => {
e.intercept({ commit: "after-transition" });
assert_throws_dom("InvalidStateError", () => e.commit());
});
await navigation.navigate("#").finished;
}, "commit() during event dispatch");
promise_test(async t => {
let navigate_event;
navigation.onnavigate = t.step_func(e => {
e.intercept({ commit: "after-transition" });
navigate_event = e;
});
await navigation.navigate("#").finished;
assert_throws_dom("InvalidStateError", () => navigate_event.commit());
}, "commit() after finish");
promise_test(async t => {
navigation.onnavigate = t.step_func(e => {
e.intercept({
handler: t.step_func(() => {
e.commit();
assert_throws_dom("InvalidStateError", () => e.commit());
}),
commit: "after-transition"
});
});
await navigation.navigate("#").finished;
}, "commit() twice");
promise_test(async t => {
// We need to grab an NavigationDestination to construct the event.
navigation.onnavigate = t.step_func(e => {
const event = new NavigateEvent("navigate", {
destination: e.destination,
signal: (new AbortController()).signal
});
assert_throws_dom("SecurityError", () => event.commit());
});
await navigation.navigate("#").finished;
}, "commit() on synthetic NavigateEvent");
promise_test(async t => {
let i = document.createElement("iframe");
i.src = "about:blank";
document.body.appendChild(i);
i.contentWindow.navigation.onnavigate = t.step_func(e => {
e.intercept({
handler: t.step_func(() => {
let iframe_constructor = i.contentWindow.DOMException;
i.remove();
assert_throws_dom("InvalidStateError", iframe_constructor, () => e.commit());
}),
commit: "after-transition"
});
});
i.contentWindow.navigation.navigate("#");
}, "commit() in detached iframe");
</script>
</body>

View file

@ -0,0 +1,83 @@
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<div style="height: 1000px; width: 1000px;"></div>
<div id="frag"></div>
<script>
let i = 0;
async function urlDidChangeImmediately(listener, expected) {
navigation.addEventListener("navigate", listener, { once: true });
let expected_hash = "#" + ++i;
assert_not_equals(location.hash, expected_hash);
let finished = navigation.navigate(expected_hash).finished;
assert_equals(location.hash === expected_hash, expected);
await finished;
assert_equals(location.hash, expected_hash);
}
async function testUrlDidChangeImmediately(listener) {
await urlDidChangeImmediately(listener, true);
}
async function testUrlDidNotChangeImmediately(listener) {
await urlDidChangeImmediately(listener, false);
}
promise_test(async t => {
await testUrlDidNotChangeImmediately(e => {
e.intercept({ commit: "after-transition" });
e.intercept({ commit: "after-transition" });
});
}, "after-transition + after-transition");
promise_test(async t => {
await testUrlDidNotChangeImmediately(e => {
e.intercept({ commit: "after-transition" });
e.intercept();
});
}, "after-transition + (not provided)");
promise_test(async t => {
await testUrlDidChangeImmediately(e => {
e.intercept({ commit: "after-transition" });
e.intercept({ commit: "immediate" });
});
}, "after-transition + immediate");
promise_test(async t => {
await testUrlDidNotChangeImmediately(e => {
e.intercept({ commit: "immediate" });
e.intercept({ commit: "after-transition" });
});
}, "immediate + after-transition");
promise_test(async t => {
await testUrlDidChangeImmediately(e => {
e.intercept({ commit: "immediate" });
e.intercept();
});
}, "immediate + (not provided)");
promise_test(async t => {
await testUrlDidChangeImmediately(e => {
e.intercept({ commit: "immediate" });
e.intercept({ commit: "immediate" });
});
}, "immediate + immediate");
promise_test(async t => {
await testUrlDidNotChangeImmediately(e => {
e.intercept();
e.intercept({ commit: "after-transition" });
});
}, "(not provided) + after-transition");
promise_test(async t => {
await testUrlDidChangeImmediately(e => {
e.intercept();
e.intercept({ commit: "immediate" });
});
}, "(not provided) + immediate");
</script>
</body>

View file

@ -0,0 +1,90 @@
window.testAfterTransitionCommit = async (t, navigationType, mode, destinationIndex = 0) => {
let startHash = location.hash;
let destinationHash;
const err = new Error("boo!");
let popstate_fired = false;
window.addEventListener("popstate", () => popstate_fired = true, { once : true });
let navigatesuccess_fired = false;
navigation.addEventListener("navigatesuccess", () => navigatesuccess_fired = true, { once : true });
let navigateerror_fired = false;
navigation.addEventListener("navigateerror", () => navigateerror_fired = true, { once : true });
// mode-specific logic for the navigate event handler
let navigate_helpers = {
rejectBeforeCommit : async (e) => {
return Promise.reject(err);
},
rejectAfterCommit : async (e) => {
e.commit();
assert_equals(location.hash, destinationHash, "hash after commit");
assert_true(popstate_fired, "popstate fired after commit");
await new Promise(resolve => t.step_timeout(resolve, 0));
return Promise.reject(err);
},
successExplicitCommit : async (e) => {
e.commit();
assert_equals(location.hash, destinationHash, "hash after commit");
assert_true(popstate_fired, "popstate fired after commit");
return new Promise(resolve => t.step_timeout(resolve, 0));
},
successNoExplicitCommit : async (e) => {
assert_equals(location.hash, startHash, "start has after first async step");
assert_false(popstate_fired, "popstate fired after first async step");
await new Promise(resolve => t.step_timeout(resolve, 0));
assert_equals(location.hash, startHash, "start has after second async step");
assert_false(popstate_fired, "popstate fired after second async step");
return new Promise(resolve => t.step_timeout(resolve, 0));
}
}
navigation.addEventListener("navigate", e => {
e.intercept({ commit: "after-transition",
handler: t.step_func(async () => {
assert_equals(e.navigationType, navigationType);
assert_equals(location.hash, startHash, "start hash");
assert_false(popstate_fired, "popstate fired at handler start");
await new Promise(resolve => t.step_timeout(resolve, 0));
assert_equals(location.hash, startHash, "hash after first async step");
assert_false(popstate_fired, "popstate fired after first async step");
return navigate_helpers[mode](e);
})});
}, { once: true });
let promises;
if (navigationType === "push" || navigationType === "replace") {
destinationHash = (startHash === "" ? "#" : startHash) + "a";
promises = navigation.navigate(destinationHash, { history: navigationType });
} else if (navigationType === "reload") {
destinationHash = startHash;
promises = navigation.reload();
} else if (navigationType === "traverse") {
let destinationEntry = navigation.entries()[destinationIndex];
destinationHash = new URL(destinationEntry.url).hash;
promises = navigation.traverseTo(destinationEntry.key);
}
if (mode === "rejectBeforeCommit") {
await assertBothRejectExactly(t, promises, err);
assert_equals(location.hash, startHash, "hash after promise resolution");
assert_false(popstate_fired, "popstate fired after promise resolution");
assert_false(navigatesuccess_fired, "navigatesuccess fired");
assert_true(navigateerror_fired, "navigateerror fired");
} else if (mode === "rejectAfterCommit") {
await promises.committed;
await assertCommittedFulfillsFinishedRejectsExactly(t, promises, navigation.currentEntry, err);
assert_equals(location.hash, destinationHash, "hash after promise resolution");
assert_true(popstate_fired, "popstate fired after promise resolution");
assert_false(navigatesuccess_fired, "navigatesuccess fired");
assert_true(navigateerror_fired, "navigateerror fired");
} else {
await promises.committed;
await assertBothFulfill(t, promises, navigation.currentEntry);
assert_equals(location.hash, destinationHash, "hash after promise resolution");
assert_true(popstate_fired, "popstate fired after promise resolution");
assert_true(navigatesuccess_fired, "navigatesuccess fired");
assert_false(navigateerror_fired, "navigateerror fired");
}
}