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 <script src="./resources/intersection-observer-test-utils.js"></script> |
5 <div style="white-space: nowrap;"> | 5 |
6 <div style="display: inline-block; width: 1000px; height: 100px"></div> | 6 <style> |
7 <div id="target" style="display: inline-block; background-color: green; width:
100px; height:100px"></div> | 7 pre, #log { |
8 <div style="display: inline-block; width: 1000px; height: 100px"></div> | 8 position: absolute; |
| 9 top: 0; |
| 10 left: 200px; |
| 11 } |
| 12 #target { |
| 13 display: inline-block; |
| 14 width: 100px; |
| 15 height: 100px; |
| 16 background-color: green; |
| 17 } |
| 18 .vertical-spacer { |
| 19 height: 700px; |
| 20 } |
| 21 .horizontal-spacer { |
| 22 display: inline-block; |
| 23 width: 1000px; |
| 24 } |
| 25 </style> |
| 26 |
| 27 <div class="vertical-spacer"></div> |
| 28 <div style="white-space:nowrap;"> |
| 29 <div class="horizontal-spacer"></div> |
| 30 <div id="target"></div> |
| 31 <div class="horizontal-spacer"></div> |
9 </div> | 32 </div> |
10 <div style="width:100%; height:700px;"></div> | 33 <div class="vertical-spacer"></div> |
11 | 34 |
12 <script> | 35 <script> |
13 description("Intersection observer test with root margin and implicit root."); | |
14 var target = document.getElementById("target"); | |
15 var entries = []; | 36 var entries = []; |
16 var observer = new IntersectionObserver( | 37 var target; |
17 changes => { entries = entries.concat(changes) }, | |
18 { rootMargin: "10px 20% 40% 30px" } | |
19 ); | |
20 | 38 |
21 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px' })"); | 39 runTestCycle(function() { |
22 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px 2px' })")
; | 40 assert_equals(window.innerWidth, 800, "Window must be 800 pixels wide."); |
23 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px 2px 3%' }
)"); | 41 assert_equals(window.innerHeight, 600, "Window must be 600 pixels high."); |
24 | 42 |
25 onload = function() { | 43 target = document.getElementById("target"); |
| 44 assert_true(!!target, "Target exists"); |
| 45 var observer = new IntersectionObserver(function(changes) { |
| 46 entries = entries.concat(changes) |
| 47 }, { rootMargin: "10px 20% 40% 30px" }); |
26 observer.observe(target); | 48 observer.observe(target); |
27 entries = entries.concat(observer.takeRecords()); | 49 entries = entries.concat(observer.takeRecords()); |
28 shouldBeEqualToNumber("entries.length", 0); | 50 assert_equals(entries.length, 0, "No initial notifications."); |
29 waitForNotification(step0); | 51 runTestCycle(step0, "First rAF."); |
30 } | 52 }, "Root margin tests"); |
31 | 53 |
32 function step0() { | 54 function step0() { |
33 shouldBeEqualToNumber("entries.length", 0); | |
34 document.scrollingElement.scrollLeft = 100; | 55 document.scrollingElement.scrollLeft = 100; |
35 waitForNotification(step1); | 56 runTestCycle(step1, "document.scrollingElement.scrollLeft = 100"); |
| 57 assert_equals(entries.length, 0, "No notifications after first rAF."); |
36 } | 58 } |
37 | 59 |
38 function step1() { | 60 function step1() { |
39 shouldBeEqualToNumber("entries.length", 1); | |
40 if (entries.length > 0) { | |
41 shouldBeEqualToNumber("entries.length", 1); | |
42 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 912); | |
43 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 1012); | |
44 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 708); | |
45 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 808); | |
46 shouldBeEqualToNumber("entries[0].intersectionRect.left", 912); | |
47 shouldBeEqualToNumber("entries[0].intersectionRect.right", 942); | |
48 shouldBeEqualToNumber("entries[0].intersectionRect.top", 708); | |
49 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 808); | |
50 shouldBeEqualToNumber("entries[0].rootBounds.left", -30); | |
51 shouldBeEqualToNumber("entries[0].rootBounds.right", 942); | |
52 shouldBeEqualToNumber("entries[0].rootBounds.top", -10); | |
53 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 819); | |
54 shouldEvaluateToSameObject("entries[0].target", target); | |
55 } | |
56 document.scrollingElement.scrollTop = 800; | 61 document.scrollingElement.scrollTop = 800; |
57 waitForNotification(step2); | 62 runTestCycle(step2, "document.scrollingElement.scrollTop = 800"); |
| 63 checkLastEntry(entries, 0, [912, 1012, 708, 808, 912, 942, 708, 808, -30, 942,
-10, 819, target]); |
58 } | 64 } |
59 | 65 |
60 function step2() { | 66 function step2() { |
61 shouldBeEqualToNumber("entries.length", 1); | |
62 document.scrollingElement.scrollTop = 900; | 67 document.scrollingElement.scrollTop = 900; |
63 waitForNotification(step3); | 68 runTestCycle(step3, "document.scrollingElement.scrollTop = 900"); |
| 69 checkLastEntry(entries, 0); |
64 } | 70 } |
65 | 71 |
66 function step3() { | 72 function step3() { |
67 shouldBeEqualToNumber("entries.length", 2); | |
68 if (entries.length > 1) { | |
69 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 912); | |
70 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 1012); | |
71 shouldBeEqualToNumber("entries[1].boundingClientRect.top", -192); | |
72 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", -92); | |
73 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); | |
74 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); | |
75 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); | |
76 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); | |
77 shouldBeEqualToNumber("entries[1].rootBounds.left", -30); | |
78 shouldBeEqualToNumber("entries[1].rootBounds.right", 942); | |
79 shouldBeEqualToNumber("entries[1].rootBounds.top", -10); | |
80 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 819); | |
81 shouldEvaluateToSameObject("entries[1].target", target); | |
82 } | |
83 finishJSTest(); | |
84 document.scrollingElement.scrollLeft = 0; | 73 document.scrollingElement.scrollLeft = 0; |
85 document.scrollingElement.scrollTop = 0; | 74 document.scrollingElement.scrollTop = 0; |
| 75 checkLastEntry(entries, 1, [912, 1012, -192, -92, 0, 0, 0, 0, -30, 942, -10, 8
19, target]); |
86 } | 76 } |
87 </script> | 77 </script> |
OLD | NEW |