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 <style> | 4 <style> |
5 #root { | 5 #root { |
6 width: 200px; | 6 width: 200px; |
7 height: 200px; | 7 height: 200px; |
8 overflow-y: scroll; | 8 overflow-y: scroll; |
9 } | 9 } |
10 #target { | 10 #target { |
11 width: 100px; | 11 width: 100px; |
12 height: 100px; | 12 height: 100px; |
13 background-color: green; | 13 background-color: green; |
14 position: absolute; | 14 position: absolute; |
15 } | 15 } |
16 </style> | 16 </style> |
17 <div id="root" style="position: absolute"> | 17 <div id="root" style="position: absolute"> |
18 <div id="target" style="left: 50px; top: 250px"></div> | 18 <div id="target" style="left: 50px; top: 250px"></div> |
19 </div> | 19 </div> |
20 | 20 |
21 <script> | 21 <script> |
22 description("Test that no notifications are generated when root is not in the co
ntaining block chain of target."); | 22 function waitForNotification(f) { |
23 var root = document.getElementById("root"); | 23 requestAnimationFrame(() => { |
24 var target = document.getElementById("target"); | 24 setTimeout(() => { |
25 var entries = []; | 25 setTimeout(f); |
26 | 26 }); |
27 var observer = new IntersectionObserver( | 27 }); |
28 changes => { entries.push(...changes) }, | 28 } |
29 { root: root } | |
30 ); | |
31 | 29 |
32 onload = function() { | 30 onload = function() { |
| 31 var t = async_test("Test that no notifications are generated when root is not
in the containing block chain of target."); |
| 32 |
| 33 test(function() { assert_equals(window.innerWidth, 800) }, "Window must be 800
pixels wide."); |
| 34 test(function() { assert_equals(window.innerHeight, 600) }, "Window must be 60
0 pixels high."); |
| 35 |
| 36 var root = document.getElementById("root"); |
| 37 var target = document.getElementById("target"); |
| 38 var entries = []; |
| 39 var observer = new IntersectionObserver(function(changes) { |
| 40 entries = entries.concat(changes); |
| 41 }, { root: root }); |
33 observer.observe(target); | 42 observer.observe(target); |
34 shouldBeEqualToNumber("entries.length", 0); | 43 entries = entries.concat(observer.takeRecords()); |
| 44 test(function() { assert_equals(entries.length, 0) }, "No initial notification
s."); |
35 target.style.top = "10px"; | 45 target.style.top = "10px"; |
36 waitForNotification(step1); | 46 waitForNotification(step1); |
| 47 |
| 48 function checkEntry(i, expected) { |
| 49 test(function() { assert_equals(entries.length, i+1) }, String(i+1) + " noti
fication(s)."); |
| 50 if (expected && entries.length > i) { |
| 51 test(function() { assert_equals(entries[i].boundingClientRect.left, expect
ed[0]) }, |
| 52 "entries[" + i + "].boundingClientRect.left == " + expected[0]); |
| 53 test(function() { assert_equals(entries[i].boundingClientRect.right, expec
ted[1]) }, |
| 54 "entries[" + i + "].boundingClientRect.right == " + expected[1]); |
| 55 test(function() { assert_equals(entries[i].boundingClientRect.top, expecte
d[2]) }, |
| 56 "entries[" + i + "].boundingClientRect.top == " + expected[2]); |
| 57 test(function() { assert_equals(entries[i].boundingClientRect.bottom, expe
cted[3]) }, |
| 58 "entries[" + i + "].boundingClientRect.bottom == " + expected[3]); |
| 59 test(function() { assert_equals(entries[i].intersectionRect.left, expected
[4]) }, |
| 60 "entries[" + i + "].intersectionRect.left == " + expected[4]); |
| 61 test(function() { assert_equals(entries[i].intersectionRect.right, expecte
d[5]) }, |
| 62 "entries[" + i + "].intersectionRect.right == " + expected[5]); |
| 63 test(function() { assert_equals(entries[i].intersectionRect.top, expected[
6]) }, |
| 64 "entries[" + i + "].intersectionRect.top == " + expected[6]); |
| 65 test(function() { assert_equals(entries[i].intersectionRect.bottom, expect
ed[7]) }, |
| 66 "entries[" + i + "].intersectionRect.bottom == " + expected[7]); |
| 67 test(function() { assert_equals(entries[i].rootBounds.left, expected[8]) }
, |
| 68 "entries[" + i + "].rootBounds.left == " + expected[8]); |
| 69 test(function() { assert_equals(entries[i].rootBounds.right, expected[9])
}, |
| 70 "entries[" + i + "].rootBounds.right == " + expected[9]); |
| 71 test(function() { assert_equals(entries[i].rootBounds.top, expected[10]) }
, |
| 72 "entries[" + i + "].rootBounds.top == " + expected[10]); |
| 73 test(function() { assert_equals(entries[i].rootBounds.bottom, expected[11]
) }, |
| 74 "entries[" + i + "].rootBounds.bottom == " + expected[11]); |
| 75 test(function() { assert_true(entries[i].target === expected[12]) }, |
| 76 "entries[" + i + "].target === " + expected[12]); |
| 77 } |
| 78 } |
| 79 |
| 80 function step1() { |
| 81 checkEntry(0, [58, 158, 18, 118, 58, 158, 18, 118, 8, 193, 8, 208, target]); |
| 82 target.style.top = "250px"; |
| 83 waitForNotification(step2); |
| 84 } |
| 85 |
| 86 function step2() { |
| 87 checkEntry(1, [58, 158, 258, 358, 0, 0, 0, 0, 8, 193, 8, 208, target]); |
| 88 root.style.position = "static"; |
| 89 target.style.top = "10px"; |
| 90 waitForNotification(step3); |
| 91 } |
| 92 |
| 93 function step3() { |
| 94 checkEntry(1); |
| 95 target.style.top = "250px"; |
| 96 waitForNotification(step4); |
| 97 } |
| 98 |
| 99 function step4() { |
| 100 checkEntry(1); |
| 101 target.style.top = "0"; |
| 102 t.done(); |
| 103 } |
37 }; | 104 }; |
38 | |
39 function step1() { | |
40 shouldBeEqualToNumber("entries.length", 1); | |
41 if (entries.length > 0) { | |
42 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 58); | |
43 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 158); | |
44 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 18); | |
45 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 118); | |
46 shouldBeEqualToNumber("entries[0].intersectionRect.left", 58); | |
47 shouldBeEqualToNumber("entries[0].intersectionRect.right", 158); | |
48 shouldBeEqualToNumber("entries[0].intersectionRect.top", 18); | |
49 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 118); | |
50 shouldBeEqualToNumber("entries[0].rootBounds.left", 8); | |
51 shouldBeEqualToNumber("entries[0].rootBounds.right", 193); | |
52 shouldBeEqualToNumber("entries[0].rootBounds.top", 8); | |
53 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 208); | |
54 shouldEvaluateToSameObject("entries[0].target", target); | |
55 } | |
56 target.style.top = "250px"; | |
57 waitForNotification(step2); | |
58 } | |
59 | |
60 function step2() { | |
61 shouldBeEqualToNumber("entries.length", 2); | |
62 if (entries.length > 1) { | |
63 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 58); | |
64 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 158); | |
65 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 258); | |
66 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 358); | |
67 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); | |
68 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); | |
69 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); | |
70 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); | |
71 shouldBeEqualToNumber("entries[1].rootBounds.left", 8); | |
72 shouldBeEqualToNumber("entries[1].rootBounds.right", 193); | |
73 shouldBeEqualToNumber("entries[1].rootBounds.top", 8); | |
74 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 208); | |
75 shouldEvaluateToSameObject("entries[1].target", target); | |
76 } | |
77 root.style.position = "static"; | |
78 target.style.top = "10px"; | |
79 waitForNotification(step3); | |
80 } | |
81 | |
82 function step3() { | |
83 shouldBeEqualToNumber("entries.length", 2); | |
84 target.style.top = "250px"; | |
85 waitForNotification(step4); | |
86 } | |
87 | |
88 function step4() { | |
89 shouldBeEqualToNumber("entries.length", 2); | |
90 finishJSTest(); | |
91 } | |
92 </script> | 105 </script> |
OLD | NEW |