| Tobias Schneider | 9a6600e | 2017-06-28 17:46:45 | [diff] [blame] | 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 | iframe { |
| 13 | width: 180px; |
| 14 | height: 100px; |
| 15 | } |
| 16 | </style> |
| 17 | |
| Ali Juma | 69f77c2 | 2018-07-17 21:31:43 | [diff] [blame] | 18 | <iframe id="iframe" srcdoc="<div id='target' style='margin:0.5px;width:1000px;height:1000px;'></div>"></iframe> |
| Tobias Schneider | 9a6600e | 2017-06-28 17:46:45 | [diff] [blame] | 19 | |
| 20 | <script> |
| 21 | var target; |
| 22 | var entries = []; |
| 23 | var observer; |
| 24 | var iframe = document.getElementById("iframe"); |
| 25 | |
| 26 | iframe.onload = function() { |
| 27 | runTestCycle(function() { |
| 28 | target = iframe.contentDocument.getElementById("target"); |
| 29 | assert_true(!!target, "Target element exists."); |
| 30 | observer = new IntersectionObserver(function(changes) { |
| 31 | entries = entries.concat(changes); |
| 32 | }); |
| 33 | observer.observe(target); |
| 34 | entries = entries.concat(observer.takeRecords()); |
| 35 | assert_equals(entries.length, 0, "No initial notifications."); |
| 36 | runTestCycle(test0, "First rAF should generate notification."); |
| 37 | }, "IntersectionObserverEntry.boundingClientRect should match target.boundingClientRect()"); |
| 38 | }; |
| 39 | |
| 40 | function test0() { |
| 41 | assert_equals(entries.length, 1, "One notification."); |
| 42 | var bcr = target.getBoundingClientRect(); |
| 43 | checkLastEntry(entries, 0, [bcr.left, bcr.right, bcr.top, bcr.bottom]); |
| 44 | } |
| 45 | </script> |