Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: third_party/WebKit/LayoutTests/intersection-observer/timestamp.html

Issue 1806133002: IntersectionObserver: use an idle callback to send notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: typo Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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="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;
12 var iframeWindowObserver;
11 var targetIframe; 13 var targetIframe;
12 var iframeScroller; 14 var iframeScroller;
13 var topWindowTime; 15 var topWindowTime;
14 var iframeWindowTime; 16 var iframeWindowTime;
15 var timestampTolerance = 24; // 1.5 times frame duration. 17 // TODO(szager): We should be able to use a much smaller value for timestampTole rance.
18 // Currently, when running in the layout test framework, IntersectionObserver no tifications
19 // are sent as late as possible (when the 100ms idle callback timeout expires), due to
20 // this bug:
21 // https://bugs.chromium.org/p/chromium/issues/detail?id=595152
22 var timestampTolerance = 124; // ~= 100ms idle callback timeout + 1.5 * frame t ime
16 23
17 function step0() { 24 function step0() {
18 setTimeout(function() { 25 // Test results are only significant if there's a sufficient gap between
19 // Test results are only significant if there's a sufficient gap between 26 // top window time and iframe window time.
20 // top window time and iframe window time. 27 topWindowTime = performance.now();
21 topWindowTime = performance.now(); 28 iframeWindowTime = targetIframe.contentWindow.performance.now();
22 iframeWindowTime = targetIframe.contentWindow.performance.now(); 29 shouldBeGreaterThan("topWindowTime - iframeWindowTime", "2.5 * timestampTolera nce");
23 shouldBeGreaterThan("topWindowTime - iframeWindowTime", "2 * timestampTolera nce");
24 30
25 shouldBeEqualToNumber("topWindowEntries.length", 0); 31 topWindowEntries = topWindowEntries.concat(topWindowObserver.takeRecords());
26 shouldBeEqualToNumber("iframeWindowEntries.length", 0); 32 iframeWindowEntries = iframeWindowEntries.concat(iframeWindowObserver.takeReco rds());
27 document.scrollingElement.scrollTop = 200; 33 shouldBeEqualToNumber("topWindowEntries.length", 0);
28 iframeScroller.scrollTop = 250; 34 shouldBeEqualToNumber("iframeWindowEntries.length", 0);
29 requestAnimationFrame(step1); 35 document.scrollingElement.scrollTop = 200;
30 }); 36 iframeScroller.scrollTop = 250;
37 requestAnimationFrame(step1);
31 } 38 }
32 39
33 function step1() { 40 function step1() {
34 setTimeout(function() { 41 topWindowEntries = topWindowEntries.concat(topWindowObserver.takeRecords());
35 topWindowTime = performance.now(); 42 iframeWindowEntries = iframeWindowEntries.concat(iframeWindowObserver.takeReco rds());
36 iframeWindowTime = targetIframe.contentWindow.performance.now(); 43 topWindowTime = performance.now();
37 shouldBeEqualToNumber("topWindowEntries.length", 1); 44 iframeWindowTime = targetIframe.contentWindow.performance.now();
38 if (topWindowEntries.length) { 45 shouldBeEqualToNumber("topWindowEntries.length", 1);
39 shouldBeCloseTo("topWindowEntries[0].time", "topWindowTime", timestampTole rance); 46 if (topWindowEntries.length)
40 } 47 shouldBeCloseTo("topWindowEntries[0].time", "topWindowTime", timestampTolera nce);
41 shouldBeEqualToNumber("iframeWindowEntries.length", 1); 48
42 if (iframeWindowEntries.length) { 49 shouldBeEqualToNumber("iframeWindowEntries.length", 1);
43 shouldBeCloseTo("iframeWindowEntries[0].time", "iframeWindowTime", timesta mpTolerance); 50 if (iframeWindowEntries.length) {
44 } 51 shouldBeCloseTo("iframeWindowEntries[0].time", "iframeWindowTime", timestamp Tolerance);
45 finishJSTest(); 52 }
46 document.scrollingElement.scrollTop = 0; 53 // See README for explanation of this requestIdleCallback.
47 }); 54 requestIdleCallback(finishJSTest, {timeout: 100});
55 document.scrollingElement.scrollTop = 0;
48 } 56 }
49 57
50 function runTest() { 58 function runTest() {
51 var target = targetIframe.contentDocument.getElementById("target"); 59 var target = targetIframe.contentDocument.getElementById("target");
52 iframeScroller = targetIframe.contentDocument.scrollingElement; 60 iframeScroller = targetIframe.contentDocument.scrollingElement;
53 61
54 // Observer created here, callback created in iframe context. Timestamps shou ld be 62 // Observer created here, callback created in iframe context. Timestamps shou ld be
55 // from this window. 63 // from this window.
56 var observer = new IntersectionObserver(targetIframe.contentDocument.createObs erverCallback(topWindowEntries), {}); 64 topWindowObserver = new IntersectionObserver(targetIframe.contentDocument.crea teObserverCallback(topWindowEntries), {});
57 observer.observe(target); 65 topWindowObserver.observe(target);
58 66
59 // Callback created here, observer created in iframe. Timestamps should be 67 // Callback created here, observer created in iframe. Timestamps should be
60 // from iframe window. 68 // from iframe window.
61 observer = targetIframe.contentDocument.createObserver(function(newEntries) { 69 iframeWindowObserver = targetIframe.contentDocument.createObserver(function(ne wEntries) {
62 for (var i = 0; i < newEntries.length; i++) 70 for (var i = 0; i < newEntries.length; i++)
63 iframeWindowEntries.push(newEntries[i]); 71 iframeWindowEntries.push(newEntries[i]);
64 }); 72 });
65 observer.observe(target); 73 iframeWindowObserver.observe(target);
66 74
67 step0(); 75 // See README for explanation of double RAF.
76 requestAnimationFrame(() => { requestAnimationFrame(step0) });
68 } 77 }
69 78
70 window.onload = function() { 79 onload = function() {
71 setTimeout(function() { 80 setTimeout(function() {
72 targetIframe = document.createElement("iframe"); 81 targetIframe = document.createElement("iframe");
73 targetIframe.src = "../resources/intersection-observer-timestamp-subframe.ht ml"; 82 targetIframe.src = "../resources/intersection-observer-timestamp-subframe.ht ml";
74 targetIframe.style = "height: 100px; overflow-y: scroll"; 83 targetIframe.style = "height: 100px; overflow-y: scroll";
75 var afterFrame = document.getElementById("afterFrame"); 84 var afterFrame = document.getElementById("afterFrame");
76 afterFrame.parentNode.insertBefore(targetIframe, afterFrame); 85 afterFrame.parentNode.insertBefore(targetIframe, afterFrame);
77 targetIframe.onload = runTest; 86 targetIframe.onload = runTest;
78 }, 100); 87 }, 2.5 * timestampTolerance);
79 }; 88 };
80 89
81 </script> 90 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698