blob: e85171ca7c9771cb0e53cc318c88bdfbc36362ff [file] [log] [blame]
Xiaoming Shi73dfa202020-03-12 11:31:35 -07001<!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>
8pre, #log {
9 position: absolute;
10 top: 0;
11 left: 200px;
12}
13iframe {
14 width: 180px;
15 height: 100px;
16}
17</style>
18
19<iframe id="iframe" srcdoc="<div id='target' style='margin:0.5px;width:1000px;height:1000px;'></div>"></iframe>
20
21<script>
22var target;
23var entries = [];
24var observer;
25var iframe = document.getElementById("iframe");
26
27iframe.onload = function() {
28 runTestCycle(function() {
29 target = iframe.contentDocument.getElementById("target");
30 assert_true(!!target, "Target element exists.");
31 observer = new IntersectionObserver(function(changes) {
32 entries = entries.concat(changes);
33 });
34 observer.observe(target);
35 entries = entries.concat(observer.takeRecords());
36 assert_equals(entries.length, 0, "No initial notifications.");
37 runTestCycle(test0, "First rAF should generate notification.");
38 }, "IntersectionObserverEntry.boundingClientRect should match target.boundingClientRect()");
39};
40
41function test0() {
42 assert_equals(entries.length, 1, "One notification.");
43 var bcr = target.getBoundingClientRect();
44 checkLastEntry(entries, 0, [bcr.left, bcr.right, bcr.top, bcr.bottom]);
45}
46</script>