Skip to content

Commit

Permalink
[IntersectionObserver] Use inclusive intersect with remote frame parent
Browse files Browse the repository at this point in the history
The rest of the MapToVisualRectInAncestorSpace code will do inclusive
intersections when the kEdgeInclusive flag is set, as required by
IntersectionObserver to correctly handle zero-area targets.

This patch adds coverage for this situation to the existing WPT for
cross-origin IntersectionObserver. Since the bug only affects
IntersectionObserver running inside an OOPIF, this also updates the
test to force the iframe into a different domain, rather than just
using the sandbox attribute (which is not sufficient to trigger OOPIF).

BUG=978759

Change-Id: I7dbe52d2f3e39e029fed3dda5be31190c593a1e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1754595
Reviewed-by: Ken Buchanan <kenrb@chromium.org>
Commit-Queue: Stefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/heads/master@{#687361}
  • Loading branch information
szager-chromium authored and Hexcles committed Aug 16, 2019
1 parent c1e8936 commit 504feb2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
Expand Up @@ -21,7 +21,7 @@
</style>

<div class="spacer"></div>
<iframe src="resources/cross-origin-subframe.html" sandbox="allow-scripts"></iframe>
<iframe src="http://{{hosts[alt][]}}:{{ports[http][0]}}/intersection-observer/resources/cross-origin-subframe.html" sandbox="allow-scripts"></iframe>
<div class="spacer"></div>

<script>
Expand Down
48 changes: 32 additions & 16 deletions intersection-observer/resources/cross-origin-subframe.html
@@ -1,12 +1,14 @@
<!DOCTYPE html>
<div style="height: 200px; width: 100px;"></div>
<div id="target" style="background-color: green; width:100px; height:100px"></div>
<div id="empty-target" style="width: 100px"></div>
<div style="height: 200px; width: 100px;"></div>

<script>
var port;
var entries = [];
var target = document.getElementById('target');
var target = document.getElementById("target");
var emptyTarget = document.getElementById("empty-target");
var scroller = document.scrollingElement;
var nextStep;

Expand All @@ -26,19 +28,11 @@
boundingClientRect: clientRectToJson(entry.boundingClientRect),
intersectionRect: clientRectToJson(entry.intersectionRect),
rootBounds: clientRectToJson(entry.rootBounds),
isIntersecting: entry.isIntersecting,
target: entry.target.id
};
}

function coordinatesToClientRectJson(top, right, bottom, left) {
return {
top: top,
right: right,
bottom: bottom,
left: left
};
}

// Note that we never use RAF in this code, because this frame might get render-throttled.
// Instead of RAF-ing, we just post an empty message to the parent window, which will
// RAF when it is received, and then send us a message to cause the next step to run.
Expand All @@ -48,15 +42,23 @@
entries = entries.concat(changes)
}, { rootMargin: "7px" });
observer.observe(target);
observer.observe(emptyTarget);

function step0() {
entries = entries.concat(observer.takeRecords());
nextStep = step1;
var expected = [{
boundingClientRect: coordinatesToClientRectJson(8, 208, 108, 308),
intersectionRect: coordinatesToClientRectJson(0, 0, 0, 0),
boundingClientRect: [8, 108, 208, 308],
intersectionRect: [0, 0, 0, 0],
rootBounds: "null",
isIntersecting: false,
target: target.id
}, {
boundingClientRect: [8, 108, 308, 308],
intersectionRect: [0, 0, 0, 0],
rootBounds: "null",
isIntersecting: false,
target: emptyTarget.id
}];
port.postMessage({
actual: entries.map(entryToJson),
Expand All @@ -83,10 +85,17 @@
function step2() {
entries = entries.concat(observer.takeRecords());
var expected = [{
boundingClientRect: coordinatesToClientRectJson(-42, 108, 58, 8),
intersectionRect: coordinatesToClientRectJson(0, 108, 58, 8),
boundingClientRect: [8, 108, -42, 58],
intersectionRect: [8, 108, 0, 58],
rootBounds: "null",
isIntersecting: true,
target: target.id
}, {
boundingClientRect: [8, 108, 58, 58],
intersectionRect: [8, 108, 58, 58],
rootBounds: "null",
isIntersecting: true,
target: emptyTarget.id
}];
port.postMessage({
actual: entries.map(entryToJson),
Expand All @@ -101,10 +110,17 @@
function step3() {
entries = entries.concat(observer.takeRecords());
var expected = [{
boundingClientRect: coordinatesToClientRectJson(-42, 108, 58, 8),
intersectionRect: coordinatesToClientRectJson(0, 0, 0, 0),
boundingClientRect: [8, 108, -42, 58],
intersectionRect: [0, 0, 0, 0],
rootBounds: "null",
isIntersecting: false,
target: target.id
}, {
boundingClientRect: [8, 108, 58, 58],
intersectionRect: [0, 0, 0, 0],
rootBounds: "null",
isIntersecting: false,
target: emptyTarget.id
}];
port.postMessage({
actual: entries.map(entryToJson),
Expand Down
Expand Up @@ -178,6 +178,7 @@ function checkJsonEntry(actual, expected) {
assert_equals(expected.rootBounds, 'null', 'rootBounds is null');
else
checkRect(actual.rootBounds, expected.rootBounds, 'entry.rootBounds');
assert_equals(actual.isIntersecting, expected.isIntersecting);
assert_equals(actual.target, expected.target);
}

Expand Down

0 comments on commit 504feb2

Please sign in to comment.