| <!DOCTYPE html> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="./resources/intersection-observer-test-utils.js"></script> |
| |
| <style> |
| pre, #log { |
| position: absolute; |
| top: 0; |
| left: 200px; |
| } |
| .spacer { |
| height: 700px; |
| } |
| #root { |
| display: inline-block; |
| overflow-y: scroll; |
| height: 200px; |
| border: 3px solid black; |
| } |
| #target { |
| width: 100px; |
| height: 100px; |
| background-color: green; |
| } |
| </style> |
| |
| <div class="spacer"></div> |
| <div id="root"> |
| <div style="height: 300px;"></div> |
| <div id="target"></div> |
| </div> |
| <div class="spacer"></div> |
| |
| <script> |
| var entries = []; |
| var root, target; |
| |
| runTestCycle(function() { |
| assert_equals(window.innerWidth, 800, "Window must be 800 pixels wide."); |
| assert_equals(window.innerHeight, 600, "Window must be 600 pixels high."); |
| |
| target = document.getElementById("target"); |
| assert_true(!!target, "target exists"); |
| root = document.getElementById("root"); |
| assert_true(!!root, "root exists"); |
| var observer = new IntersectionObserver(function(changes) { |
| entries = entries.concat(changes) |
| }, { root: root }); |
| observer.observe(target); |
| entries = entries.concat(observer.takeRecords()); |
| assert_equals(entries.length, 0, "No initial notifications."); |
| runTestCycle(step0, "First rAF"); |
| }, "IntersectionObserver in a single document with explicit root."); |
| |
| function step0() { |
| document.scrollingElement.scrollTop = 600; |
| runTestCycle(step1, "document.scrollingElement.scrollTop = 600."); |
| checkLastEntry(entries, 0, [11, 111, 1011, 1111, 0, 0, 0, 0, 11, 111, 711, 911, false]); |
| } |
| |
| function step1() { |
| root.scrollTop = 150; |
| runTestCycle(step2, "root.scrollTop = 150 with root scrolled into view."); |
| assert_equals(entries.length, 1, "No notifications after scrolling frame."); |
| } |
| |
| function step2() { |
| document.scrollingElement.scrollTop = 0; |
| runTestCycle(step3, "document.scrollingElement.scrollTop = 0."); |
| checkLastEntry(entries, 1, [11, 111, 261, 361, 11, 111, 261, 311, 11, 111, 111, 311, true]); |
| } |
| |
| function step3() { |
| root.scrollTop = 0; |
| runTestCycle(step4, "root.scrollTop = 0"); |
| checkLastEntry(entries, 1); |
| } |
| |
| function step4() { |
| root.scrollTop = 150; |
| runTestCycle(step5, "root.scrollTop = 150 with root scrolled out of view."); |
| checkLastEntry(entries, 2, [11, 111, 1011, 1111, 0, 0, 0, 0, 11, 111, 711, 911, false]); |
| } |
| |
| // This tests that notifications are generated even when the root element is off screen. |
| function step5() { |
| checkLastEntry(entries, 3, [11, 111, 861, 961, 11, 111, 861, 911, 11, 111, 711, 911, true]); |
| } |
| </script> |