OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/js-test.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/intersection-observer-helper-functions.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
| 4 |
4 <div id="host"></div> | 5 <div id="host"></div> |
5 | 6 |
6 <script> | 7 <script> |
7 description("Tests that observations can be made across shadow DOM boundaries.")
; | 8 function waitForNotification(f) { |
8 var entries = []; | 9 requestAnimationFrame(() => { |
9 var target; | 10 setTimeout(() => { |
10 var observer = new IntersectionObserver(changes => { entries = entries.concat(ch
anges) }); | 11 setTimeout(f); |
| 12 }); |
| 13 }); |
| 14 } |
11 | 15 |
12 onload = function() { | 16 onload = function() { waitForNotification(function() { |
13 let shadowHost = document.getElementById("host"); | 17 var t = async_test("Tests that observations can be made across shadow DOM boun
daries."); |
14 let shadowRoot = shadowHost.createShadowRoot(); | 18 |
15 target = document.createElement('div'); | 19 test(function() { assert_equals(window.innerWidth, 800) }, "Window must be 800
pixels wide."); |
| 20 test(function() { assert_equals(window.innerHeight, 600) }, "Window must be 60
0 pixels high."); |
| 21 |
| 22 var shadowHost = document.getElementById("host"); |
| 23 var shadowRoot = shadowHost.createShadowRoot(); |
| 24 var target = document.createElement('div'); |
16 target.style.cssText = "background-color: green; width:100px; height:100px"; | 25 target.style.cssText = "background-color: green; width:100px; height:100px"; |
17 shadowRoot.appendChild(target); | 26 shadowRoot.appendChild(target); |
| 27 |
| 28 var entries = []; |
| 29 var observer = new IntersectionObserver(function(changes) { |
| 30 entries = entries.concat(changes) |
| 31 }); |
18 observer.observe(target); | 32 observer.observe(target); |
| 33 entries = entries.concat(observer.takeRecords()); |
| 34 test(function() { assert_equals(entries.length, 0) }, "No initial notification
s."); |
| 35 waitForNotification(step0); |
19 | 36 |
20 entries = entries.concat(observer.takeRecords()); | 37 function checkEntry(i, expected) { |
21 shouldBeEqualToNumber("entries.length", 0); | 38 test(function() { assert_equals(entries.length, i+1) }, String(i+1) + " noti
fication(s)."); |
22 waitForNotification(step1); | 39 if (expected && entries.length > i) { |
23 }; | 40 test(function() { assert_equals(entries[i].boundingClientRect.left, expect
ed[0]) }, |
| 41 "entries[" + i + "].boundingClientRect.left == " + expected[0]); |
| 42 test(function() { assert_equals(entries[i].boundingClientRect.right, expec
ted[1]) }, |
| 43 "entries[" + i + "].boundingClientRect.right == " + expected[1]); |
| 44 test(function() { assert_equals(entries[i].boundingClientRect.top, expecte
d[2]) }, |
| 45 "entries[" + i + "].boundingClientRect.top == " + expected[2]); |
| 46 test(function() { assert_equals(entries[i].boundingClientRect.bottom, expe
cted[3]) }, |
| 47 "entries[" + i + "].boundingClientRect.bottom == " + expected[3]); |
| 48 test(function() { assert_equals(entries[i].intersectionRect.left, expected
[4]) }, |
| 49 "entries[" + i + "].intersectionRect.left == " + expected[4]); |
| 50 test(function() { assert_equals(entries[i].intersectionRect.right, expecte
d[5]) }, |
| 51 "entries[" + i + "].intersectionRect.right == " + expected[5]); |
| 52 test(function() { assert_equals(entries[i].intersectionRect.top, expected[
6]) }, |
| 53 "entries[" + i + "].intersectionRect.top == " + expected[6]); |
| 54 test(function() { assert_equals(entries[i].intersectionRect.bottom, expect
ed[7]) }, |
| 55 "entries[" + i + "].intersectionRect.bottom == " + expected[7]); |
| 56 test(function() { assert_equals(entries[i].rootBounds.left, expected[8]) }
, |
| 57 "entries[" + i + "].rootBounds.left == " + expected[8]); |
| 58 test(function() { assert_equals(entries[i].rootBounds.right, expected[9])
}, |
| 59 "entries[" + i + "].rootBounds.right == " + expected[9]); |
| 60 test(function() { assert_equals(entries[i].rootBounds.top, expected[10]) }
, |
| 61 "entries[" + i + "].rootBounds.top == " + expected[10]); |
| 62 test(function() { assert_equals(entries[i].rootBounds.bottom, expected[11]
) }, |
| 63 "entries[" + i + "].rootBounds.bottom == " + expected[11]); |
| 64 test(function() { assert_true(entries[i].target === expected[12]) }, |
| 65 "entries[" + i + "].target === " + expected[12]); |
| 66 } |
| 67 } |
24 | 68 |
25 function step1() { | 69 function step0() { |
26 shouldBeEqualToNumber("entries.length", 1); | 70 checkEntry(0, [8, 108, 8, 108, 8, 108, 8, 108, 0, 800, 0, 600, target]); |
27 if (entries.length > 0) { | 71 t.done(); |
28 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8); | |
29 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 108); | |
30 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 8); | |
31 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 108); | |
32 shouldBeEqualToNumber("entries[0].intersectionRect.left", 8); | |
33 shouldBeEqualToNumber("entries[0].intersectionRect.right", 108); | |
34 shouldBeEqualToNumber("entries[0].intersectionRect.top", 8); | |
35 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 108); | |
36 shouldBeEqualToNumber("entries[0].rootBounds.left", 0); | |
37 shouldBeEqualToNumber("entries[0].rootBounds.right", 800); | |
38 shouldBeEqualToNumber("entries[0].rootBounds.top", 0); | |
39 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600); | |
40 shouldEvaluateToSameObject("entries[0].target", target); | |
41 } | 72 } |
42 finishJSTest(); | 73 })}; |
43 } | |
44 </script> | 74 </script> |
OLD | NEW |