blob: cbd3e15f17746ca6f2e182362a3cd1f90ba12311 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="./resources/intersection-observer-test-utils.js"></script>
<style>
pre, #log {
position: absolute;
top: 0;
left: 200px;
}
#target {
display: inline-block;
width: 100px;
height: 100px;
background-color: green;
}
.vertical-spacer {
height: 700px;
}
.horizontal-spacer {
display: inline-block;
width: 1000px;
}
</style>
<div class="vertical-spacer"></div>
<div style="white-space:nowrap;">
<div class="horizontal-spacer"></div>
<div id="target"></div>
<div class="horizontal-spacer"></div>
</div>
<div class="vertical-spacer"></div>
<script>
var entries = [];
var target;
runTestCycle(function() {
assert_equals(window.innerWidth, 800, "Window must be 800 pixels wide.");
assert_equals(window.innerHeight, 600, "Window must be 600 pixels high.");
target = document.getElementById("target");
assert_true(!!target, "Target exists");
var observer = new IntersectionObserver(function(changes) {
entries = entries.concat(changes)
}, { rootMargin: "10px 20% 40% 30px" });
observer.observe(target);
entries = entries.concat(observer.takeRecords());
assert_equals(entries.length, 0, "No initial notifications.");
runTestCycle(step0, "First rAF.");
}, "Root margin tests");
function step0() {
document.scrollingElement.scrollLeft = 100;
runTestCycle(step1, "document.scrollingElement.scrollLeft = 100");
checkLastEntry(entries, 0, [1012, 1112, 708, 808, 0, 0, 0, 0, -30, 942, -10, 819, false]);
}
function step1() {
document.scrollingElement.scrollTop = 800;
runTestCycle(step2, "document.scrollingElement.scrollTop = 800");
checkLastEntry(entries, 1, [912, 1012, 708, 808, 912, 942, 708, 808, -30, 942, -10, 819, true]);
}
function step2() {
document.scrollingElement.scrollTop = 900;
runTestCycle(step3, "document.scrollingElement.scrollTop = 900");
checkLastEntry(entries, 1);
}
function step3() {
document.scrollingElement.scrollLeft = 0;
document.scrollingElement.scrollTop = 0;
checkLastEntry(entries, 2, [912, 1012, -192, -92, 0, 0, 0, 0, -30, 942, -10, 819, false]);
}
</script>