| 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 <style> | 5 <style> |
| 5 #root { | 6 #root { |
| 6 overflow: visible; | 7 overflow: visible; |
| 7 height: 200px; | 8 height: 200px; |
| 8 width: 200px; | 9 width: 200px; |
| 9 border: 7px solid black; | 10 border: 7px solid black; |
| 10 } | 11 } |
| 11 #target { | 12 #target { |
| 12 width: 100px; | 13 width: 100px; |
| 13 height: 100px; | 14 height: 100px; |
| 14 background-color: green; | 15 background-color: green; |
| 15 } | 16 } |
| 16 </style> | 17 </style> |
| 17 <div id="root"> | 18 <div id="root"> |
| 18 <div id="target" style="transform: translateY(300px)"></div> | 19 <div id="target" style="transform: translateY(300px)"></div> |
| 19 </div> | 20 </div> |
| 20 | 21 |
| 21 <script> | 22 <script> |
| 22 description("Test that border bounding box is used to calculate intersection wit
h a non-scrolling root."); | 23 function waitForNotification(f) { |
| 23 var target = document.getElementById("target"); | 24 requestAnimationFrame(() => { |
| 24 var root = document.getElementById("root"); | 25 setTimeout(() => { |
| 25 var entries = []; | 26 setTimeout(f); |
| 26 var observer = new IntersectionObserver( | 27 }); |
| 27 changes => { entries.push(...changes) }, | 28 }); |
| 28 { root: document.getElementById("root") } | 29 } |
| 29 ); | |
| 30 | 30 |
| 31 onload = function() { | 31 onload = function() { |
| 32 var t = async_test("Test that border bounding box is used to calculate interse
ction with a non-scrolling root."); |
| 33 var root = document.getElementById("root"); |
| 34 var target = document.getElementById("target"); |
| 35 var entries = []; |
| 36 var observer = new IntersectionObserver(function(changes) { |
| 37 entries = entries.concat(changes) |
| 38 }, {root: root}); |
| 32 observer.observe(target); | 39 observer.observe(target); |
| 33 entries.push(...observer.takeRecords()); | 40 entries = entries.concat(observer.takeRecords()); |
| 34 shouldBeEqualToNumber("entries.length", 0); | 41 test(function() { assert_equals(entries.length, 0) }, "No initial notification
s."); |
| 35 waitForNotification(step0); | 42 waitForNotification(step0); |
| 36 } | |
| 37 | 43 |
| 38 function step0() { | 44 function checkEntry(i, expected) { |
| 39 shouldBeEqualToNumber("entries.length", 0); | 45 test(function() { assert_equals(entries.length, i+1) }, String(i+1) + " noti
fication(s)."); |
| 40 target.style.transform = "translateY(195px)"; | 46 if (expected && entries.length > i) { |
| 41 waitForNotification(step1); | 47 test(function() { assert_equals(entries[i].boundingClientRect.left, expect
ed[0]) }, |
| 42 } | 48 "entries[" + i + "].boundingClientRect.left == " + expected[0]); |
| 43 | 49 test(function() { assert_equals(entries[i].boundingClientRect.right, expec
ted[1]) }, |
| 44 function step1() { | 50 "entries[" + i + "].boundingClientRect.right == " + expected[1]); |
| 45 shouldBeEqualToNumber("entries.length", 1); | 51 test(function() { assert_equals(entries[i].boundingClientRect.top, expecte
d[2]) }, |
| 46 if (entries.length > 0) { | 52 "entries[" + i + "].boundingClientRect.top == " + expected[2]); |
| 47 shouldBeEqualToNumber("entries[0].boundingClientRect.left", 15); | 53 test(function() { assert_equals(entries[i].boundingClientRect.bottom, expe
cted[3]) }, |
| 48 shouldBeEqualToNumber("entries[0].boundingClientRect.right", 115); | 54 "entries[" + i + "].boundingClientRect.bottom == " + expected[3]); |
| 49 shouldBeEqualToNumber("entries[0].boundingClientRect.top", 210); | 55 test(function() { assert_equals(entries[i].intersectionRect.left, expected
[4]) }, |
| 50 shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 310); | 56 "entries[" + i + "].intersectionRect.left == " + expected[4]); |
| 51 shouldBeEqualToNumber("entries[0].intersectionRect.left", 15); | 57 test(function() { assert_equals(entries[i].intersectionRect.right, expecte
d[5]) }, |
| 52 shouldBeEqualToNumber("entries[0].intersectionRect.right", 115); | 58 "entries[" + i + "].intersectionRect.right == " + expected[5]); |
| 53 shouldBeEqualToNumber("entries[0].intersectionRect.top", 210); | 59 test(function() { assert_equals(entries[i].intersectionRect.top, expected[
6]) }, |
| 54 shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 222); | 60 "entries[" + i + "].intersectionRect.top == " + expected[6]); |
| 55 shouldBeEqualToNumber("entries[0].rootBounds.left", 8); | 61 test(function() { assert_equals(entries[i].intersectionRect.bottom, expect
ed[7]) }, |
| 56 shouldBeEqualToNumber("entries[0].rootBounds.right", 222); | 62 "entries[" + i + "].intersectionRect.bottom == " + expected[7]); |
| 57 shouldBeEqualToNumber("entries[0].rootBounds.top", 8); | 63 test(function() { assert_equals(entries[i].rootBounds.left, expected[8]) }
, |
| 58 shouldBeEqualToNumber("entries[0].rootBounds.bottom", 222); | 64 "entries[" + i + "].rootBounds.left == " + expected[8]); |
| 59 shouldEvaluateToSameObject("entries[0].target", target); | 65 test(function() { assert_equals(entries[i].rootBounds.right, expected[9])
}, |
| 66 "entries[" + i + "].rootBounds.right == " + expected[9]); |
| 67 test(function() { assert_equals(entries[i].rootBounds.top, expected[10]) }
, |
| 68 "entries[" + i + "].rootBounds.top == " + expected[10]); |
| 69 test(function() { assert_equals(entries[i].rootBounds.bottom, expected[11]
) }, |
| 70 "entries[" + i + "].rootBounds.bottom == " + expected[11]); |
| 71 test(function() { assert_true(entries[i].target === expected[12]) }, |
| 72 "entries[" + i + "].target === " + expected[12]); |
| 73 } |
| 60 } | 74 } |
| 61 | 75 |
| 62 finishJSTest(); | 76 function step0() { |
| 63 } | 77 test(function() { assert_equals(entries.length, 0) }, "No notifications afte
r first rAF."); |
| 78 target.style.transform = "translateY(195px)"; |
| 79 waitForNotification(step1); |
| 80 } |
| 81 |
| 82 function step1() { |
| 83 checkEntry(0, [15, 115, 210, 310, 15, 115, 210, 222, 8, 222, 8, 222, target]
); |
| 84 target.style.transform = ""; |
| 85 t.done(); |
| 86 } |
| 87 }; |
| 64 </script> | 88 </script> |
| OLD | NEW |