blob: 645b7ec1908cc2788c8196786537ec5a4f305f88 [file] [log] [blame]
Xiaoming Shi73dfa202020-03-12 11:31:35 -07001<!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<script>
8var entries = [];
9var popup, target;
10
11function waitForPopupNotification(f) {
12 popup.requestAnimationFrame(function() {
13 popup.requestAnimationFrame(function() { popup.setTimeout(f); });
14 });
15}
16
17async_test((t) => {
18 var observer = new IntersectionObserver(function(changes) {
19 entries = entries.concat(changes);
20 });
21 popup = window.open();
22 t.add_cleanup(() => popup.close());
23 target = popup.document.createElement('div');
24 target.style.width = "100px";
25 target.style.height = "100px";
26 observer.observe(target);
27 waitForPopupNotification(t.step_func(() => {
28 assert_equals(entries.length, 1, "Initial notification for detached target.");
29 assert_equals(entries[0].isIntersecting, false, "not intersecting");
30 popup.document.body.appendChild(target);
31 waitForPopupNotification(t.step_func_done(() => {
32 assert_equals(entries.length, 2, "Notification after insertion into popup.");
33 assert_equals(entries[1].isIntersecting, true, "intersecting");
34 }));
35 }));
36}, "IntersectionObserver with target in a different window.");
37</script>