blob: 13dc3abea2d8b0438ac76e9da974718778bcbb12 [file] [log] [blame]
Ali Juma69f77c22018-07-17 21:31:431<!DOCTYPE html>
2<script src="/resources/testharness.js"></script>
3<script src="/resources/testharnessreport.js"></script>
4<script src="./resources/intersection-observer-test-utils.js"></script>
5
6<style>
7pre, #log {
8 position: absolute;
9 top: 0;
10 left: 200px;
11}
12.spacer {
13 height: calc(100vh + 100px);
14}
15</style>
16
17<div class="spacer"></div>
18<br id="target">
19<div class="spacer"></div>
20
21<script>
22var vw = document.documentElement.clientWidth;
23var vh = document.documentElement.clientHeight;
24
25var entries = [];
26var target;
27var tw, th;
28
29runTestCycle(function() {
30 target = document.getElementById("target");
31 let target_rect = target.getBoundingClientRect();
32 tw = target_rect.width;
33 th = target_rect.height;
34 assert_true(!!target, "target exists");
35 var observer = new IntersectionObserver(function(changes) {
36 entries = entries.concat(changes)
37 });
38 observer.observe(target);
39 entries = entries.concat(observer.takeRecords());
40 assert_equals(entries.length, 0, "No initial notifications.");
41 runTestCycle(step0, "First rAF.");
42}, "IntersectionObserver observing a br element.");
43
44function step0() {
45 document.scrollingElement.scrollTop = 300;
46 runTestCycle(step1, "document.scrollingElement.scrollTop = 300");
47 // The numbers in brackets are target client rect; intersection rect;
48 // and root bounds.
49 checkLastEntry(entries, 0, [8, 8 + tw, vh + 108, vh + 108 + th, 0, 0, 0, 0, 0, vw, 0, vh, false]);
50}
51
52function step1() {
53 document.scrollingElement.scrollTop = 100;
54 runTestCycle(step2, "document.scrollingElement.scrollTop = 100");
55 checkLastEntry(entries, 1, [8, 8 + tw, vh - 192, vh - 192 + th, 8, 8 + tw, vh - 192, vh - 192 + th, 0, vw, 0, vh, true]);
56}
57
58function step2() {
59 document.scrollingElement.scrollTop = 0;
60 checkLastEntry(entries, 2, [8, 8 + tw, vh + 8, vh + 8 + th, 0, 0, 0, 0, 0, vw, 0, vh, false]);
61}
62</script>