Skip to content

Commit f874f36

Browse files
[IntersectionObserver] Fix cross-origin check for honoring rootMargin
An issue on the IntersectionObserver spec repo raised the issue of the precise limitation on rootMargin and rootBounds. The original spec language refers to the "unit of related similar-origin browsing contexts", which suggests that cross-origin same-site observations could use rootMargin and rootBounds. That is incorrect; same-site cross-origin observations should *not* be able to use rootMargin and rootBounds. Chromium already conforms to the more restrictive behavior; this CL is just to add a test to enforce it. w3c/IntersectionObserver#448 Separately, the existing cross-origin-iframe.sub.html test was disabled due to flakiness; and then a subsequent code change broke the cross-origin limitation for applying rootMargin, so the test has been reliably failing. This patch fixes the cross-origin check and reenables the test. Change-Id: Ib864f9a9433b4d323ef73a3b2b5a8f645697c07c
1 parent 1bffae4 commit f874f36

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<meta name="viewport" content="width=device-width,initial-scale=1">
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="./resources/intersection-observer-test-utils.js"></script>
6+
7+
<style>
8+
pre, #log {
9+
position: absolute;
10+
top: 0;
11+
left: 200px;
12+
}
13+
iframe {
14+
width: 160px;
15+
height: 100px;
16+
overflow-y: scroll;
17+
}
18+
.spacer {
19+
height: calc(100vh + 100px);
20+
}
21+
</style>
22+
23+
<div class="spacer"></div>
24+
<iframe src="http://{{hosts[][www1]}}:{{ports[http][0]}}/intersection-observer/resources/cross-origin-subframe.html" sandbox="allow-scripts"></iframe>
25+
<div class="spacer"></div>
26+
27+
<script>
28+
async_test(function(t) {
29+
var iframe = document.querySelector("iframe");
30+
31+
function handleMessage(event) {
32+
if (event.data.hasOwnProperty('scrollTo')) {
33+
document.scrollingElement.scrollTop = event.data.scrollTo;
34+
waitForNotification(t, function() { iframe.contentWindow.postMessage("", "*"); },
35+
"document.scrollingElement.scrollTop = " + event.data.scrollTo);
36+
} else if (event.data.hasOwnProperty('actual')) {
37+
checkJsonEntries(event.data.actual, event.data.expected, event.data.description);
38+
} else if (event.data.hasOwnProperty('DONE')) {
39+
document.scrollingElement.scrollTop = 0;
40+
t.done();
41+
} else {
42+
var description = event.data.description;
43+
waitForNotification(t, function() { iframe.contentWindow.postMessage("", "*"); }, description);
44+
}
45+
}
46+
47+
window.addEventListener("message", t.step_func(handleMessage));
48+
49+
iframe.onload = t.step_func(function() {
50+
waitForNotification(t, function() { iframe.contentWindow.postMessage("", "*") }, "setup");
51+
});
52+
}, "Intersection observer test with no explicit root and target in a cross-origin iframe.");
53+
</script>

0 commit comments

Comments
 (0)