Skip to content

Commit 53960f8

Browse files
domenicchromium-wpt-export-bot
authored andcommitted
Implement the basics of appHistory.transition
That is, it includes navigationType and from. Bug: 1183545 Change-Id: I033906c7fbde626840eff23f34437a0ddaf67a2c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3123206 Commit-Queue: Domenic Denicola <[email protected]> Reviewed-by: Nate Chapin <[email protected]> Cr-Commit-Position: refs/heads/main@{#916920}
1 parent c542eb4 commit 53960f8

16 files changed

+568
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
5+
<script>
6+
async_test(t => {
7+
// Wait for after the load event so that the navigation doesn't get converted
8+
// into a replace navigation.
9+
window.onload = () => t.step_timeout(() => {
10+
appHistory.navigate("#1").then(t.step_func(() => {
11+
assert_equals(appHistory.transition, null);
12+
const from = appHistory.current;
13+
const error = new Error("test");
14+
15+
appHistory.addEventListener("navigate", t.step_func(e => {
16+
e.transitionWhile(Promise.reject(error));
17+
assert_equals(appHistory.transition, null);
18+
}));
19+
20+
let navigateerrorFired = false;
21+
appHistory.addEventListener("navigateerror", t.step_func(() => {
22+
navigateerrorFired = true;
23+
assert_equals(appHistory.transition.navigationType, "traverse");
24+
assert_equals(appHistory.transition.from, from);
25+
26+
Promise.resolve().then(t.step_func_done(() => {
27+
assert_equals(appHistory.transition, null);
28+
}));
29+
}));
30+
31+
promise_rejects_exactly(t, error, appHistory.back()).then(t.step_func_done(() => {
32+
assert_equals(appHistory.transition, null);
33+
assert_true(navigateerrorFired);
34+
}));
35+
36+
assert_equals(appHistory.transition, null);
37+
}));
38+
}, 0);
39+
}, "transitionWhile()ed back() with a rejected promise");
40+
</script>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
5+
<script>
6+
async_test(t => {
7+
// Wait for after the load event so that the navigation doesn't get converted
8+
// into a replace navigation.
9+
window.onload = () => t.step_timeout(() => {
10+
appHistory.navigate("#1").then(t.step_func(() => {
11+
assert_equals(appHistory.transition, null);
12+
const from = appHistory.current;
13+
14+
appHistory.addEventListener("navigate", t.step_func(e => {
15+
e.transitionWhile(Promise.resolve());
16+
assert_equals(appHistory.transition, null);
17+
}));
18+
19+
let navigatesuccessFired = false;
20+
appHistory.addEventListener("navigatesuccess", t.step_func(() => {
21+
navigatesuccessFired = true;
22+
23+
assert_equals(appHistory.transition.navigationType, "traverse");
24+
assert_equals(appHistory.transition.from, from);
25+
}));
26+
27+
appHistory.back().then(t.step_func_done(() => {
28+
assert_equals(appHistory.transition, null);
29+
assert_true(navigatesuccessFired);
30+
}));
31+
assert_equals(appHistory.transition, null);
32+
}));
33+
}, 0);
34+
}, "transitionWhile()ed back()");
35+
</script>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!doctype html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
5+
<iframe id="i" src="/common/blank.html"></iframe>
6+
7+
<script>
8+
promise_test(async t => {
9+
// Wait for after the load event so that the navigation doesn't get converted
10+
// into a replace navigation.
11+
await new Promise(r => window.onload = () => t.step_timeout(r, 0));
12+
13+
i.contentWindow.appHistory.onnavigatesuccess = t.unreached_func("navigatesuccess must not fire");
14+
i.contentWindow.appHistory.onnavigateerror = t.unreached_func("navigateerror must not fire");
15+
16+
assert_equals(i.contentWindow.appHistory.transition, null);
17+
i.contentWindow.appHistory.reload();
18+
assert_equals(i.contentWindow.appHistory.transition, null);
19+
20+
await new Promise(r => i.onload = () => t.step_timeout(r, 0));
21+
}, "cross-document reload() must leave transition null");
22+
23+
promise_test(async t => {
24+
i.contentWindow.appHistory.onnavigatesuccess = t.unreached_func("navigatesuccess must not fire");
25+
i.contentWindow.appHistory.onnavigateerror = t.unreached_func("navigateerror must not fire");
26+
27+
assert_equals(i.contentWindow.appHistory.transition, null);
28+
i.contentWindow.appHistory.navigate("?1");
29+
assert_equals(i.contentWindow.appHistory.transition, null);
30+
31+
await new Promise(r => i.onload = () => t.step_timeout(r, 0));
32+
}, "cross-document navigate() must leave transition null");
33+
34+
promise_test(async t => {
35+
i.contentWindow.appHistory.onnavigatesuccess = t.unreached_func("navigatesuccess must not fire");
36+
i.contentWindow.appHistory.onnavigateerror = t.unreached_func("navigateerror must not fire");
37+
38+
assert_equals(i.contentWindow.appHistory.transition, null);
39+
i.contentWindow.appHistory.back();
40+
assert_equals(i.contentWindow.appHistory.transition, null);
41+
42+
await new Promise(r => i.onload = r);
43+
}, "cross-document back() must leave transition null");
44+
</script>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!doctype html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script>
5+
async_test(t => {
6+
// Wait for after the load event so that the navigation doesn't get converted
7+
// into a replace navigation.
8+
window.onload = () => t.step_timeout(() => {
9+
assert_equals(appHistory.transition, null);
10+
const from = appHistory.current;
11+
12+
appHistory.addEventListener("navigate", t.step_func(e => {
13+
e.transitionWhile(Promise.resolve());
14+
assert_equals(appHistory.transition, null);
15+
}));
16+
17+
appHistory.addEventListener("navigatesuccess", t.step_func_done(() => {
18+
assert_equals(appHistory.transition.navigationType, "push");
19+
assert_equals(appHistory.transition.from, from);
20+
}));
21+
22+
location.href = "#1";
23+
24+
assert_equals(appHistory.transition.navigationType, "push");
25+
assert_equals(appHistory.transition.from, from);
26+
}, 0);
27+
}, "intercepted fragment navigations set transition");
28+
</script>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!doctype html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script>
5+
async_test(t => {
6+
// Wait for after the load event so that the navigation doesn't get converted
7+
// into a replace navigation.
8+
window.onload = () => t.step_timeout(() => {
9+
appHistory.onnavigateerror = t.unreached_func("navigateerror must not fire");
10+
appHistory.onnavigatesuccess = t.step_func_done(() => {
11+
assert_equals(appHistory.transition, null);
12+
});
13+
14+
assert_equals(appHistory.transition, null);
15+
location.href = "#1";
16+
assert_equals(appHistory.transition, null);
17+
}, 0);
18+
}, "non-intercepted fragment navigations leave transition null");
19+
</script>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
5+
<script>
6+
async_test(t => {
7+
// Wait for after the load event so that the navigation doesn't get converted
8+
// into a replace navigation.
9+
window.onload = () => t.step_timeout(t.step_func_done(() => {
10+
assert_equals(appHistory.transition, null);
11+
const from = appHistory.current;
12+
13+
const events = [];
14+
15+
appHistory.addEventListener("navigate", t.step_func(e => {
16+
events.push("navigate");
17+
18+
e.preventDefault();
19+
assert_equals(appHistory.transition, null);
20+
}));
21+
22+
appHistory.addEventListener("navigateerror", t.step_func(() => {
23+
events.push("navigateerror");
24+
25+
assert_equals(appHistory.transition, null);
26+
}));
27+
28+
location.href = "?1";
29+
assert_equals(appHistory.transition, null);
30+
assert_array_equals(events, ["navigate", "navigateerror"]);
31+
}), 0);
32+
}, "canceled location.href navigation");
33+
</script>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
5+
<script>
6+
async_test(t => {
7+
// Wait for after the load event so that the navigation doesn't get converted
8+
// into a replace navigation.
9+
window.onload = () => t.step_timeout(() => {
10+
assert_equals(appHistory.transition, null);
11+
const from = appHistory.current;
12+
13+
appHistory.addEventListener("navigate", t.step_func(e => {
14+
e.transitionWhile(Promise.reject(new Error("test")));
15+
assert_equals(appHistory.transition, null);
16+
}));
17+
18+
appHistory.addEventListener("navigateerror", t.step_func(() => {
19+
assert_equals(appHistory.transition.navigationType, "push");
20+
assert_equals(appHistory.transition.from, from);
21+
22+
Promise.resolve().then(t.step_func_done(() => {
23+
assert_equals(appHistory.transition, null);
24+
}));
25+
}));
26+
27+
location.href = "?1";
28+
29+
assert_equals(appHistory.transition.navigationType, "push");
30+
assert_equals(appHistory.transition.from, from);
31+
}, 0);
32+
}, "transitionWhile()ed location.href navigation with a rejected promise");
33+
</script>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
5+
<script>
6+
async_test(t => {
7+
// Wait for after the load event so that the navigation doesn't get converted
8+
// into a replace navigation.
9+
window.onload = () => t.step_timeout(() => {
10+
assert_equals(appHistory.transition, null);
11+
const from = appHistory.current;
12+
13+
appHistory.addEventListener("navigate", t.step_func(e => {
14+
e.transitionWhile(Promise.resolve());
15+
assert_equals(appHistory.transition, null);
16+
}));
17+
18+
appHistory.addEventListener("navigatesuccess", t.step_func(() => {
19+
assert_equals(appHistory.transition.navigationType, "push");
20+
assert_equals(appHistory.transition.from, from);
21+
22+
Promise.resolve().then(t.step_func_done(() => {
23+
assert_equals(appHistory.transition, null);
24+
}));
25+
}));
26+
27+
location.href = "?1";
28+
assert_equals(appHistory.transition.navigationType, "push");
29+
assert_equals(appHistory.transition.from, from);
30+
}, 0);
31+
}, "transitionWhile()ed location.href navigation");
32+
</script>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
5+
<script>
6+
promise_test(async t => {
7+
assert_equals(appHistory.transition, null);
8+
9+
const events = [];
10+
11+
appHistory.addEventListener("navigate", t.step_func(e => {
12+
events.push("navigate");
13+
14+
e.preventDefault();
15+
assert_equals(appHistory.transition, null);
16+
}));
17+
18+
appHistory.addEventListener("navigateerror", t.step_func(() => {
19+
events.push("navigateerror");
20+
21+
assert_equals(appHistory.transition, null);
22+
}));
23+
24+
await promise_rejects_dom(t, "AbortError", appHistory.navigate("?1"));
25+
assert_equals(appHistory.transition, null);
26+
assert_array_equals(events, ["navigate", "navigateerror"]);
27+
}, "canceled navigate()");
28+
</script>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
5+
<script>
6+
async_test(t => {
7+
// Wait for after the load event so that the navigation doesn't get converted
8+
// into a replace navigation.
9+
window.onload = () => t.step_timeout(() => {
10+
assert_equals(appHistory.transition, null);
11+
const from = appHistory.current;
12+
let from2;
13+
14+
appHistory.addEventListener("navigate", t.step_func(e => {
15+
e.transitionWhile(new Promise(r => t.step_timeout(r, 1)));
16+
assert_equals(appHistory.transition, null);
17+
}));
18+
19+
let navigateerrorFired = false;
20+
appHistory.addEventListener("navigateerror", t.step_func(() => {
21+
// (3) handle the interruption of the navigation to ?1.
22+
navigateerrorFired = true;
23+
24+
assert_equals(appHistory.transition.navigationType, "push");
25+
assert_equals(appHistory.transition.from, from);
26+
}));
27+
28+
let navigatesuccessFired = false;
29+
appHistory.addEventListener("navigatesuccess", t.step_func(() => {
30+
// (5) The navigation to ?2 succeeds.
31+
navigatesuccessFired = true;
32+
assert_true(navigateerrorFired, "navigateerror must fire before navigatesuccess");
33+
34+
assert_equals(appHistory.transition.navigationType, "replace");
35+
assert_equals(appHistory.transition.from, from2);
36+
}));
37+
38+
// (1) Navigate to ?1. This will take 1 ms to settle.
39+
let secondNavigateFulfilled = false;
40+
promise_rejects_dom(t, "AbortError", appHistory.navigate("?1")).then(t.step_func(() => {
41+
// (4) After navigateerror for the navigation to ?1 comes the promise rejection.
42+
firstNavigateRejected = true;
43+
44+
assert_equals(appHistory.transition.navigationType, "replace");
45+
assert_equals(appHistory.transition.from, from2);
46+
assert_true(navigateerrorFired, "navigateerror must fire before the first navigate() rejects");
47+
}));
48+
49+
assert_equals(appHistory.transition.navigationType, "push");
50+
assert_equals(appHistory.transition.from, from);
51+
52+
from2 = appHistory.current;
53+
assert_not_equals(from, from2);
54+
55+
// (2) Navigate to ?2. This will interrupt the navigation to ?1 and take us to (3).
56+
appHistory.navigate("?2", { replace: true }).then(t.step_func_done(() => {
57+
// (6) After navigatesuccess for the navigation to ?2 comes the promise fulfillment.
58+
assert_true(navigatesuccessFired, "navigatesuccess must be fired");
59+
60+
assert_equals(appHistory.transition, null);
61+
}));
62+
63+
assert_equals(appHistory.transition.navigationType, "replace");
64+
assert_equals(appHistory.transition.from, from2);
65+
}, 0);
66+
}, "transitionWhile()ed one navigate() interrupting the other");
67+
</script>

0 commit comments

Comments
 (0)