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 |
| 5 <div id="leading-space" style="width:100%; height:700px;"></div> |
5 <div id="target" style="background-color: green; width:0px; height:0px"></div> | 6 <div id="target" style="background-color: green; width:0px; height:0px"></div> |
6 <div style="width:100%; height:700px;"></div> | 7 <div id="trailing-space" style="width:100%; height:700px;"></div> |
7 | 8 |
8 <script> | 9 <script> |
9 description("Intersection observer test with zero-size target element."); | 10 function waitForNotification(f) { |
10 var target = document.getElementById("target"); | 11 requestAnimationFrame(() => { |
11 var entries = []; | 12 setTimeout(() => { |
12 var observer = new IntersectionObserver(changes => { entries = entries.concat(ch
anges) }, {}); | 13 setTimeout(f); |
| 14 }); |
| 15 }); |
| 16 } |
13 | 17 |
14 onload = function() { | 18 onload = function() { |
| 19 var t = async_test("Intersection observer test with zero-size target element."
); |
| 20 |
| 21 test(function() { assert_equals(window.innerWidth, 800) }, "Window must be 800
pixels wide."); |
| 22 test(function() { assert_equals(window.innerHeight, 600) }, "Window must be 60
0 pixels high."); |
| 23 |
| 24 var target = document.getElementById("target"); |
| 25 var entries = []; |
| 26 var observer = new IntersectionObserver(function(changes) { |
| 27 entries = entries.concat(changes) |
| 28 }); |
15 observer.observe(target); | 29 observer.observe(target); |
16 entries.push(...observer.takeRecords()); | 30 entries = entries.concat(observer.takeRecords()); |
17 shouldBeEqualToNumber("entries.length", 0); | 31 test(function() { assert_equals(entries.length, 0) }, "No initial notification
s."); |
18 document.scrollingElement.scrollTop = 300; | 32 waitForNotification(step0); |
19 waitForNotification(step1); | 33 |
| 34 function checkEntry(i, expected) { |
| 35 test(function() { assert_equals(entries.length, i+1) }, String(i+1) + " noti
fication(s)."); |
| 36 if (expected && entries.length > i) { |
| 37 test(function() { assert_equals(entries[i].boundingClientRect.left, expect
ed[0]) }, |
| 38 "entries[" + i + "].boundingClientRect.left == " + expected[0]); |
| 39 test(function() { assert_equals(entries[i].boundingClientRect.right, expec
ted[1]) }, |
| 40 "entries[" + i + "].boundingClientRect.right == " + expected[1]); |
| 41 test(function() { assert_equals(entries[i].boundingClientRect.top, expecte
d[2]) }, |
| 42 "entries[" + i + "].boundingClientRect.top == " + expected[2]); |
| 43 test(function() { assert_equals(entries[i].boundingClientRect.bottom, expe
cted[3]) }, |
| 44 "entries[" + i + "].boundingClientRect.bottom == " + expected[3]); |
| 45 test(function() { assert_equals(entries[i].intersectionRect.left, expected
[4]) }, |
| 46 "entries[" + i + "].intersectionRect.left == " + expected[4]); |
| 47 test(function() { assert_equals(entries[i].intersectionRect.right, expecte
d[5]) }, |
| 48 "entries[" + i + "].intersectionRect.right == " + expected[5]); |
| 49 test(function() { assert_equals(entries[i].intersectionRect.top, expected[
6]) }, |
| 50 "entries[" + i + "].intersectionRect.top == " + expected[6]); |
| 51 test(function() { assert_equals(entries[i].intersectionRect.bottom, expect
ed[7]) }, |
| 52 "entries[" + i + "].intersectionRect.bottom == " + expected[7]); |
| 53 test(function() { assert_equals(entries[i].rootBounds.left, expected[8]) }
, |
| 54 "entries[" + i + "].rootBounds.left == " + expected[8]); |
| 55 test(function() { assert_equals(entries[i].rootBounds.right, expected[9])
}, |
| 56 "entries[" + i + "].rootBounds.right == " + expected[9]); |
| 57 test(function() { assert_equals(entries[i].rootBounds.top, expected[10]) }
, |
| 58 "entries[" + i + "].rootBounds.top == " + expected[10]); |
| 59 test(function() { assert_equals(entries[i].rootBounds.bottom, expected[11]
) }, |
| 60 "entries[" + i + "].rootBounds.bottom == " + expected[11]); |
| 61 test(function() { assert_true(entries[i].target === expected[12]) }, |
| 62 "entries[" + i + "].target === " + expected[12]); |
| 63 } |
| 64 } |
| 65 |
| 66 function step0() { |
| 67 test(function() { assert_equals(entries.length, 0) }, "No notifications afte
r first rAF."); |
| 68 document.scrollingElement.scrollTop = 300; |
| 69 waitForNotification(step1); |
| 70 } |
| 71 |
| 72 function step1() { |
| 73 checkEntry(0, [8, 8, 408, 408, 8, 8, 408, 408, 0, 785, 0, 600, target]); |
| 74 document.scrollingElement.scrollTop = 100; |
| 75 waitForNotification(step2); |
| 76 } |
| 77 |
| 78 function step2() { |
| 79 checkEntry(1, [8, 8, 608, 608, 0, 0, 0, 0, 0, 785, 0, 600, target]); |
| 80 document.getElementById("leading-space").style.height = ""; |
| 81 document.getElementById("trailing-space").style.height = ""; |
| 82 document.scrollingElement.scrollTop = 0; |
| 83 t.done(); |
| 84 } |
20 }; | 85 }; |
21 | |
22 function step1() { | |
23 shouldBeEqualToNumber("entries.length", 1); | |
24 if (entries.length > 0) { | |
25 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8); | |
26 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 8); | |
27 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 408); | |
28 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 408); | |
29 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8); | |
30 shouldBeEqualToNumber("entries[0].intersectionRect.right", 8); | |
31 shouldBeEqualToNumber("entries[0].intersectionRect.top", 408); | |
32 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 408); | |
33 shouldBeEqualToNumber("entries[0].rootBounds.left", 0); | |
34 shouldBeEqualToNumber("entries[0].rootBounds.right", 785); | |
35 shouldBeEqualToNumber("entries[0].rootBounds.top", 0); | |
36 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600); | |
37 shouldEvaluateToSameObject("entries[0].target", target); | |
38 | |
39 // ClientRect members of IntersectionObserverEntry should be stable. | |
40 shouldEvaluateToSameObject("entries[0].boundingClientRect", entries[0].bound
ingClientRect); | |
41 shouldEvaluateToSameObject("entries[0].intersectionRect", entries[0].interse
ctionRect); | |
42 shouldEvaluateToSameObject("entries[0].rootBounds", entries[0].rootBounds); | |
43 } | |
44 document.scrollingElement.scrollTop = 100; | |
45 waitForNotification(step2); | |
46 } | |
47 | |
48 function step2() { | |
49 shouldBeEqualToNumber("entries.length", 2); | |
50 if (entries.length > 1) { | |
51 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 8); | |
52 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 8); | |
53 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 608); | |
54 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 608); | |
55 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); | |
56 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); | |
57 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); | |
58 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); | |
59 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); | |
60 shouldBeEqualToNumber("entries[1].rootBounds.right", 785); | |
61 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); | |
62 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); | |
63 shouldEvaluateToSameObject("entries[1].target", target); | |
64 } | |
65 finishJSTest(); | |
66 document.scrollingElement.scrollTop = 0; | |
67 } | |
68 </script> | 86 </script> |
OLD | NEW |