LEFT | RIGHT |
(no file at all) | |
| 1 <!DOCTYPE html> |
| 2 <script src="/resources/testharness.js"></script> |
| 3 <script src="/resources/testharnessreport.js"></script> |
| 4 <script src="./resources/intersection-observer-test-utils.js"></script> |
| 5 |
| 6 <style> |
| 7 pre, #log { |
| 8 position: absolute; |
| 9 top: 0; |
| 10 left: 200px; |
| 11 } |
| 12 .spacer { |
| 13 height: calc(100vh + 100px); |
| 14 } |
| 15 </style> |
| 16 |
| 17 <div class="spacer"></div> |
| 18 <br id="target"> |
| 19 <div class="spacer"></div> |
| 20 |
| 21 <script> |
| 22 var vw = document.documentElement.clientWidth; |
| 23 var vh = document.documentElement.clientHeight; |
| 24 |
| 25 var entries = []; |
| 26 var target; |
| 27 var tw, th; |
| 28 |
| 29 runTestCycle(function() { |
| 30 target = document.getElementById("target"); |
| 31 let target_rect = target.getBoundingClientRect(); |
| 32 tw = target_rect.width; |
| 33 th = target_rect.height; |
| 34 assert_true(!!target, "target exists"); |
| 35 var observer = new IntersectionObserver(function(changes) { |
| 36 entries = entries.concat(changes) |
| 37 }); |
| 38 observer.observe(target); |
| 39 entries = entries.concat(observer.takeRecords()); |
| 40 assert_equals(entries.length, 0, "No initial notifications."); |
| 41 runTestCycle(step0, "First rAF."); |
| 42 }, "IntersectionObserver observing a br element."); |
| 43 |
| 44 function step0() { |
| 45 document.scrollingElement.scrollTop = 300; |
| 46 runTestCycle(step1, "document.scrollingElement.scrollTop = 300"); |
| 47 // The numbers in brackets are target client rect; intersection rect; |
| 48 // and root bounds. |
| 49 checkLastEntry(entries, 0, [8, 8 + tw, vh + 108, vh + 108 + th, 0, 0, 0, 0, 0,
vw, 0, vh, false]); |
| 50 } |
| 51 |
| 52 function step1() { |
| 53 document.scrollingElement.scrollTop = 100; |
| 54 runTestCycle(step2, "document.scrollingElement.scrollTop = 100"); |
| 55 checkLastEntry(entries, 1, [8, 8 + tw, vh - 192, vh - 192 + th, 8, 8 + tw, vh
- 192, vh - 192 + th, 0, vw, 0, vh, true]); |
| 56 } |
| 57 |
| 58 function step2() { |
| 59 document.scrollingElement.scrollTop = 0; |
| 60 checkLastEntry(entries, 2, [8, 8 + tw, vh + 8, vh + 8 + th, 0, 0, 0, 0, 0, vw,
0, vh, false]); |
| 61 } |
| 62 </script> |
LEFT | RIGHT |