| <!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; |
| } |
| #target { |
| width: 100px; |
| height: 100px; |
| background-color: green; |
| } |
| </style> |
| |
| <div class="spacer"></div> |
| <div id="target"></div> |
| <div class="spacer"></div> |
| |
| <script> |
| var entries = []; |
| var 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"); |
| var observer = new IntersectionObserver(function(changes) { |
| entries = entries.concat(changes) |
| }, { threshold: [0, 0.25, 0.5, 0.75, 1] }); |
| observer.observe(target); |
| entries = entries.concat(observer.takeRecords()); |
| assert_equals(entries.length, 0, "No initial notifications."); |
| runTestCycle(step0, "First rAF."); |
| }, "Observer with multiple thresholds."); |
| |
| function step0() { |
| document.scrollingElement.scrollTop = 120; |
| runTestCycle(step1, "document.scrollingElement.scrollTop = 120"); |
| checkLastEntry(entries, 0, [8, 108, 708, 808, 0, 0, 0, 0, 0, 785, 0, 600, false]); |
| } |
| |
| function step1() { |
| document.scrollingElement.scrollTop = 160; |
| runTestCycle(step2, "document.scrollingElement.scrollTop = 160"); |
| checkLastEntry(entries, 1, [8, 108, 588, 688, 8, 108, 588, 600, 0, 785, 0, 600, true]); |
| } |
| |
| function step2() { |
| document.scrollingElement.scrollTop = 200; |
| runTestCycle(step3, "document.scrollingElement.scrollTop = 200"); |
| checkLastEntry(entries, 2, [8, 108, 548, 648, 8, 108, 548, 600, 0, 785, 0, 600, true]); |
| } |
| |
| function step3() { |
| document.scrollingElement.scrollTop = 240; |
| runTestCycle(step4, "document.scrollingElement.scrollTop = 240"); |
| checkLastEntry(entries, 3, [8, 108, 508, 608, 8, 108, 508, 600, 0, 785, 0, 600, true]); |
| } |
| |
| function step4() { |
| document.scrollingElement.scrollTop = 740; |
| runTestCycle(step5, "document.scrollingElement.scrollTop = 740"); |
| checkLastEntry(entries, 4, [8, 108, 468, 568, 8, 108, 468, 568, 0, 785, 0, 600, true]); |
| } |
| |
| function step5() { |
| document.scrollingElement.scrollTop = 760; |
| runTestCycle(step6, "document.scrollingElement.scrollTop = 760"); |
| checkLastEntry(entries, 5, [8, 108, -32, 68, 8, 108, 0, 68, 0, 785, 0, 600, true]); |
| } |
| |
| function step6() { |
| document.scrollingElement.scrollTop = 800; |
| runTestCycle(step7, "document.scrollingElement.scrollTop = 800"); |
| checkLastEntry(entries, 6, [8, 108, -52, 48, 8, 108, 0, 48, 0, 785, 0, 600, true]); |
| } |
| |
| function step7() { |
| checkLastEntry(entries, 7, [8, 108, -92, 8, 8, 108, 0, 8, 0, 785, 0, 600, true]); |
| document.scrollingElement.scrollTop = 820; |
| runTestCycle(step8, "document.scrollingElement.scrollTop = 820"); |
| } |
| |
| function step8() { |
| checkLastEntry(entries, 8, [8, 108, -112, -12, 0, 0, 0, 0, 0, 785, 0, 600, false]); |
| document.scrollingElement.scrollTop = 0; |
| } |
| </script> |