OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../resources/testharness.js"></script> |
| 3 <script src="../resources/testharnessreport.js"></script> |
| 4 |
| 5 <style> |
| 6 iframe { |
| 7 height: 100px; |
| 8 overflow-y: scroll; |
| 9 } |
| 10 </style> |
| 11 |
| 12 <div id="leading-space" style="width:100%; height:700px;"></div> |
| 13 <iframe src="resources/cross-origin-subframe.html" sandbox="allow-scripts"></ifr
ame> |
| 14 <div id="trailing-space" style="width:100%; height:700px;"></div> |
| 15 |
| 16 <script> |
| 17 function waitForNotification(f) { |
| 18 requestAnimationFrame(() => { |
| 19 setTimeout(() => { |
| 20 setTimeout(f); |
| 21 }); |
| 22 }); |
| 23 } |
| 24 |
| 25 function checkEntries(actual, expected) { |
| 26 test(function() { assert_equals(actual.length, expected.length) }, String(actu
al.length) + " notification(s)."); |
| 27 for (var i = 0; i < actual.length && i < expected.length; i++) { |
| 28 test(function() { assert_equals(actual[i].boundingClientRect.left, expected[
i].boundingClientRect.left) }, |
| 29 "entries[" + i + "].boundingClientRect.left == " + expected[i].bounding
ClientRect.left); |
| 30 test(function() { assert_equals(actual[i].boundingClientRect.right, expected
[i].boundingClientRect.right) }, |
| 31 "entries[" + i + "].boundingClientRect.right == " + expected[i].boundin
gClientRect.right); |
| 32 test(function() { assert_equals(actual[i].boundingClientRect.top, expected[i
].boundingClientRect.top) }, |
| 33 "entries[" + i + "].boundingClientRect.top == " + expected[i].boundingC
lientRect.top); |
| 34 test(function() { assert_equals(actual[i].boundingClientRect.bottom, expecte
d[i].boundingClientRect.bottom) }, |
| 35 "entries[" + i + "].boundingClientRect.bottom == " + expected[i].boundi
ngClientRect.bottom); |
| 36 test(function() { assert_equals(actual[i].intersectionRect.left, expected[i]
.intersectionRect.left) }, |
| 37 "entries[" + i + "].intersectionRect.left == " + expected[i].intersecti
onRect.left); |
| 38 test(function() { assert_equals(actual[i].intersectionRect.right, expected[i
].intersectionRect.right) }, |
| 39 "entries[" + i + "].intersectionRect.right == " + expected[i].intersect
ionRect.right); |
| 40 test(function() { assert_equals(actual[i].intersectionRect.top, expected[i].
intersectionRect.top) }, |
| 41 "entries[" + i + "].intersectionRect.top == " + expected[i].intersectio
nRect.top); |
| 42 test(function() { assert_equals(actual[i].intersectionRect.bottom, expected[
i].intersectionRect.bottom) }, |
| 43 "entries[" + i + "].intersectionRect.bottom == " + expected[i].intersec
tionRect.bottom); |
| 44 if (expected[i].rootBounds == "null") { |
| 45 test(function() { assert_equals(actual[i].rootBounds, null) }, |
| 46 "actual[" + i + "].rootBonds == null"); |
| 47 } else if (actual[i].rootBounds == null) { |
| 48 test(function() { assert_not_equals(actual[i].rootBounds, null) }, |
| 49 "actual[" + i + "].rootBonds != null"); |
| 50 } else { |
| 51 test(function() { assert_equals(actual[i].rootBounds.left, expected[i].roo
tBounds.left) }, |
| 52 "entries[" + i + "].rootBounds.left == " + expected[i].rootBounds.lef
t); |
| 53 test(function() { assert_equals(actual[i].rootBounds.right, expected[i].ro
otBounds.right) }, |
| 54 "entries[" + i + "].rootBounds.right == " + expected[i].rootBounds.ri
ght); |
| 55 test(function() { assert_equals(actual[i].rootBounds.top, expected[i].root
Bounds.top) }, |
| 56 "entries[" + i + "].rootBounds.top == " + expected[i].rootBounds.top)
; |
| 57 test(function() { assert_equals(actual[i].rootBounds.bottom, expected[i].r
ootBounds.bottom) }, |
| 58 "entries[" + i + "].rootBounds.bottom == " + expected[i].rootBounds.b
ottom); |
| 59 } |
| 60 test(function() { assert_equals(actual[i].target, expected[i].target) }, |
| 61 "entries[" + i + "].target.id == " + expected[i].target); |
| 62 } |
| 63 } |
| 64 |
| 65 var iframe = document.querySelector("iframe"); |
| 66 console.log("iframe =" + iframe); |
| 67 iframe.onload = (() => { |
| 68 waitForNotification(() => { iframe.contentWindow.postMessage("", "*") }); |
| 69 }); |
| 70 |
| 71 onload = function() { |
| 72 var t = async_test("Intersection observer test with no explicit root and targe
t in a cross-origin iframe."); |
| 73 |
| 74 test(function() { assert_equals(window.innerWidth, 800) }, "Window must be 800
pixels wide."); |
| 75 test(function() { assert_equals(window.innerHeight, 600) }, "Window must be 60
0 pixels high."); |
| 76 |
| 77 function handleMessage(event) { |
| 78 console.log(event); |
| 79 if (event.data.hasOwnProperty('scrollTo')) { |
| 80 document.scrollingElement.scrollTop = event.data.scrollTo; |
| 81 waitForNotification(() => { iframe.contentWindow.postMessage("", "*") }); |
| 82 } else if (event.data.hasOwnProperty('actual')) { |
| 83 checkEntries(event.data.actual, event.data.expected); |
| 84 } else if (event.data.hasOwnProperty('DONE')) { |
| 85 document.getElementById("leading-space").style.height = ""; |
| 86 document.getElementById("trailing-space").style.height = ""; |
| 87 document.scrollingElement.scrollTop = 0; |
| 88 t.done(); |
| 89 } else { |
| 90 waitForNotification(() => { iframe.contentWindow.postMessage("", "*") }); |
| 91 } |
| 92 } |
| 93 |
| 94 window.addEventListener("message", handleMessage); |
| 95 }; |
| 96 </script> |
OLD | NEW |