Skip to content

Commit 9375ad7

Browse files
domenicchromium-wpt-export-bot
authored andcommitted
Navigation API: test that 204/205/downloads never settle
See WICG/navigation-api#137. Bug: 1183545 Change-Id: I6f8f1771816ddf454d651f7147d3179fba88979b
1 parent ec9d207 commit 9375ad7

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<!doctype html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script src="resources/helpers.js"></script>
5+
<script src="/common/utils.js"></script>
6+
7+
<body>
8+
<script>
9+
promise_test(async t => {
10+
const id = token();
11+
12+
const i = document.createElement("iframe");
13+
i.src = `resources/204-205-download-on-second-visit.py?id=${id}`;
14+
document.body.append(i);
15+
await new Promise(r => i.onload = r);
16+
17+
// Configure it to return a 204 on the next visit
18+
await fetch(i.src + "&action=204", { method: "POST" });
19+
20+
// Now navigate elsewhere
21+
i.contentWindow.location.href = "/common/blank.html";
22+
await new Promise(r => i.onload = r);
23+
24+
// Now try going back. It should do nothing (and not tell us about the result).
25+
26+
const indexBefore = i.contentWindow.navigation.currentEntry.index;
27+
28+
const result = i.contentWindow.navigation.back();
29+
30+
assertNeverSettles(t, result, i.contentWindow);
31+
i.contentWindow.navigation.onnavigate = t.unreached_func("onnavigate should not be called");
32+
i.contentWindow.navigation.onnavigatesuccess = t.unreached_func("onnavigatesuccess should not be called");
33+
i.contentWindow.navigation.onnavigateerror = t.unreached_func("onnavigateerror should not be called");
34+
35+
await new Promise(resolve => t.step_timeout(resolve, 30));
36+
assert_equals(i.contentWindow.navigation.currentEntry.index, indexBefore);
37+
}, "back() promises to 204s never settle");
38+
39+
promise_test(async t => {
40+
const id = token();
41+
42+
const i = document.createElement("iframe");
43+
i.src = `resources/204-205-download-on-second-visit.py?id=${id}`;
44+
document.body.append(i);
45+
await new Promise(r => i.onload = r);
46+
47+
// Configure it to return a 205 on the next visit
48+
await fetch(i.src + "&action=205", { method: "POST" });
49+
50+
// Now navigate elsewhere
51+
i.contentWindow.location.href = "/common/blank.html";
52+
await new Promise(r => i.onload = r);
53+
54+
// Now try going back. It should do nothing (and not tell us about the result).
55+
56+
const indexBefore = i.contentWindow.navigation.currentEntry.index;
57+
58+
const result = i.contentWindow.navigation.back();
59+
60+
assertNeverSettles(t, result, i.contentWindow);
61+
i.contentWindow.navigation.onnavigate = t.unreached_func("onnavigate should not be called");
62+
i.contentWindow.navigation.onnavigatesuccess = t.unreached_func("onnavigatesuccess should not be called");
63+
i.contentWindow.navigation.onnavigateerror = t.unreached_func("onnavigateerror should not be called");
64+
65+
await new Promise(resolve => t.step_timeout(resolve, 30));
66+
assert_equals(i.contentWindow.navigation.currentEntry.index, indexBefore);
67+
}, "back() promises to 205s never settle");
68+
69+
promise_test(async t => {
70+
const id = token();
71+
72+
const i = document.createElement("iframe");
73+
i.src = `resources/204-205-download-on-second-visit.py?id=${id}`;
74+
document.body.append(i);
75+
await new Promise(r => i.onload = r);
76+
77+
// Configure it to return a download on the next visit
78+
await fetch(i.src + "&action=download", { method: "POST" });
79+
80+
// Now navigate elsewhere
81+
i.contentWindow.location.href = "/common/blank.html";
82+
await new Promise(r => i.onload = r);
83+
84+
// Now try going back. It should do nothing (and not tell us about the result).
85+
86+
const indexBefore = i.contentWindow.navigation.currentEntry.index;
87+
88+
const result = i.contentWindow.navigation.back();
89+
90+
assertNeverSettles(t, result, i.contentWindow);
91+
i.contentWindow.navigation.onnavigate = t.unreached_func("onnavigate should not be called");
92+
i.contentWindow.navigation.onnavigatesuccess = t.unreached_func("onnavigatesuccess should not be called");
93+
i.contentWindow.navigation.onnavigateerror = t.unreached_func("onnavigateerror should not be called");
94+
95+
await new Promise(resolve => t.step_timeout(resolve, 30));
96+
assert_equals(i.contentWindow.navigation.currentEntry.index, indexBefore);
97+
}, "back() promises to Content-Disposition: attachment responses never settle");
98+
</script>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!doctype html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script src="resources/helpers.js"></script>
5+
6+
<iframe id="i" src="/common/blank.html"></iframe>
7+
<script>
8+
promise_test(async t => {
9+
const result = i.contentWindow.navigation.navigate("/common/blank.html?pipe=status(204)");
10+
11+
assertNeverSettles(t, result, i.contentWindow);
12+
i.contentWindow.navigation.onnavigate = t.unreached_func("onnavigate should not be called");
13+
i.contentWindow.navigation.onnavigatesuccess = t.unreached_func("onnavigatesuccess should not be called");
14+
i.contentWindow.navigation.onnavigateerror = t.unreached_func("onnavigateerror should not be called");
15+
16+
await new Promise(resolve => t.step_timeout(resolve, 10));
17+
assert_equals(i.contentWindow.location.search, "");
18+
}, "navigate() promises to 204s never settle");
19+
20+
promise_test(async t => {
21+
const result = i.contentWindow.navigation.navigate("/common/blank.html?pipe=status(205)");
22+
23+
assertNeverSettles(t, result, i.contentWindow);
24+
i.contentWindow.navigation.onnavigate = t.unreached_func("onnavigate should not be called");
25+
i.contentWindow.navigation.onnavigatesuccess = t.unreached_func("onnavigatesuccess should not be called");
26+
i.contentWindow.navigation.onnavigateerror = t.unreached_func("onnavigateerror should not be called");
27+
28+
await new Promise(resolve => t.step_timeout(resolve, 10));
29+
assert_equals(i.contentWindow.location.search, "");
30+
}, "navigate() promises to 205s never settle");
31+
32+
promise_test(async t => {
33+
const result = i.contentWindow.navigation.navigate("/common/blank.html?pipe=header(Content-Disposition,attachment)");
34+
35+
assertNeverSettles(t, result, i.contentWindow);
36+
i.contentWindow.navigation.onnavigate = t.unreached_func("onnavigate should not be called");
37+
i.contentWindow.navigation.onnavigatesuccess = t.unreached_func("onnavigatesuccess should not be called");
38+
i.contentWindow.navigation.onnavigateerror = t.unreached_func("onnavigateerror should not be called");
39+
40+
await new Promise(resolve => t.step_timeout(resolve, 10));
41+
assert_equals(i.contentWindow.location.search, "");
42+
}, "navigate() promises to Content-Disposition: attachment responses never settle");
43+
</script>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def main(request, response):
2+
key = request.GET[b"id"]
3+
4+
# If hit with a POST with ?action=X, store X in the stash
5+
if request.method == "POST":
6+
action = request.GET[b"action"]
7+
request.server.stash.put(key, action)
8+
9+
return (204, [], "")
10+
11+
# If hit with a GET, either return a normal initial page, or the abnormal requested response
12+
elif request.method == "GET":
13+
action = request.server.stash.take(key)
14+
15+
if action is None:
16+
return (200, [("Content-Type", "text/html"), ("Cache-Control", "no-store")], "initial page")
17+
if action == b"204":
18+
return (204, [], "")
19+
if action == b"205":
20+
return (205, [], "")
21+
if action == b"download":
22+
return (200, [("Content-Type", "text/plain"), ("Content-Disposition", "attachment")], "some text to download")
23+
24+
return (400, [], "")

0 commit comments

Comments
 (0)