Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <meta name="viewport" content="width=device-width,initial-scale=1"> |
| 3 | <script src="/resources/testharness.js"></script> |
| 4 | <script src="/resources/testharnessreport.js"></script> |
| 5 | <script src="./resources/intersection-observer-test-utils.js"></script> |
| 6 | |
| 7 | <style> |
| 8 | pre, #log { |
| 9 | position: absolute; |
| 10 | top: 0; |
| 11 | left: 200px; |
| 12 | } |
| 13 | #target { |
| 14 | width: 0px; |
| 15 | height: 0px; |
| 16 | } |
| 17 | </style> |
| 18 | |
| 19 | <div id='target'></div> |
| 20 | |
| 21 | <script> |
| 22 | var entries = []; |
| 23 | |
| 24 | runTestCycle(function() { |
| 25 | var target = document.getElementById('target'); |
| 26 | assert_true(!!target, "target exists"); |
| 27 | var observer = new IntersectionObserver(function(changes) { |
| 28 | entries = entries.concat(changes) |
| 29 | }); |
| 30 | observer.observe(target); |
| 31 | entries = entries.concat(observer.takeRecords()); |
| 32 | assert_equals(entries.length, 0, "No initial notifications."); |
| 33 | runTestCycle(step0, "First rAF should generate a notification."); |
| 34 | }, "Ensure that a zero-area target intersecting root generates a notification with intersectionRatio == 1"); |
| 35 | |
| 36 | function step0() { |
| 37 | assert_equals(entries.length, 1, "One notification."); |
| 38 | assert_equals(entries[0].intersectionRatio, 1, "intersectionRatio == 1"); |
| 39 | } |
| 40 | </script> |