Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <script src="../resources/js-test.js"></script> | |
| 3 <script src="helper-functions.js"></script> | |
| 4 <div id="beforeFrame" style="width:100%; height:700px;"></div> | |
| 5 <div id="afterFrame" style="width:100%; height:700px;"></div> | |
| 6 | |
| 7 <script> | |
| 8 description("Test that intersection observer time is relative to time in the cal lback context."); | |
| 9 var topWindowEntries = []; | |
| 10 var iframeWindowEntries = []; | |
| 11 var targetIframe; | |
| 12 var iframeScroller; | |
| 13 var topWindowTime; | |
| 14 var iframeWindowTime; | |
| 15 var timestampTolerance = 24; // 1.5 times frame duration. | |
| 16 | |
| 17 function step0() { | |
| 18 setTimeout(function() { | |
|
ojan
2016/02/03 01:46:28
Why do you need the setTimeout?
szager1
2016/02/03 01:54:45
The setTimeout's are to allow the IO notifications
| |
| 19 // Test results are only significant if there's a sufficient gap between | |
| 20 // top window time and iframe window time. | |
| 21 topWindowTime = performance.now(); | |
| 22 iframeWindowTime = targetIframe.contentWindow.performance.now(); | |
| 23 shouldBeGreaterThan("topWindowTime - iframeWindowTime", "2 * timestampTolera nce"); | |
| 24 | |
| 25 shouldBeEqualToNumber("topWindowEntries.length", 0); | |
| 26 shouldBeEqualToNumber("iframeWindowEntries.length", 0); | |
| 27 document.scrollingElement.scrollTop = 200; | |
| 28 iframeScroller.scrollTop = 250; | |
| 29 requestAnimationFrame(step1); | |
| 30 }); | |
| 31 } | |
| 32 | |
| 33 function step1() { | |
| 34 setTimeout(function() { | |
|
ojan
2016/02/03 01:46:28
Ditto.
| |
| 35 topWindowTime = performance.now(); | |
| 36 iframeWindowTime = targetIframe.contentWindow.performance.now(); | |
| 37 shouldBeEqualToNumber("topWindowEntries.length", 1); | |
| 38 if (topWindowEntries.length) { | |
| 39 shouldBeCloseTo("topWindowEntries[0].time", "topWindowTime", timestampTole rance); | |
| 40 } | |
| 41 shouldBeEqualToNumber("iframeWindowEntries.length", 1); | |
| 42 if (iframeWindowEntries.length) { | |
| 43 shouldBeCloseTo("iframeWindowEntries[0].time", "iframeWindowTime", timesta mpTolerance); | |
| 44 } | |
| 45 finishTest(); | |
| 46 document.scrollingElement.scrollTop = 0; | |
| 47 }); | |
| 48 } | |
| 49 | |
| 50 function runTest() { | |
| 51 var target = targetIframe.contentDocument.getElementById("target"); | |
| 52 iframeScroller = targetIframe.contentDocument.scrollingElement; | |
| 53 | |
| 54 // Observer created here, callback created in iframe context. Timestamps shou ld be | |
| 55 // from this window. | |
| 56 var observer = new IntersectionObserver(targetIframe.contentDocument.createObs erverCallback(topWindowEntries), {}); | |
| 57 observer.observe(target); | |
| 58 | |
| 59 // Callback created here, observer created in iframe. Timestamps should be | |
| 60 // from iframe window. | |
| 61 observer = targetIframe.contentDocument.createObserver(function(newEntries) { | |
| 62 for (var i = 0; i < newEntries.length; i++) | |
| 63 iframeWindowEntries.push(newEntries[i]); | |
| 64 }); | |
| 65 observer.observe(target); | |
| 66 | |
| 67 step0(); | |
| 68 } | |
| 69 | |
| 70 window.onload = function() { | |
| 71 setTimeout(function() { | |
| 72 targetIframe = document.createElement("iframe"); | |
| 73 targetIframe.src = "../resources/intersection-observer-timestamp-subframe.ht ml"; | |
| 74 targetIframe.style = "height: 100px; overflow-y: scroll"; | |
| 75 var afterFrame = document.getElementById("afterFrame"); | |
| 76 afterFrame.parentNode.insertBefore(targetIframe, afterFrame); | |
| 77 targetIframe.onload = runTest; | |
| 78 }, 100); | |
| 79 }; | |
| 80 | |
| 81 </script> | |
| OLD | NEW |