| 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 id="target" style="background-color: green; width:100px; height:100px"></di
v> | 5 |
| 6 <div style="width:100%; height:700px;"></div> | 6 <style> |
| 7 pre, #log { |
| 8 position: absolute; |
| 9 top: 0; |
| 10 left: 200px; |
| 11 } |
| 12 .spacer { |
| 13 height: 700px; |
| 14 } |
| 15 #target { |
| 16 width: 100px; |
| 17 height: 100px; |
| 18 background-color: green; |
| 19 } |
| 20 </style> |
| 21 |
| 22 <div class="spacer"></div> |
| 23 <div id="target"></div> |
| 24 <div class="spacer"></div> |
| 7 | 25 |
| 8 <script> | 26 <script> |
| 9 description("Simple intersection observer test with no explicit root and one doc
ument."); | |
| 10 var target = document.getElementById("target"); | |
| 11 var entries = []; | 27 var entries = []; |
| 12 var observer = new IntersectionObserver(changes => { entries = entries.concat(ch
anges) }); | 28 var target; |
| 13 | 29 |
| 14 onload = function() { | 30 runTestCycle(function() { |
| 31 assert_equals(window.innerWidth, 800, "Window must be 800 pixels wide."); |
| 32 assert_equals(window.innerHeight, 600, "Window must be 600 pixels high."); |
| 33 |
| 34 target = document.getElementById("target"); |
| 35 assert_true(!!target, "target exists"); |
| 36 var observer = new IntersectionObserver(function(changes) { |
| 37 entries = entries.concat(changes) |
| 38 }); |
| 15 observer.observe(target); | 39 observer.observe(target); |
| 16 entries = entries.concat(observer.takeRecords()); | 40 entries = entries.concat(observer.takeRecords()); |
| 17 shouldBeEqualToNumber("entries.length", 0); | 41 assert_equals(entries.length, 0, "No initial notifications."); |
| 42 runTestCycle(step0, "First rAF."); |
| 43 }, "IntersectionObserver in a single document using the implicit root."); |
| 44 |
| 45 function step0() { |
| 18 document.scrollingElement.scrollTop = 300; | 46 document.scrollingElement.scrollTop = 300; |
| 19 waitForNotification(step1); | 47 runTestCycle(step1, "document.scrollingElement.scrollTop = 300"); |
| 20 }; | 48 assert_equals(entries.length, 0, "No notifications after first rAF."); |
| 49 } |
| 21 | 50 |
| 22 function step1() { | 51 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", 108); | |
| 27 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 408); | |
| 28 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 508); | |
| 29 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8); | |
| 30 shouldBeEqualToNumber("entries[0].intersectionRect.right", 108); | |
| 31 shouldBeEqualToNumber("entries[0].intersectionRect.top", 408); | |
| 32 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 508); | |
| 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; | 52 document.scrollingElement.scrollTop = 100; |
| 45 waitForNotification(step2); | 53 runTestCycle(step2, "document.scrollingElement.scrollTop = 100"); |
| 54 checkLastEntry(entries, 0, [8, 108, 408, 508, 8, 108, 408, 508, 0, 785, 0, 600
, target]); |
| 46 } | 55 } |
| 47 | 56 |
| 48 function step2() { | 57 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", 108); | |
| 53 shouldBeEqualToNumber("entries[1].boundingClientRect.top", 608); | |
| 54 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 708); | |
| 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; | 58 document.scrollingElement.scrollTop = 0; |
| 59 checkLastEntry(entries, 1, [8, 108, 608, 708, 0, 0, 0, 0, 0, 785, 0, 600, targ
et]); |
| 67 } | 60 } |
| 68 | |
| 69 </script> | 61 </script> |
| OLD | NEW |