OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/js-test.js"></script> | 2 <script src="../resources/js-test.js"></script> |
3 <script src="helper-functions.js"></script> | 3 <script src="helper-functions.js"></script> |
4 <div style="width:100%; height:700px;"></div> | 4 <div style="width:100%; height:700px;"></div> |
5 <div style="white-space: nowrap;"> | 5 <div style="white-space: nowrap;"> |
6 <div style="display: inline-block; width: 1000px; height: 100px"></div> | 6 <div style="display: inline-block; width: 1000px; height: 100px"></div> |
7 <div id="target" style="display: inline-block; background-color: green; width:
100px; height:100px"></div> | 7 <div id="target" style="display: inline-block; background-color: green; width:
100px; height:100px"></div> |
8 <div style="display: inline-block; width: 1000px; height: 100px"></div> | 8 <div style="display: inline-block; width: 1000px; height: 100px"></div> |
9 </div> | 9 </div> |
10 <div style="width:100%; height:700px;"></div> | 10 <div style="width:100%; height:700px;"></div> |
11 | 11 |
12 <script> | 12 <script> |
13 description("Intersection observer test with root margin and implicit root."); | 13 description("Intersection observer test with root margin and implicit root."); |
14 var target = document.getElementById("target"); | 14 var target = document.getElementById("target"); |
15 var entries = []; | 15 var entries = []; |
16 var observer = new IntersectionObserver( | |
17 changes => { entries = entries.concat(changes) }, | |
18 { rootMargin: "10px 20% 40% 30px" } | |
19 ); | |
20 | 16 |
21 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px' })"); | 17 function observer_callback(changes) { |
22 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px 2px' })")
; | 18 for (var i in changes) |
23 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px 2px 3%' }
)"); | 19 entries.push(changes[i]); |
24 shouldNotThrow("new IntersectionObserver(c => {}, { rootMargin: '1.4px 2px 3% 40
px junk junk junk' })"); | 20 } |
25 | 21 |
26 onload = function() { | 22 var observer = new IntersectionObserver(observer_callback, { |
| 23 rootMargin: "10px 20% 40% 30px" |
| 24 }); |
27 observer.observe(target); | 25 observer.observe(target); |
28 entries = entries.concat(observer.takeRecords()); | |
29 shouldBeEqualToNumber("entries.length", 0); | |
30 // See README for explanation of double RAF. | |
31 requestAnimationFrame(() => { requestAnimationFrame(step0) }); | |
32 } | |
33 | 26 |
34 function step0() { | 27 function step0() { |
35 entries = entries.concat(observer.takeRecords()); | 28 setTimeout(function() { |
36 shouldBeEqualToNumber("entries.length", 0); | 29 shouldNotThrow("new IntersectionObserver(observer_callback, { rootMargin:
'1.4px' })"); |
37 document.scrollingElement.scrollLeft = 100; | 30 shouldNotThrow("new IntersectionObserver(observer_callback, { rootMargin:
'1.4px 2px' })"); |
38 requestAnimationFrame(step1); | 31 shouldNotThrow("new IntersectionObserver(observer_callback, { rootMargin:
'1.4px 2px 3%' })"); |
39 } | 32 shouldNotThrow("new IntersectionObserver(observer_callback, { rootMargin:
'1.4px 2px 3% 40px junk junk junk' })"); |
| 33 shouldBeEqualToNumber("entries.length", 0); |
| 34 document.scrollingElement.scrollLeft = 100; |
| 35 requestAnimationFrame(step1); |
| 36 }); |
| 37 } |
40 | 38 |
41 function step1() { | 39 function step1() { |
42 entries = entries.concat(observer.takeRecords()); | 40 setTimeout(function() { |
43 shouldBeEqualToNumber("entries.length", 1); | 41 shouldBeEqualToNumber("entries.length", 1); |
44 if (entries.length > 0) { | 42 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 912); |
45 shouldBeEqualToNumber("entries.length", 1); | 43 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 1012); |
46 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 912); | 44 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 708); |
47 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 1012); | 45 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 808); |
48 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 708); | 46 shouldBeEqualToNumber("entries[0].intersectionRect.left", 912); |
49 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 808); | 47 shouldBeEqualToNumber("entries[0].intersectionRect.right", 942); |
50 shouldBeEqualToNumber("entries[0].intersectionRect.left", 912); | 48 shouldBeEqualToNumber("entries[0].intersectionRect.top", 708); |
51 shouldBeEqualToNumber("entries[0].intersectionRect.right", 942); | 49 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 808); |
52 shouldBeEqualToNumber("entries[0].intersectionRect.top", 708); | 50 shouldBeEqualToNumber("entries[0].rootBounds.left", -30); |
53 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 808); | 51 shouldBeEqualToNumber("entries[0].rootBounds.right", 942); |
54 shouldBeEqualToNumber("entries[0].rootBounds.left", -30); | 52 shouldBeEqualToNumber("entries[0].rootBounds.top", -10); |
55 shouldBeEqualToNumber("entries[0].rootBounds.right", 942); | 53 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 819); |
56 shouldBeEqualToNumber("entries[0].rootBounds.top", -10); | 54 shouldEvaluateToSameObject("entries[0].target", target); |
57 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 819); | 55 document.scrollingElement.scrollTop = 800; |
58 shouldEvaluateToSameObject("entries[0].target", target); | 56 requestAnimationFrame(step2); |
| 57 }); |
59 } | 58 } |
60 document.scrollingElement.scrollTop = 800; | |
61 requestAnimationFrame(step2); | |
62 } | |
63 | 59 |
64 function step2() { | 60 function step2() { |
65 entries = entries.concat(observer.takeRecords()); | 61 setTimeout(function() { |
66 shouldBeEqualToNumber("entries.length", 1); | 62 shouldBeEqualToNumber("entries.length", 1); |
67 document.scrollingElement.scrollTop = 900; | 63 document.scrollingElement.scrollTop = 900; |
68 requestAnimationFrame(step3); | 64 requestAnimationFrame(step3); |
69 } | 65 }); |
| 66 } |
70 | 67 |
71 function step3() { | 68 function step3() { |
72 entries = entries.concat(observer.takeRecords()); | 69 setTimeout(function() { |
73 shouldBeEqualToNumber("entries.length", 2); | 70 shouldBeEqualToNumber("entries.length", 2); |
74 if (entries.length > 1) { | 71 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 912); |
75 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 912); | 72 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 1012); |
76 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 1012); | 73 shouldBeEqualToNumber("entries[1].boundingClientRect.top", -192); |
77 shouldBeEqualToNumber("entries[1].boundingClientRect.top", -192); | 74 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", -92); |
78 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", -92); | 75 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); |
79 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); | 76 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); |
80 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); | 77 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); |
81 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); | 78 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); |
82 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); | 79 shouldBeEqualToNumber("entries[1].rootBounds.left", -30); |
83 shouldBeEqualToNumber("entries[1].rootBounds.left", -30); | 80 shouldBeEqualToNumber("entries[1].rootBounds.right", 942); |
84 shouldBeEqualToNumber("entries[1].rootBounds.right", 942); | 81 shouldBeEqualToNumber("entries[1].rootBounds.top", -10); |
85 shouldBeEqualToNumber("entries[1].rootBounds.top", -10); | 82 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 819); |
86 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 819); | 83 shouldEvaluateToSameObject("entries[1].target", target); |
87 shouldEvaluateToSameObject("entries[1].target", target); | 84 |
| 85 finishJSTest(); |
| 86 document.scrollingElement.scrollLeft = 0; |
| 87 document.scrollingElement.scrollTop = 0; |
| 88 }); |
88 } | 89 } |
89 finishJSTest(); | 90 |
90 document.scrollingElement.scrollLeft = 0; | 91 step0(); |
91 document.scrollingElement.scrollTop = 0; | |
92 } | |
93 </script> | 92 </script> |
OLD | NEW |