blob: 48a735f05fb3797cbc538bb71b9fb9d979dd2835 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/js-test.js"></script>
<script src="../resources/intersection-observer-helper-functions.js"></script>
<div style="width:100%; height:700px;"></div>
<iframe id="target-iframe" src="../resources/intersection-observer-subframe.html" style="height: 100px; overflow-y: scroll"></iframe>
<div style="width:100%; height:700px;"></div>
<script>
description("Simple intersection observer test with no explicit root and target in an iframe.");
var entries = [];
var observer = new IntersectionObserver(changes => { entries = entries.concat(changes) }, {});
var targetIframe = document.getElementById("target-iframe");
var target;
var iframeScroller;
targetIframe.onload = function() {
target = targetIframe.contentDocument.getElementById("target");
iframeScroller = targetIframe.contentDocument.scrollingElement;
observer.observe(target);
entries = entries.concat(observer.takeRecords());
shouldBeEqualToNumber("entries.length", 0);
waitForNotification(step0);
}
function step0() {
shouldBeEqualToNumber("entries.length", 0);
document.scrollingElement.scrollTop = 200;
waitForNotification(step1);
}
function step1() {
shouldBeEqualToNumber("entries.length", 0);
iframeScroller.scrollTop = 250;
waitForNotification(step2);
}
function step2() {
shouldBeEqualToNumber("entries.length", 1);
if (entries.length > 0) {
shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8);
shouldBeEqualToNumber("entries[0].boundingClientRect.right", 108);
shouldBeEqualToNumber("entries[0].boundingClientRect.top", -42);
shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 58);
shouldBeEqualToNumber("entries[0].intersectionRect.left", 8);
shouldBeEqualToNumber("entries[0].intersectionRect.right", 108);
shouldBeEqualToNumber("entries[0].intersectionRect.top", 0);
shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 58);
shouldBeEqualToNumber("entries[0].rootBounds.left", 0);
shouldBeEqualToNumber("entries[0].rootBounds.right", 785);
shouldBeEqualToNumber("entries[0].rootBounds.top", 0);
shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600);
shouldEvaluateToSameObject("entries[0].target", target);
}
document.scrollingElement.scrollTop = 100;
waitForNotification(step3);
}
function step3() {
shouldBeEqualToNumber("entries.length", 2);
if (entries.length > 1) {
shouldBeEqualToNumber("entries[1].boundingClientRect.left", 8);
shouldBeEqualToNumber("entries[1].boundingClientRect.right", 108);
shouldBeEqualToNumber("entries[1].boundingClientRect.top", -42);
shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 58);
shouldBeEqualToNumber("entries[1].intersectionRect.left", 0);
shouldBeEqualToNumber("entries[1].intersectionRect.right", 0);
shouldBeEqualToNumber("entries[1].intersectionRect.top", 0);
shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0);
shouldBeEqualToNumber("entries[1].rootBounds.left", 0);
shouldBeEqualToNumber("entries[1].rootBounds.right", 785);
shouldBeEqualToNumber("entries[1].rootBounds.top", 0);
shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600);
shouldEvaluateToSameObject("entries[1].target", target);
}
finishJSTest();
document.scrollingElement.scrollTop = 0;
}
</script>