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