| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="/js-test-resources/intersection-observer-helper-functions.js"></scr
ipt> | 2 <script src="./intersection-observer-test-utils.js"></script> |
| 3 |
| 3 <div style="height: 200px; width: 100px;"></div> | 4 <div style="height: 200px; width: 100px;"></div> |
| 4 <div id="target" style="background-color: green; width:100px; height:100px"></di
v> | 5 <div id="target" style="background-color: green; width:100px; height:100px"></di
v> |
| 5 <div style="height: 200px; width: 100px;"></div> | 6 <div style="height: 200px; width: 100px;"></div> |
| 7 |
| 6 <script> | 8 <script> |
| 7 var port; | 9 var port; |
| 8 var entries = []; | 10 var entries = []; |
| 9 var target = document.getElementById('target'); | 11 var target = document.getElementById('target'); |
| 10 var scroller = document.scrollingElement; | 12 var scroller = document.scrollingElement; |
| 11 var nextStep; | 13 var nextStep; |
| 12 | 14 |
| 13 // Note that we never use RAF in this code, because this frame might get render-
throttled. | 15 // Note that we never use RAF in this code, because this frame might get render-
throttled. |
| 14 // Instead of RAF-ing, we just post an empty message to the parent window, which
will | 16 // Instead of RAF-ing, we just post an empty message to the parent window, which
will |
| 15 // RAF when it is received, and then send us a message to cause the next step to
run. | 17 // RAF when it is received, and then send us a message to cause the next step to
run. |
| 16 | 18 |
| 17 // Use a rootMargin here, and verify it does NOT get applied for the cross-origi
n case. | 19 // Use a rootMargin here, and verify it does NOT get applied for the cross-origi
n case. |
| 18 var observer = new IntersectionObserver( | 20 var observer = new IntersectionObserver(function(changes) { |
| 19 changes => { entries = entries.concat(changes) }, | 21 entries = entries.concat(changes) |
| 20 { rootMargin: "7px" } | 22 }, { rootMargin: "7px" }); |
| 21 ); | |
| 22 observer.observe(target); | 23 observer.observe(target); |
| 23 | 24 |
| 24 function step0() { | 25 function step0() { |
| 25 entries = entries.concat(observer.takeRecords()); | 26 entries = entries.concat(observer.takeRecords()); |
| 26 nextStep = step1; | 27 nextStep = step1; |
| 27 port.postMessage({actual: entries.map(entryToJson), expected: []}, "*"); | 28 port.postMessage({ |
| 29 actual: entries.map(entryToJson), |
| 30 expected: [], |
| 31 description: "First rAF" |
| 32 }, "*"); |
| 28 entries = []; | 33 entries = []; |
| 29 port.postMessage({scrollTo: 200}, "*"); | 34 port.postMessage({scrollTo: 200}, "*"); |
| 30 } | 35 } |
| 31 | 36 |
| 32 function step1() { | 37 function step1() { |
| 33 entries = entries.concat(observer.takeRecords()); | 38 entries = entries.concat(observer.takeRecords()); |
| 34 port.postMessage({actual: entries.map(entryToJson), expected: []}, "*"); | 39 port.postMessage({ |
| 40 actual: entries.map(entryToJson), |
| 41 expected: [], |
| 42 description: "topDocument.scrollingElement.scrollTop = 200" |
| 43 }, "*"); |
| 35 entries = []; | 44 entries = []; |
| 36 scroller.scrollTop = 250; | 45 scroller.scrollTop = 250; |
| 37 nextStep = step2; | 46 nextStep = step2; |
| 38 port.postMessage({}, "*"); | 47 port.postMessage({}, "*"); |
| 39 } | 48 } |
| 40 | 49 |
| 41 function step2() { | 50 function step2() { |
| 42 entries = entries.concat(observer.takeRecords()); | 51 entries = entries.concat(observer.takeRecords()); |
| 43 var expected = [{ | 52 var expected = [{ |
| 44 boundingClientRect: coordinatesToClientRectJson(-42, 108, 58, 8), | 53 boundingClientRect: coordinatesToClientRectJson(-42, 108, 58, 8), |
| 45 intersectionRect: coordinatesToClientRectJson(0, 108, 58, 8), | 54 intersectionRect: coordinatesToClientRectJson(0, 108, 58, 8), |
| 46 rootBounds: "null", | 55 rootBounds: "null", |
| 47 target: target.id | 56 target: target.id |
| 48 }]; | 57 }]; |
| 49 port.postMessage({actual: entries.map(entryToJson), expected: expected}, "*"); | 58 port.postMessage({ |
| 59 actual: entries.map(entryToJson), |
| 60 expected: expected, |
| 61 description: "iframeDocument.scrollingElement.scrollTop = 250" |
| 62 }, "*"); |
| 50 entries = []; | 63 entries = []; |
| 51 nextStep = step3; | 64 nextStep = step3; |
| 52 port.postMessage({scrollTo: 100}, "*"); | 65 port.postMessage({scrollTo: 100}, "*"); |
| 53 } | 66 } |
| 54 | 67 |
| 55 function step3() { | 68 function step3() { |
| 56 entries = entries.concat(observer.takeRecords()); | 69 entries = entries.concat(observer.takeRecords()); |
| 57 var expected = [{ | 70 var expected = [{ |
| 58 boundingClientRect: coordinatesToClientRectJson(-42, 108, 58, 8), | 71 boundingClientRect: coordinatesToClientRectJson(-42, 108, 58, 8), |
| 59 intersectionRect: coordinatesToClientRectJson(0, 0, 0, 0), | 72 intersectionRect: coordinatesToClientRectJson(0, 0, 0, 0), |
| 60 rootBounds: "null", | 73 rootBounds: "null", |
| 61 target: target.id | 74 target: target.id |
| 62 }]; | 75 }]; |
| 63 port.postMessage({actual: entries.map(entryToJson), expected: expected}, "*"); | 76 port.postMessage({ |
| 77 actual: entries.map(entryToJson), |
| 78 expected: expected, |
| 79 description: "topDocument.scrollingElement.scrollTop = 100" |
| 80 }, "*"); |
| 64 port.postMessage({DONE: 1}, "*"); | 81 port.postMessage({DONE: 1}, "*"); |
| 65 } | 82 } |
| 66 | 83 |
| 67 function handleMessage(event) | 84 function handleMessage(event) |
| 68 { | 85 { |
| 69 port = event.source; | 86 port = event.source; |
| 70 nextStep(); | 87 nextStep(); |
| 71 } | 88 } |
| 72 | 89 |
| 73 nextStep = step0; | 90 nextStep = step0; |
| 74 window.addEventListener("message", handleMessage); | 91 window.addEventListener("message", handleMessage); |
| 75 </script> | 92 </script> |
| OLD | NEW |