| 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 <iframe id="target-iframe" src="../resources/intersection-observer-subframe.html
" style="height: 100px; overflow-y: scroll"></iframe> | 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 iframe { |
| 16 height: 100px; |
| 17 width: 150px; |
| 18 } |
| 19 </style> |
| 20 |
| 21 <div class="spacer"></div> |
| 22 <iframe id="target-iframe" src="resources/iframe-no-root-subframe.html"></iframe
> |
| 23 <div class="spacer"></div> |
| 7 | 24 |
| 8 <script> | 25 <script> |
| 9 description("Simple intersection observer test with no explicit root and target
in an iframe."); | 26 var iframe = document.getElementById("target-iframe"); |
| 27 var target; |
| 10 var entries = []; | 28 var entries = []; |
| 11 var observer = new IntersectionObserver(changes => { entries = entries.concat(ch
anges) }, {}); | |
| 12 var targetIframe = document.getElementById("target-iframe"); | |
| 13 var target; | |
| 14 var iframeScroller; | |
| 15 | 29 |
| 16 targetIframe.onload = function() { | 30 iframe.onload = function() { |
| 17 target = targetIframe.contentDocument.getElementById("target"); | 31 runTestCycle(function() { |
| 18 iframeScroller = targetIframe.contentDocument.scrollingElement; | 32 assert_true(!!iframe, "iframe exists"); |
| 19 observer.observe(target); | 33 assert_equals(window.innerWidth, 800, "Window must be 800 pixels wide."); |
| 20 entries = entries.concat(observer.takeRecords()); | 34 assert_equals(window.innerHeight, 600, "Window must be 600 pixels high."); |
| 21 shouldBeEqualToNumber("entries.length", 0); | 35 |
| 22 waitForNotification(step0); | 36 target = iframe.contentDocument.getElementById("target"); |
| 23 } | 37 assert_true(!!target, "Target element exists."); |
| 38 var observer = new IntersectionObserver(function(changes) { |
| 39 entries = entries.concat(changes) |
| 40 }); |
| 41 observer.observe(target); |
| 42 entries = entries.concat(observer.takeRecords()); |
| 43 assert_equals(entries.length, 0, "No initial notifications."); |
| 44 runTestCycle(step0, "No notifications after first rAF."); |
| 45 }, "Observer with the implicit root; target in a same-origin iframe."); |
| 46 }; |
| 24 | 47 |
| 25 function step0() { | 48 function step0() { |
| 26 shouldBeEqualToNumber("entries.length", 0); | |
| 27 document.scrollingElement.scrollTop = 200; | 49 document.scrollingElement.scrollTop = 200; |
| 28 waitForNotification(step1); | 50 runTestCycle(step1, "document.scrollingElement.scrollTop = 200"); |
| 51 assert_equals(entries.length, 0, "entries.length == 0"); |
| 29 } | 52 } |
| 30 | 53 |
| 31 function step1() { | 54 function step1() { |
| 32 shouldBeEqualToNumber("entries.length", 0); | 55 iframe.contentDocument.scrollingElement.scrollTop = 250; |
| 33 iframeScroller.scrollTop = 250; | 56 runTestCycle(step2, "iframe.contentDocument.scrollingElement.scrollTop = 250")
; |
| 34 waitForNotification(step2); | 57 assert_equals(entries.length, 0, "entries.length == 0"); |
| 35 } | 58 } |
| 36 | 59 |
| 37 function step2() { | 60 function step2() { |
| 38 shouldBeEqualToNumber("entries.length", 1); | |
| 39 if (entries.length > 0) { | |
| 40 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8); | |
| 41 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 108); | |
| 42 shouldBeEqualToNumber("entries[0].boundingClientRect.top", -42); | |
| 43 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 58); | |
| 44 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8); | |
| 45 shouldBeEqualToNumber("entries[0].intersectionRect.right", 108); | |
| 46 shouldBeEqualToNumber("entries[0].intersectionRect.top", 0); | |
| 47 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 58); | |
| 48 shouldBeEqualToNumber("entries[0].rootBounds.left", 0); | |
| 49 shouldBeEqualToNumber("entries[0].rootBounds.right", 785); | |
| 50 shouldBeEqualToNumber("entries[0].rootBounds.top", 0); | |
| 51 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600); | |
| 52 shouldEvaluateToSameObject("entries[0].target", target); | |
| 53 } | |
| 54 document.scrollingElement.scrollTop = 100; | 61 document.scrollingElement.scrollTop = 100; |
| 55 waitForNotification(step3); | 62 runTestCycle(step3, "document.scrollingElement.scrollTop = 100"); |
| 63 checkLastEntry(entries, 0, [8, 108, -42, 58, 8, 108, 0, 58, 0, 785, 0, 600, ta
rget]); |
| 56 } | 64 } |
| 57 | 65 |
| 58 function step3() { | 66 function step3() { |
| 59 shouldBeEqualToNumber("entries.length", 2); | 67 checkLastEntry(entries, 1, [8, 108, -42, 58, 0, 0, 0, 0, 0, 785, 0, 600, targe
t]); |
| 60 if (entries.length > 1) { | |
| 61 shouldBeEqualToNumber("entries[1].boundingClientRect.left", 8); | |
| 62 shouldBeEqualToNumber("entries[1].boundingClientRect.right", 108); | |
| 63 shouldBeEqualToNumber("entries[1].boundingClientRect.top", -42); | |
| 64 shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 58); | |
| 65 shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); | |
| 66 shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); | |
| 67 shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); | |
| 68 shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); | |
| 69 shouldBeEqualToNumber("entries[1].rootBounds.left", 0); | |
| 70 shouldBeEqualToNumber("entries[1].rootBounds.right", 785); | |
| 71 shouldBeEqualToNumber("entries[1].rootBounds.top", 0); | |
| 72 shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600); | |
| 73 shouldEvaluateToSameObject("entries[1].target", target); | |
| 74 } | |
| 75 finishJSTest(); | |
| 76 document.scrollingElement.scrollTop = 0; | 68 document.scrollingElement.scrollTop = 0; |
| 77 } | 69 } |
| 78 </script> | 70 </script> |
| OLD | NEW |