OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/js-test.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/intersection-observer-helper-functions.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <div style="width:100%; height:700px;"></div> | 4 <div id="leading-space" style="width:100%; height:700px;"></div> |
5 <iframe id="target-iframe" src="../resources/intersection-observer-subframe.html
" style="height: 100px; overflow-y: scroll"></iframe> | 5 <iframe id="target-iframe" src="resources/iframe-no-root-subframe.html" style="h
eight: 100px; overflow-y: scroll"></iframe> |
6 <div style="width:100%; height:700px;"></div> | 6 <div id="trailing-space" style="width:100%; height:700px;"></div> |
7 | 7 |
8 <script> | 8 <script> |
9 description("Simple intersection observer test with no explicit root and target
in an iframe."); | 9 function waitForNotification(f) { |
10 var entries = []; | 10 requestAnimationFrame(() => { |
11 var observer = new IntersectionObserver(changes => { entries = entries.concat(ch
anges) }, {}); | 11 setTimeout(() => { |
| 12 setTimeout(f); |
| 13 }); |
| 14 }); |
| 15 } |
| 16 |
12 var targetIframe = document.getElementById("target-iframe"); | 17 var targetIframe = document.getElementById("target-iframe"); |
13 var target; | 18 targetIframe.onload = function() { |
14 var iframeScroller; | 19 var t = async_test("Simple intersection observer test with no explicit root an
d target in an iframe."); |
15 | 20 |
16 targetIframe.onload = function() { | 21 test(function() { assert_equals(window.innerWidth, 800) }, "Window must be 800
pixels wide."); |
17 target = targetIframe.contentDocument.getElementById("target"); | 22 test(function() { assert_equals(window.innerHeight, 600) }, "Window must be 60
0 pixels high."); |
18 iframeScroller = targetIframe.contentDocument.scrollingElement; | 23 |
| 24 var target = targetIframe.contentDocument.getElementById("target"); |
| 25 var iframeScroller = targetIframe.contentDocument.scrollingElement; |
| 26 var entries = []; |
| 27 var observer = new IntersectionObserver(function(changes) { |
| 28 entries = entries.concat(changes) |
| 29 }); |
19 observer.observe(target); | 30 observer.observe(target); |
20 entries = entries.concat(observer.takeRecords()); | 31 entries = entries.concat(observer.takeRecords()); |
21 shouldBeEqualToNumber("entries.length", 0); | 32 test(function() { assert_equals(entries.length, 0) }, "No initial notification
s."); |
22 waitForNotification(step0); | 33 waitForNotification(step0); |
23 } | |
24 | 34 |
25 function step0() { | 35 function checkEntry(i, expected) { |
26 shouldBeEqualToNumber("entries.length", 0); | 36 test(function() { assert_equals(entries.length, i+1) }, String(i+1) + " noti
fication(s)."); |
27 document.scrollingElement.scrollTop = 200; | 37 if (expected && entries.length > i) { |
28 waitForNotification(step1); | 38 test(function() { assert_equals(entries[i].boundingClientRect.left, expect
ed[0]) }, |
29 } | 39 "entries[" + i + "].boundingClientRect.left == " + expected[0]); |
| 40 test(function() { assert_equals(entries[i].boundingClientRect.right, expec
ted[1]) }, |
| 41 "entries[" + i + "].boundingClientRect.right == " + expected[1]); |
| 42 test(function() { assert_equals(entries[i].boundingClientRect.top, expecte
d[2]) }, |
| 43 "entries[" + i + "].boundingClientRect.top == " + expected[2]); |
| 44 test(function() { assert_equals(entries[i].boundingClientRect.bottom, expe
cted[3]) }, |
| 45 "entries[" + i + "].boundingClientRect.bottom == " + expected[3]); |
| 46 test(function() { assert_equals(entries[i].intersectionRect.left, expected
[4]) }, |
| 47 "entries[" + i + "].intersectionRect.left == " + expected[4]); |
| 48 test(function() { assert_equals(entries[i].intersectionRect.right, expecte
d[5]) }, |
| 49 "entries[" + i + "].intersectionRect.right == " + expected[5]); |
| 50 test(function() { assert_equals(entries[i].intersectionRect.top, expected[
6]) }, |
| 51 "entries[" + i + "].intersectionRect.top == " + expected[6]); |
| 52 test(function() { assert_equals(entries[i].intersectionRect.bottom, expect
ed[7]) }, |
| 53 "entries[" + i + "].intersectionRect.bottom == " + expected[7]); |
| 54 test(function() { assert_equals(entries[i].rootBounds.left, expected[8]) }
, |
| 55 "entries[" + i + "].rootBounds.left == " + expected[8]); |
| 56 test(function() { assert_equals(entries[i].rootBounds.right, expected[9])
}, |
| 57 "entries[" + i + "].rootBounds.right == " + expected[9]); |
| 58 test(function() { assert_equals(entries[i].rootBounds.top, expected[10]) }
, |
| 59 "entries[" + i + "].rootBounds.top == " + expected[10]); |
| 60 test(function() { assert_equals(entries[i].rootBounds.bottom, expected[11]
) }, |
| 61 "entries[" + i + "].rootBounds.bottom == " + expected[11]); |
| 62 test(function() { assert_true(entries[i].target === expected[12]) }, |
| 63 "entries[" + i + "].target === " + expected[12]); |
| 64 } |
| 65 } |
30 | 66 |
31 function step1() { | 67 function step0() { |
32 shouldBeEqualToNumber("entries.length", 0); | 68 test(function() { assert_equals(entries.length, 0) }, "entries.length == 0")
; |
33 iframeScroller.scrollTop = 250; | 69 document.scrollingElement.scrollTop = 200; |
34 waitForNotification(step2); | 70 waitForNotification(step1); |
35 } | 71 } |
36 | 72 |
37 function step2() { | 73 function step1() { |
38 shouldBeEqualToNumber("entries.length", 1); | 74 test(function() { assert_equals(entries.length, 0) }, "entries.length == 0")
; |
39 if (entries.length > 0) { | 75 iframeScroller.scrollTop = 250; |
40 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8); | 76 waitForNotification(step2); |
41 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 108); | |
42 shouldBeEqualToNumber("entries[0].boundingClientRect.top", -42); | |
43 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 58); | |
44 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8); | |
45 shouldBeEqualToNumber("entries[0].intersectionRect.right", 108); | |
46 shouldBeEqualToNumber("entries[0].intersectionRect.top", 0); | |
47 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 58); | |
48 shouldBeEqualToNumber("entries[0].rootBounds.left", 0); | |
49 shouldBeEqualToNumber("entries[0].rootBounds.right", 785); | |
50 shouldBeEqualToNumber("entries[0].rootBounds.top", 0); | |
51 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600); | |
52 shouldEvaluateToSameObject("entries[0].target", target); | |
53 } | 77 } |
54 document.scrollingElement.scrollTop = 100; | |
55 waitForNotification(step3); | |
56 } | |
57 | 78 |
58 function step3() { | 79 function step2() { |
59 shouldBeEqualToNumber("entries.length", 2); | 80 checkEntry(0, [8, 108, -42, 58, 8, 108, 0, 58, 0, 785, 0, 600, target]); |
60 if (entries.length > 1) { | 81 document.scrollingElement.scrollTop = 100; |
61 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 8); | 82 waitForNotification(step3); |
62 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 108); | |
63 shouldBeEqualToNumber("entries[1].boundingClientRect.top", -42); | |
64 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 58); | |
65 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); | |
66 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); | |
67 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); | |
68 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); | |
69 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); | |
70 shouldBeEqualToNumber("entries[1].rootBounds.right", 785); | |
71 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); | |
72 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); | |
73 shouldEvaluateToSameObject("entries[1].target", target); | |
74 } | 83 } |
75 finishJSTest(); | 84 |
76 document.scrollingElement.scrollTop = 0; | 85 function step3() { |
77 } | 86 checkEntry(1, [8, 108, -42, 58, 0, 0, 0, 0, 0, 785, 0, 600, target]); |
| 87 document.getElementById("leading-space").style.height = ""; |
| 88 document.getElementById("trailing-space").style.height = ""; |
| 89 t.done(); |
| 90 } |
| 91 }; |
78 </script> | 92 </script> |
OLD | NEW |