| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../resources/js-test.js"></script> | 2 <script src="../resources/js-test.js"></script> |
| 3 <script src="helper-functions.js"></script> | 3 <script src="../resources/intersection-observer-helper-functions.js"></script> |
| 4 <div id="beforeFrame" style="width:100%; height:700px;"></div> | 4 <div id="beforeFrame" style="width:100%; height:700px;"></div> |
| 5 <div id="afterFrame" style="width:100%; height:700px;"></div> | 5 <div id="afterFrame" style="width:100%; height:700px;"></div> |
| 6 | 6 |
| 7 <script> | 7 <script> |
| 8 description("Test that intersection observer time is relative to time in the cal
lback context."); | 8 description("Test that intersection observer time is relative to time in the cal
lback context."); |
| 9 var topWindowEntries = []; | 9 var topWindowEntries = []; |
| 10 var iframeWindowEntries = []; | 10 var iframeWindowEntries = []; |
| 11 var topWindowObserver; | 11 var topWindowObserver; |
| 12 var iframeWindowObserver; | 12 var iframeWindowObserver; |
| 13 var targetIframe; | 13 var targetIframe; |
| 14 var iframeScroller; | 14 var iframeScroller; |
| 15 var topWindowTime; | 15 var topWindowTime; |
| 16 var iframeWindowTime; | 16 var iframeWindowTime; |
| 17 // TODO(szager): We should be able to use a much smaller value for timestampTole
rance | 17 var timestampTolerance = 24; |
| 18 // by using testRunner.runIdleTasks after this patch lands: | |
| 19 // https://codereview.chromium.org/1806133002/ | |
| 20 var timestampTolerance = 124; // ~= 100ms idle callback timeout + 1.5 * frame t
ime | |
| 21 | 18 |
| 22 function step0() { | 19 function step0() { |
| 23 // Test results are only significant if there's a sufficient gap between | 20 // Test results are only significant if there's a sufficient gap between |
| 24 // top window time and iframe window time. | 21 // top window time and iframe window time. |
| 25 topWindowTime = performance.now(); | 22 topWindowTime = performance.now(); |
| 26 iframeWindowTime = targetIframe.contentWindow.performance.now(); | 23 iframeWindowTime = targetIframe.contentWindow.performance.now(); |
| 27 shouldBeGreaterThan("topWindowTime - iframeWindowTime", "2.5 * timestampTolera
nce"); | 24 shouldBeGreaterThan("topWindowTime - iframeWindowTime", "2.5 * timestampTolera
nce"); |
| 28 | 25 |
| 29 topWindowEntries = topWindowEntries.concat(topWindowObserver.takeRecords()); | |
| 30 iframeWindowEntries = iframeWindowEntries.concat(iframeWindowObserver.takeReco
rds()); | |
| 31 shouldBeEqualToNumber("topWindowEntries.length", 0); | 26 shouldBeEqualToNumber("topWindowEntries.length", 0); |
| 32 shouldBeEqualToNumber("iframeWindowEntries.length", 0); | 27 shouldBeEqualToNumber("iframeWindowEntries.length", 0); |
| 33 document.scrollingElement.scrollTop = 200; | 28 document.scrollingElement.scrollTop = 200; |
| 34 iframeScroller.scrollTop = 250; | 29 iframeScroller.scrollTop = 250; |
| 35 requestAnimationFrame(step1); | 30 waitForNotification(step1); |
| 36 } | 31 } |
| 37 | 32 |
| 38 function step1() { | 33 function step1() { |
| 39 topWindowEntries = topWindowEntries.concat(topWindowObserver.takeRecords()); | |
| 40 iframeWindowEntries = iframeWindowEntries.concat(iframeWindowObserver.takeReco
rds()); | |
| 41 topWindowTime = performance.now(); | 34 topWindowTime = performance.now(); |
| 42 iframeWindowTime = targetIframe.contentWindow.performance.now(); | 35 iframeWindowTime = targetIframe.contentWindow.performance.now(); |
| 43 shouldBeEqualToNumber("topWindowEntries.length", 1); | 36 shouldBeEqualToNumber("topWindowEntries.length", 1); |
| 44 if (topWindowEntries.length) | 37 if (topWindowEntries.length) |
| 45 shouldBeCloseTo("topWindowEntries[0].time", "topWindowTime", timestampTolera
nce); | 38 shouldBeCloseTo("topWindowEntries[0].time", "topWindowTime", timestampTolera
nce); |
| 46 | 39 |
| 47 shouldBeEqualToNumber("iframeWindowEntries.length", 1); | 40 shouldBeEqualToNumber("iframeWindowEntries.length", 1); |
| 48 if (iframeWindowEntries.length) { | 41 if (iframeWindowEntries.length) { |
| 49 shouldBeCloseTo("iframeWindowEntries[0].time", "iframeWindowTime", timestamp
Tolerance); | 42 shouldBeCloseTo("iframeWindowEntries[0].time", "iframeWindowTime", timestamp
Tolerance); |
| 50 } | 43 } |
| 51 finishJSTest(); | 44 waitForNotification(finishJSTest); |
| 52 document.scrollingElement.scrollTop = 0; | 45 document.scrollingElement.scrollTop = 0; |
| 53 } | 46 } |
| 54 | 47 |
| 55 function runTest() { | 48 function runTest() { |
| 56 var target = targetIframe.contentDocument.getElementById("target"); | 49 var target = targetIframe.contentDocument.getElementById("target"); |
| 57 iframeScroller = targetIframe.contentDocument.scrollingElement; | 50 iframeScroller = targetIframe.contentDocument.scrollingElement; |
| 58 | 51 |
| 59 // Observer created here, callback created in iframe context. Timestamps shou
ld be | 52 // Observer created here, callback created in iframe context. Timestamps shou
ld be |
| 60 // from this window. | 53 // from this window. |
| 61 topWindowObserver = new IntersectionObserver(targetIframe.contentDocument.crea
teObserverCallback(topWindowEntries), {}); | 54 topWindowObserver = new IntersectionObserver(targetIframe.contentDocument.crea
teObserverCallback(topWindowEntries), {}); |
| 62 topWindowObserver.observe(target); | 55 topWindowObserver.observe(target); |
| 63 | 56 |
| 64 // Callback created here, observer created in iframe. Timestamps should be | 57 // Callback created here, observer created in iframe. Timestamps should be |
| 65 // from iframe window. | 58 // from iframe window. |
| 66 iframeWindowObserver = targetIframe.contentDocument.createObserver(function(ne
wEntries) { | 59 iframeWindowObserver = targetIframe.contentDocument.createObserver(function(ne
wEntries) { |
| 67 for (var i = 0; i < newEntries.length; i++) | 60 for (var i = 0; i < newEntries.length; i++) |
| 68 iframeWindowEntries.push(newEntries[i]); | 61 iframeWindowEntries.push(newEntries[i]); |
| 69 }); | 62 }); |
| 70 iframeWindowObserver.observe(target); | 63 iframeWindowObserver.observe(target); |
| 71 | 64 |
| 72 // See README for explanation of double RAF. | 65 waitForNotification(step0); |
| 73 requestAnimationFrame(() => { requestAnimationFrame(step0) }); | |
| 74 } | 66 } |
| 75 | 67 |
| 76 onload = function() { | 68 onload = function() { |
| 77 setTimeout(function() { | 69 setTimeout(function() { |
| 78 targetIframe = document.createElement("iframe"); | 70 targetIframe = document.createElement("iframe"); |
| 79 targetIframe.src = "../resources/intersection-observer-timestamp-subframe.ht
ml"; | 71 targetIframe.src = "../resources/intersection-observer-timestamp-subframe.ht
ml"; |
| 80 targetIframe.style = "height: 100px; overflow-y: scroll"; | 72 targetIframe.style = "height: 100px; overflow-y: scroll"; |
| 81 var afterFrame = document.getElementById("afterFrame"); | 73 var afterFrame = document.getElementById("afterFrame"); |
| 82 afterFrame.parentNode.insertBefore(targetIframe, afterFrame); | 74 afterFrame.parentNode.insertBefore(targetIframe, afterFrame); |
| 83 targetIframe.onload = runTest; | 75 targetIframe.onload = runTest; |
| 84 }, 2.5 * timestampTolerance); | 76 }, 2.5 * timestampTolerance); |
| 85 }; | 77 }; |
| 86 | 78 |
| 87 </script> | 79 </script> |
| OLD | NEW |