-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App history: fix cross origin-domain cross-document navigate events
Per the spec, do not fire navigate events for cross-document navigations where the initiating window is cross origin-domain from the target window. This was working with origin isolation enabled (the default for WPTs), but was not working with only site isolation (the default for real users). Also introduce a more comprehensive test matrix for these cross-window navigations and what navigate events they fire. Co-authored-by: Nate Chapin <japhet@chromium.org> Fixed: 1266580 Change-Id: Ib5e96287a5306e17e41b407db47774b6beef8119 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3256148 Reviewed-by: Mason Freed <masonf@chromium.org> Reviewed-by: Nate Chapin <japhet@chromium.org> Commit-Queue: Domenic Denicola <domenic@chromium.org> Cr-Commit-Position: refs/heads/main@{#939463}
- Loading branch information
Showing
28 changed files
with
796 additions
and
41 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...ory/navigate-event/cross-window/click-crossdocument-crossorigin-sameorigindomain.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
|
||
<script> | ||
document.domain = "{{host}}"; | ||
async_test(t => { | ||
const url = new URL("resources/document-domain-setter.sub.html", location.href); | ||
url.hostname = "{{domains[www1]}}"; | ||
const iframe = document.createElement("iframe"); | ||
iframe.name = "windowname"; | ||
iframe.src = url; | ||
document.body.append(iframe); | ||
|
||
url.search = "?foo"; | ||
const link = document.createElement("a"); | ||
link.href = url; | ||
link.target = iframe.name; | ||
document.body.append(link); | ||
|
||
appHistory.onnavigate = t.unreached_func("onnavigate must not fire in the source window"); | ||
window.onload = t.step_func(() => { | ||
iframe.contentWindow.appHistory.onnavigate = t.step_func_done(e => { | ||
assert_equals(e.navigationType, "push", "navigationType"); | ||
assert_true(e.cancelable, "cancelable"); | ||
assert_true(e.canTransition, "canTransition"); | ||
assert_false(e.userInitiated, "userInitiated"); | ||
assert_false(e.hashChange, "hashChange"); | ||
assert_equals(e.formData, null, "formData"); | ||
assert_equals(e.destination.url, link.href, "destination.url"); | ||
assert_false(e.destination.sameDocument, "destination.sameDocument"); | ||
assert_equals(e.destination.key, null, "destination.key"); | ||
assert_equals(e.destination.id, null, "destination.id"); | ||
assert_equals(e.destination.index, -1, "destination.index"); | ||
}); | ||
|
||
link.click(); | ||
}); | ||
}, "clicking on an <a> element that navigates cross-document targeting a same-origin-domain (but cross-origin) window"); | ||
</script> |
30 changes: 30 additions & 0 deletions
30
app-history/navigate-event/cross-window/click-crossdocument-crossorigin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/get-host-info.sub.js"></script> | ||
<body> | ||
|
||
<script> | ||
async_test(t => { | ||
const url = new URL("resources/cross-origin-iframe-helper.html", location.href); | ||
url.hostname = get_host_info().REMOTE_HOST; | ||
const iframe = document.createElement("iframe"); | ||
iframe.src = url; | ||
iframe.name = "windowname"; | ||
document.body.append(iframe); | ||
|
||
url.search = "?postMessage-top-when-done"; | ||
const link = document.createElement("a"); | ||
link.href = url; | ||
link.target = iframe.name; | ||
document.body.append(link); | ||
|
||
window.onmessage = t.step_func_done(e => { | ||
// If we hit onnavigate in the target window, we'll get a different message, and fail. | ||
assert_equals(e.data, "DONE"); | ||
}); | ||
|
||
appHistory.onnavigate = t.unreached_func("onnavigate must not fire in the source window"); | ||
window.onload = t.step_func(() => link.click()); | ||
}, "clicking on an <a> element that navigates cross-document targeting a cross-origin window"); | ||
</script> |
29 changes: 29 additions & 0 deletions
29
app-history/navigate-event/cross-window/click-crossdocument-sameorigin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<a id="link" href="/common/blank.html?foo" target="windowname">Click me</a> | ||
<iframe id="i" name="windowname" src="/common/blank.html"></iframe> | ||
|
||
<script> | ||
async_test(t => { | ||
appHistory.onnavigate = t.unreached_func("onnavigate must not fire in the source window"); | ||
window.onload = t.step_func(() => { | ||
i.contentWindow.appHistory.onnavigate = t.step_func_done(e => { | ||
assert_equals(e.navigationType, "push", "navigationType"); | ||
assert_true(e.cancelable, "cancelable"); | ||
assert_true(e.canTransition, "canTransition"); | ||
assert_false(e.userInitiated, "userInitiated"); | ||
assert_false(e.hashChange, "hashChange"); | ||
assert_equals(e.formData, null, "formData"); | ||
assert_equals(e.destination.url, link.href, "destination.url"); | ||
assert_false(e.destination.sameDocument, "destination.sameDocument"); | ||
assert_equals(e.destination.key, null, "destination.key"); | ||
assert_equals(e.destination.id, null, "destination.id"); | ||
assert_equals(e.destination.index, -1, "destination.index"); | ||
}); | ||
|
||
link.click(); | ||
}); | ||
}, "clicking on an <a> element that navigates cross-document targeting a same-origin window"); | ||
</script> |
41 changes: 41 additions & 0 deletions
41
...tory/navigate-event/cross-window/click-samedocument-crossorigin-sameorigindomain.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
|
||
<script> | ||
document.domain = "{{host}}"; | ||
async_test(t => { | ||
const url = new URL("resources/document-domain-setter.sub.html", location.href); | ||
url.hostname = "{{domains[www1]}}"; | ||
const iframe = document.createElement("iframe"); | ||
iframe.name = "windowname"; | ||
iframe.src = url; | ||
document.body.append(iframe); | ||
|
||
url.hash = "#foo"; | ||
const link = document.createElement("a"); | ||
link.href = url; | ||
link.target = iframe.name; | ||
document.body.append(link); | ||
|
||
appHistory.onnavigate = t.unreached_func("onnavigate must not fire in the source window"); | ||
window.onload = t.step_func(() => { | ||
iframe.contentWindow.appHistory.onnavigate = t.step_func_done(e => { | ||
assert_equals(e.navigationType, "push", "navigationType"); | ||
assert_true(e.cancelable, "cancelable"); | ||
assert_true(e.canTransition, "canTransition"); | ||
assert_false(e.userInitiated, "userInitiated"); | ||
assert_true(e.hashChange, "hashChange"); | ||
assert_equals(e.formData, null, "formData"); | ||
assert_equals(e.destination.url, link.href, "destination.url"); | ||
assert_true(e.destination.sameDocument, "destination.sameDocument"); | ||
assert_equals(e.destination.key, null, "destination.key"); | ||
assert_equals(e.destination.id, null, "destination.id"); | ||
assert_equals(e.destination.index, -1, "destination.index"); | ||
}); | ||
|
||
link.click(); | ||
}); | ||
}, "clicking on an <a> element that navigates same-document targeting a same-origin-domain (but cross-origin) window"); | ||
</script> |
39 changes: 39 additions & 0 deletions
39
app-history/navigate-event/cross-window/click-samedocument-crossorigin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/get-host-info.sub.js"></script> | ||
<body> | ||
|
||
<script> | ||
async_test(t => { | ||
const url = new URL("resources/cross-origin-iframe-helper.html", location.href); | ||
url.hostname = get_host_info().REMOTE_HOST; | ||
const iframe = document.createElement("iframe") | ||
iframe.src = url; | ||
iframe.name = "windowname"; | ||
document.body.append(iframe); | ||
|
||
url.hash = "#foo"; | ||
const link = document.createElement("a"); | ||
link.href = url; | ||
link.target = iframe.name; | ||
document.body.append(link); | ||
|
||
window.onmessage = t.step_func_done(e => { | ||
assert_equals(e.data.navigationType, "push", "navigationType"); | ||
assert_true(e.data.cancelable, "cancelable"); | ||
assert_true(e.data.canTransition, "canTransition"); | ||
assert_false(e.data.userInitiated, "userInitiated"); | ||
assert_true(e.data.hashChange, "hashChange"); | ||
assert_equals(e.data.formData, null, "formData"); | ||
assert_equals(e.data.destination.url, link.href, "destination.url"); | ||
assert_true(e.data.destination.sameDocument, "destination.sameDocument"); | ||
assert_equals(e.data.destination.key, null, "destination.key"); | ||
assert_equals(e.data.destination.id, null, "destination.id"); | ||
assert_equals(e.data.destination.index, -1, "destination.index"); | ||
}); | ||
|
||
appHistory.onnavigate = t.unreached_func("onnavigate must not fire in the source window"); | ||
window.onload = t.step_func(() => link.click()); | ||
}, "clicking on an <a> element that navigates same-document targeting a cross-origin window"); | ||
</script> |
27 changes: 27 additions & 0 deletions
27
app-history/navigate-event/cross-window/click-samedocument-sameorigin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<a id="link" href="/common/blank.html#foo" target="windowname">Click me</a> | ||
<iframe id="i" name="windowname" src="/common/blank.html"></iframe> | ||
|
||
<script> | ||
async_test(t => { | ||
i.contentWindow.appHistory.onnavigate = t.step_func_done(e => { | ||
assert_equals(e.navigationType, "push", "navigationType"); | ||
assert_true(e.cancelable, "cancelable"); | ||
assert_true(e.canTransition, "canTransition"); | ||
assert_false(e.userInitiated, "userInitiated"); | ||
assert_true(e.hashChange, "hashChange"); | ||
assert_equals(e.formData, null, "formData"); | ||
assert_equals(e.destination.url, link.href, "destination.url"); | ||
assert_true(e.destination.sameDocument, "destination.sameDocument"); | ||
assert_equals(e.destination.key, null, "destination.key"); | ||
assert_equals(e.destination.id, null, "destination.id"); | ||
assert_equals(e.destination.index, -1, "destination.index"); | ||
}); | ||
|
||
appHistory.onnavigate = t.unreached_func("onnavigate must not fire in the source window"); | ||
window.onload = t.step_func(() => link.click()); | ||
}, "clicking on an <a> element that navigates same-document targeting a same-origin window"); | ||
</script> |
34 changes: 34 additions & 0 deletions
34
.../navigate-event/cross-window/location-crossdocument-crossorigin-sameorigindomain.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
|
||
<script> | ||
document.domain = "{{host}}"; | ||
async_test(t => { | ||
const url = new URL("resources/document-domain-setter.sub.html", location.href); | ||
url.hostname = "{{domains[www1]}}"; | ||
const iframe = document.createElement("iframe"); | ||
iframe.src = url; | ||
document.body.append(iframe); | ||
|
||
appHistory.onnavigate = t.unreached_func("onnavigate must not fire in the source window"); | ||
window.onload = t.step_func(() => { | ||
iframe.contentWindow.appHistory.onnavigate = t.step_func_done(e => { | ||
assert_equals(e.navigationType, "push", "navigationType"); | ||
assert_true(e.cancelable, "cancelable"); | ||
assert_true(e.canTransition, "canTransition"); | ||
assert_false(e.userInitiated, "userInitiated"); | ||
assert_false(e.hashChange, "hashChange"); | ||
assert_equals(e.formData, null, "formData"); | ||
assert_equals(e.destination.url, iframe.src + "?foo", "destination.url"); | ||
assert_false(e.destination.sameDocument, "destination.sameDocument"); | ||
assert_equals(e.destination.key, null, "destination.key"); | ||
assert_equals(e.destination.id, null, "destination.id"); | ||
assert_equals(e.destination.index, -1, "destination.index"); | ||
}); | ||
|
||
iframe.contentWindow.location.href = url + "?foo"; | ||
}); | ||
}, "using location.href to navigate cross-document targeting a same-origin-domain (but cross-origin) window"); | ||
</script> |
23 changes: 23 additions & 0 deletions
23
app-history/navigate-event/cross-window/location-crossdocument-crossorigin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/get-host-info.sub.js"></script> | ||
<body> | ||
|
||
<script> | ||
async_test(t => { | ||
const iframeURL = new URL("resources/cross-origin-iframe-helper.html", location.href); | ||
iframeURL.hostname = get_host_info().REMOTE_HOST; | ||
const iframe = document.createElement("iframe"); | ||
iframe.src = iframeURL; | ||
document.body.append(iframe); | ||
|
||
window.onmessage = t.step_func_done(e => { | ||
// If we hit onnavigate in the target window, we'll get a different message, and fail. | ||
assert_equals(e.data, "DONE"); | ||
}); | ||
|
||
appHistory.onnavigate = t.unreached_func("onnavigate must not fire in the source window"); | ||
window.onload = t.step_func(() => iframe.contentWindow.location.href = iframeURL + "?postMessage-top-when-done"); | ||
}, "using location.href to navigate cross-document targeting a cross-origin window"); | ||
</script> |
26 changes: 26 additions & 0 deletions
26
app-history/navigate-event/cross-window/location-crossdocument-sameorigin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<iframe id="i" src="/common/blank.html"></iframe> | ||
|
||
<script> | ||
async_test(t => { | ||
i.contentWindow.appHistory.onnavigate = t.step_func_done(e => { | ||
assert_equals(e.navigationType, "push", "navigationType"); | ||
assert_true(e.cancelable, "cancelable"); | ||
assert_true(e.canTransition, "canTransition"); | ||
assert_false(e.userInitiated, "userInitiated"); | ||
assert_false(e.hashChange, "hashChange"); | ||
assert_equals(e.formData, null, "formData"); | ||
assert_equals(e.destination.url, i.src + "?foo", "destination.url"); | ||
assert_false(e.destination.sameDocument, "destination.sameDocument"); | ||
assert_equals(e.destination.key, null, "destination.key"); | ||
assert_equals(e.destination.id, null, "destination.id"); | ||
assert_equals(e.destination.index, -1, "destination.index"); | ||
}); | ||
|
||
appHistory.onnavigate = t.unreached_func("onnavigate must not fire in the source window"); | ||
window.onload = t.step_func(() => i.contentWindow.location.href = "/common/blank.html?foo"); | ||
}, "using location.href to navigate cross-document targeting a same-origin window"); | ||
</script> |
34 changes: 34 additions & 0 deletions
34
...y/navigate-event/cross-window/location-samedocument-crossorigin-sameorigindomain.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
|
||
<script> | ||
document.domain = "{{host}}"; | ||
async_test(t => { | ||
const url = new URL("resources/document-domain-setter.sub.html", location.href); | ||
url.hostname = "{{domains[www1]}}"; | ||
const iframe = document.createElement("iframe"); | ||
iframe.src = url; | ||
document.body.append(iframe); | ||
|
||
appHistory.onnavigate = t.unreached_func("onnavigate must not fire in the source window"); | ||
window.onload = t.step_func(() => { | ||
iframe.contentWindow.appHistory.onnavigate = t.step_func_done(e => { | ||
assert_equals(e.navigationType, "push", "navigationType"); | ||
assert_true(e.cancelable, "cancelable"); | ||
assert_true(e.canTransition, "canTransition"); | ||
assert_false(e.userInitiated, "userInitiated"); | ||
assert_true(e.hashChange, "hashChange"); | ||
assert_equals(e.formData, null, "formData"); | ||
assert_equals(e.destination.url, iframe.src + "#foo", "destination.url"); | ||
assert_true(e.destination.sameDocument, "destination.sameDocument"); | ||
assert_equals(e.destination.key, null, "destination.key"); | ||
assert_equals(e.destination.id, null, "destination.id"); | ||
assert_equals(e.destination.index, -1, "destination.index"); | ||
}); | ||
|
||
iframe.contentWindow.location.href = url + "#foo"; | ||
}); | ||
}, "using location.href to navigate same-document targeting a same-origin-domain (but cross-origin) window"); | ||
</script> |
32 changes: 32 additions & 0 deletions
32
app-history/navigate-event/cross-window/location-samedocument-crossorigin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/get-host-info.sub.js"></script> | ||
<body> | ||
|
||
<script> | ||
async_test(t => { | ||
const iframeURL = new URL("resources/cross-origin-iframe-helper.html", location.href); | ||
iframeURL.hostname = get_host_info().REMOTE_HOST; | ||
const iframe = document.createElement("iframe") | ||
iframe.src = iframeURL; | ||
document.body.append(iframe); | ||
|
||
window.onmessage = t.step_func_done(e => { | ||
assert_equals(e.data.navigationType, "push", "navigationType"); | ||
assert_true(e.data.cancelable, "cancelable"); | ||
assert_true(e.data.canTransition, "canTransition"); | ||
assert_false(e.data.userInitiated, "userInitiated"); | ||
assert_true(e.data.hashChange, "hashChange"); | ||
assert_equals(e.data.formData, null, "formData"); | ||
assert_equals(e.data.destination.url, iframe.src + "#foo", "destination.url"); | ||
assert_true(e.data.destination.sameDocument, "destination.sameDocument"); | ||
assert_equals(e.data.destination.key, null, "destination.key"); | ||
assert_equals(e.data.destination.id, null, "destination.id"); | ||
assert_equals(e.data.destination.index, -1, "destination.index"); | ||
}); | ||
|
||
appHistory.onnavigate = t.unreached_func("onnavigate must not fire in the source window"); | ||
window.onload = t.step_func(() => iframe.contentWindow.location.href = iframeURL + "#foo"); | ||
}, "using location.href to navigate same-document targeting a cross-origin window"); | ||
</script> |
26 changes: 26 additions & 0 deletions
26
app-history/navigate-event/cross-window/location-samedocument-sameorigin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<iframe id="i" src="/common/blank.html"></iframe> | ||
|
||
<script> | ||
async_test(t => { | ||
i.contentWindow.appHistory.onnavigate = t.step_func_done(e => { | ||
assert_equals(e.navigationType, "push", "navigationType"); | ||
assert_true(e.cancelable, "cancelable"); | ||
assert_true(e.canTransition, "canTransition"); | ||
assert_false(e.userInitiated, "userInitiated"); | ||
assert_true(e.hashChange, "hashChange"); | ||
assert_equals(e.formData, null, "formData"); | ||
assert_equals(e.destination.url, i.src + "#foo", "destination.url"); | ||
assert_true(e.destination.sameDocument, "destination.sameDocument"); | ||
assert_equals(e.destination.key, null, "destination.key"); | ||
assert_equals(e.destination.id, null, "destination.id"); | ||
assert_equals(e.destination.index, -1, "destination.index"); | ||
}); | ||
|
||
appHistory.onnavigate = t.unreached_func("onnavigate must not fire in the source window"); | ||
window.onload = t.step_func(() => i.contentWindow.location.href = "/common/blank.html#foo"); | ||
}, "using location.href to navigate same-document targeting a same-origin window"); | ||
</script> |
Oops, something went wrong.