target-in-different-window.html (1512B)
1 <!DOCTYPE html> 2 <meta name="viewport" content="width=device-width,initial-scale=1"> 3 <!-- 4 NOTE(emilio): This tests Chrome's behavior but it's not clear that's what the 5 spec asks for, see https://github.com/w3c/IntersectionObserver/issues/456 6 --> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="./resources/intersection-observer-test-utils.js"></script> 10 11 <script> 12 var entries = []; 13 var popup, target; 14 15 function waitForPopupNotification(f) { 16 popup.requestAnimationFrame(function() { 17 popup.requestAnimationFrame(function() { popup.setTimeout(f); }); 18 }); 19 } 20 21 async_test((t) => { 22 var observer = new IntersectionObserver(function(changes) { 23 entries = entries.concat(changes); 24 }); 25 popup = window.open(); 26 t.add_cleanup(() => popup.close()); 27 target = popup.document.createElement('div'); 28 target.style.width = "100px"; 29 target.style.height = "100px"; 30 observer.observe(target); 31 waitForPopupNotification(t.step_func(() => { 32 assert_equals(entries.length, 1, "Initial notification for detached target."); 33 assert_equals(entries[0].isIntersecting, false, "not intersecting"); 34 popup.document.body.appendChild(target); 35 waitForPopupNotification(t.step_func_done(() => { 36 assert_equals(entries.length, 2, "Notification after insertion into popup."); 37 assert_equals(entries[1].isIntersecting, true, "intersecting"); 38 })); 39 })); 40 }, "IntersectionObserver with target in a different window."); 41 </script>