Skip to content

Commit 9325cca

Browse files
theIDinsideKurtCattiSchmidt
authored andcommitted
Implement location.ancestorOrigins
This implements this attribute on Location and also adheres to the changes to the spec introduced in whatwg/html#11560 Tentative tests are also added in this patch. Differential Revision: https://phabricator.services.mozilla.com/D273393 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1085214 gecko-commit: f3415e1670266a11917af7fff4ba14afde5d7ca5 gecko-reviewers: necko-reviewers, webidl, dom-core, smaug, jesup, zcorpan, devtools-reviewers, nchevobbe
1 parent 6409b25 commit 9325cca

File tree

5 files changed

+503
-0
lines changed

5 files changed

+503
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Location.ancestorOrigins lifetime behavior</title>
6+
<link rel="help" href="https://html.spec.whatwg.org/multipage/browsing-the-web.html#dom-location-ancestororigins">
7+
<script src="/resources/testharness.js"></script>
8+
<script src="/resources/testharnessreport.js"></script>
9+
</head>
10+
<body>
11+
<script>
12+
function createIframeAndNavigate(test, src) {
13+
return new Promise(resolve => {
14+
const iframe = document.createElement("iframe");
15+
iframe.onload = () => {
16+
resolve(iframe);
17+
}
18+
iframe.src = src;
19+
document.body.appendChild(iframe);
20+
test.add_cleanup(() => {
21+
iframe.remove();
22+
});
23+
});
24+
}
25+
26+
27+
promise_test(async t => {
28+
assert_implements(location.ancestorOrigins, "location.ancestorOrigins not implemented");
29+
const iframe = await createIframeAndNavigate(t, "about:blank");
30+
assert_array_equals(
31+
iframe.contentWindow.location.ancestorOrigins,
32+
[location.origin],
33+
"Initial ancestorOrigins should match expected placeholder value"
34+
);
35+
36+
const loc = iframe.contentWindow.location;
37+
iframe.remove();
38+
39+
assert_array_equals(
40+
Array.from(loc.ancestorOrigins),
41+
[],
42+
"ancestorOrigins should be empty after iframe removal"
43+
);
44+
}, "location.ancestorOrigins returns empty list after iframe is removed and referenced Location's relevant document is null");
45+
46+
promise_test(async t => {
47+
assert_implements(location.ancestorOrigins, "location.ancestorOrigins not implemented");
48+
const iframe = await createIframeAndNavigate(t, "about:blank");
49+
assert_array_equals(
50+
iframe.contentWindow.location.ancestorOrigins,
51+
[location.origin],
52+
"Initial ancestorOrigins should match expected placeholder value"
53+
);
54+
55+
const loc = iframe.contentWindow.location;
56+
await new Promise(resolve => {
57+
iframe.onload = resolve;
58+
iframe.src = "http://{{hosts[alt][]}}:{{ports[http][0]}}/common/blank.html";
59+
});
60+
61+
assert_array_equals(
62+
Array.from(loc.ancestorOrigins),
63+
[],
64+
"ancestorOrigins should be empty after iframe navigation"
65+
);
66+
}, "location.ancestorOrigins returns empty list when iframe navigated away and referenced Location's relevant document is null");
67+
</script>
68+
</body>
69+
70+
</html>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!doctype html>
2+
<title>location.ancestorOrigins snapshot timing of referrerpolicy</title>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<body>
6+
<script>
7+
promise_test(async () => {
8+
assert_implements(location.ancestorOrigins);
9+
const iframe = document.createElement('iframe');
10+
iframe.src = '/common/blank.html?pipe=trickle(d1)';
11+
iframe.referrerPolicy = 'no-referrer';
12+
const loaded = new Promise(resolve => iframe.onload = resolve);
13+
document.body.append(iframe);
14+
// initial about:blank should see 'no-referrer' results
15+
assert_array_equals(Array.from(iframe.contentWindow.location.ancestorOrigins), ['null']);
16+
iframe.referrerPolicy = '';
17+
await loaded;
18+
// The referrerpolicy attribute get snapshotted at step 16 of "beginning navigation"
19+
// https://html.spec.whatwg.org/#beginning-navigation and result should therefore,
20+
// still be ["null"], here.
21+
assert_array_equals(Array.from(iframe.contentWindow.location.ancestorOrigins), ["null"]);
22+
});
23+
24+
promise_test(async () => {
25+
assert_implements(location.ancestorOrigins);
26+
const iframe = document.createElement('iframe');
27+
28+
iframe.referrerPolicy = 'no-referrer';
29+
const loaded = new Promise(resolve => iframe.onload = resolve);
30+
document.body.append(iframe);
31+
// initial about:blank should see 'no-referrer' results
32+
assert_array_equals(Array.from(iframe.contentWindow.location.ancestorOrigins), ['null']);
33+
iframe.referrerPolicy = '';
34+
await loaded;
35+
36+
await new Promise(resolve => {
37+
iframe.onload = resolve;
38+
iframe.src = '/common/blank.html?pipe=trickle(d1)';
39+
});
40+
assert_array_equals(Array.from(iframe.contentWindow.location.ancestorOrigins), [window.origin]);
41+
});
42+
</script>

0 commit comments

Comments
 (0)