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

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

Issue 1780163002: Revert of IntersectionObserver: use an idle callback to send notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: 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;
13 var targetIframe; 11 var targetIframe;
14 var iframeScroller; 12 var iframeScroller;
15 var topWindowTime; 13 var topWindowTime;
16 var iframeWindowTime; 14 var iframeWindowTime;
17 var timestampTolerance = 24; // 1.5 times frame duration. 15 var timestampTolerance = 24; // 1.5 times frame duration.
18 16
19 function step0() { 17 function step0() {
20 // Test results are only significant if there's a sufficient gap between 18 setTimeout(function() {
21 // top window time and iframe window time. 19 // Test results are only significant if there's a sufficient gap between
22 topWindowTime = performance.now(); 20 // top window time and iframe window time.
23 iframeWindowTime = targetIframe.contentWindow.performance.now(); 21 topWindowTime = performance.now();
24 shouldBeGreaterThan("topWindowTime - iframeWindowTime", "2 * timestampToleranc e"); 22 iframeWindowTime = targetIframe.contentWindow.performance.now();
23 shouldBeGreaterThan("topWindowTime - iframeWindowTime", "2 * timestampTolera nce");
25 24
26 topWindowEntries = topWindowEntries.concat(topWindowObserver.takeRecords()); 25 shouldBeEqualToNumber("topWindowEntries.length", 0);
27 iframeWindowEntries = iframeWindowEntries.concat(iframeWindowObserver.takeReco rds()); 26 shouldBeEqualToNumber("iframeWindowEntries.length", 0);
28 shouldBeEqualToNumber("topWindowEntries.length", 0); 27 document.scrollingElement.scrollTop = 200;
29 shouldBeEqualToNumber("iframeWindowEntries.length", 0); 28 iframeScroller.scrollTop = 250;
30 document.scrollingElement.scrollTop = 200; 29 requestAnimationFrame(step1);
31 iframeScroller.scrollTop = 250; 30 });
32 requestAnimationFrame(step1);
33 } 31 }
34 32
35 function step1() { 33 function step1() {
36 topWindowEntries = topWindowEntries.concat(topWindowObserver.takeRecords()); 34 setTimeout(function() {
37 iframeWindowEntries = iframeWindowEntries.concat(iframeWindowObserver.takeReco rds()); 35 topWindowTime = performance.now();
38 topWindowTime = performance.now(); 36 iframeWindowTime = targetIframe.contentWindow.performance.now();
39 iframeWindowTime = targetIframe.contentWindow.performance.now(); 37 shouldBeEqualToNumber("topWindowEntries.length", 1);
40 shouldBeEqualToNumber("topWindowEntries.length", 1); 38 if (topWindowEntries.length) {
41 if (topWindowEntries.length) { 39 shouldBeCloseTo("topWindowEntries[0].time", "topWindowTime", timestampTole rance);
42 shouldBeCloseTo("topWindowEntries[0].time", "topWindowTime", timestampTolera nce); 40 }
43 } 41 shouldBeEqualToNumber("iframeWindowEntries.length", 1);
44 shouldBeEqualToNumber("iframeWindowEntries.length", 1); 42 if (iframeWindowEntries.length) {
45 if (iframeWindowEntries.length) { 43 shouldBeCloseTo("iframeWindowEntries[0].time", "iframeWindowTime", timesta mpTolerance);
46 shouldBeCloseTo("iframeWindowEntries[0].time", "iframeWindowTime", timestamp Tolerance); 44 }
47 } 45 finishJSTest();
48 finishJSTest(); 46 document.scrollingElement.scrollTop = 0;
49 document.scrollingElement.scrollTop = 0; 47 });
50 } 48 }
51 49
52 function runTest() { 50 function runTest() {
53 var target = targetIframe.contentDocument.getElementById("target"); 51 var target = targetIframe.contentDocument.getElementById("target");
54 iframeScroller = targetIframe.contentDocument.scrollingElement; 52 iframeScroller = targetIframe.contentDocument.scrollingElement;
55 53
56 // Observer created here, callback created in iframe context. Timestamps shou ld be 54 // Observer created here, callback created in iframe context. Timestamps shou ld be
57 // from this window. 55 // from this window.
58 topWindowObserver = new IntersectionObserver(targetIframe.contentDocument.crea teObserverCallback(topWindowEntries), {}); 56 var observer = new IntersectionObserver(targetIframe.contentDocument.createObs erverCallback(topWindowEntries), {});
59 topWindowObserver.observe(target); 57 observer.observe(target);
60 58
61 // Callback created here, observer created in iframe. Timestamps should be 59 // Callback created here, observer created in iframe. Timestamps should be
62 // from iframe window. 60 // from iframe window.
63 iframeWindowObserver = targetIframe.contentDocument.createObserver(function(ne wEntries) { 61 observer = targetIframe.contentDocument.createObserver(function(newEntries) {
64 for (var i = 0; i < newEntries.length; i++) 62 for (var i = 0; i < newEntries.length; i++)
65 iframeWindowEntries.push(newEntries[i]); 63 iframeWindowEntries.push(newEntries[i]);
66 }); 64 });
67 iframeWindowObserver.observe(target); 65 observer.observe(target);
68 66
69 // See README for explanation of double RAF. 67 step0();
70 requestAnimationFrame(() => { requestAnimationFrame(step0) });
71 } 68 }
72 69
73 window.onload = function() { 70 window.onload = function() {
74 setTimeout(function() { 71 setTimeout(function() {
75 targetIframe = document.createElement("iframe"); 72 targetIframe = document.createElement("iframe");
76 targetIframe.src = "../resources/intersection-observer-timestamp-subframe.ht ml"; 73 targetIframe.src = "../resources/intersection-observer-timestamp-subframe.ht ml";
77 targetIframe.style = "height: 100px; overflow-y: scroll"; 74 targetIframe.style = "height: 100px; overflow-y: scroll";
78 var afterFrame = document.getElementById("afterFrame"); 75 var afterFrame = document.getElementById("afterFrame");
79 afterFrame.parentNode.insertBefore(targetIframe, afterFrame); 76 afterFrame.parentNode.insertBefore(targetIframe, afterFrame);
80 targetIframe.onload = runTest; 77 targetIframe.onload = runTest;
81 }, 100); 78 }, 100);
82 }; 79 };
83 80
84 </script> 81 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698