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

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

Issue 2560253004: IntersectionObserver: convert tests to testharness.js (Closed)
Patch Set: Address comments Created 3 years, 11 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/testharness.js"></script>
3 <script src="../resources/intersection-observer-helper-functions.js"></script> 3 <script src="../resources/testharnessreport.js"></script>
4 <div id="beforeFrame" style="width:100%; height:700px;"></div> 4 <script src="./resources/intersection-observer-test-utils.js"></script>
5 <div id="afterFrame" style="width:100%; height:700px;"></div> 5
6 <style>
7 pre, #log {
8 position: absolute;
9 top: 0;
10 left: 200px;
11 }
12 .spacer {
13 height: 700px;
14 }
15
16 </style>
17 <div id="leading-space" class="spacer"></div>
18 <div id="trailing-space" class="spacer"></div>
6 19
7 <script> 20 <script>
8 description("Test that intersection observer time is relative to time in the cal lback context."); 21 // Pick this number to be comfortably greater than the length of two frames at 6 0Hz.
22 var timeSkew = 40;
23
9 var topWindowEntries = []; 24 var topWindowEntries = [];
10 var iframeWindowEntries = []; 25 var iframeWindowEntries = [];
11 var topWindowObserver;
12 var iframeWindowObserver;
13 var targetIframe; 26 var targetIframe;
14 var iframeScroller; 27 var topWindowTimeBeforeNotification;
15 var topWindowTime; 28 var iframeWindowTimeBeforeNotification;
16 var iframeWindowTime;
17 var timestampTolerance = 24;
18 29
19 function step0() { 30 async_test(function(t) {
20 // Test results are only significant if there's a sufficient gap between 31 assert_equals(window.innerWidth, 800, "Window must be 800 pixels wide.");
21 // top window time and iframe window time. 32 assert_equals(window.innerHeight, 600, "Window must be 600 pixels high.");
22 topWindowTime = performance.now();
23 iframeWindowTime = targetIframe.contentWindow.performance.now();
24 shouldBeGreaterThan("topWindowTime - iframeWindowTime", "2.5 * timestampTolera nce");
25 33
26 shouldBeEqualToNumber("topWindowEntries.length", 0); 34 setTimeout(function() {
27 shouldBeEqualToNumber("iframeWindowEntries.length", 0); 35 targetIframe = document.createElement("iframe");
36 assert_true(!!targetIframe, "iframe exists");
37 targetIframe.src = "resources/timestamp-subframe.html";
38 var trailingSpace = document.getElementById("trailing-space");
39 assert_true(!!trailingSpace, "trailing-space exists");
40 trailingSpace.parentNode.insertBefore(targetIframe, trailingSpace);
41 targetIframe.onload = function() {
42 var target = targetIframe.contentDocument.getElementById("target");
43 var iframeScroller = targetIframe.contentDocument.scrollingElement;
44
45 // Observer created here, callback created in iframe context. Timestamps should be
46 // from this window.
47 var observer = new IntersectionObserver(
48 targetIframe.contentDocument.createObserverCallback(topWindowEntries), {});
49 assert_true(!!observer, "Observer exists");
50 observer.observe(target);
51
52 // Callback created here, observer created in iframe. Timestamps should b e
53 // from iframe window.
54 observer = targetIframe.contentDocument.createObserver(function(newEntries ) {
55 » iframeWindowEntries = iframeWindowEntries.concat(newEntries);
56 });
57 observer.observe(target);
58 runTestCycle(step1, "First rAF after iframe is loaded.");
59 t.done();
60 };
61 }, timeSkew);
62 }, "Check that timestamps correspond to the to execution context that created th e observer.");
63
64 function step1() {
28 document.scrollingElement.scrollTop = 200; 65 document.scrollingElement.scrollTop = 200;
29 iframeScroller.scrollTop = 250; 66 targetIframe.contentDocument.scrollingElement.scrollTop = 250;
30 waitForNotification(step1); 67 topWindowTimeBeforeNotification = performance.now();
68 iframeWindowTimeBeforeNotification = targetIframe.contentWindow.performance.no w();
69 runTestCycle(step2, "Generate notifications.");
70 assert_equals(topWindowEntries.length, 0, "No notifications to top window obse rver.");
71 assert_equals(iframeWindowEntries.length, 0, "No notifications to iframe obser ver.");
31 } 72 }
32 73
33 function step1() { 74 function step2() {
34 topWindowTime = performance.now(); 75 document.scrollingElement.scrollTop = 0;
35 iframeWindowTime = targetIframe.contentWindow.performance.now(); 76 var topWindowTimeAfterNotification = performance.now();
36 shouldBeEqualToNumber("topWindowEntries.length", 1); 77 var iframeWindowTimeAfterNotification = targetIframe.contentWindow.performance .now();
37 if (topWindowEntries.length)
38 shouldBeCloseTo("topWindowEntries[0].time", "topWindowTime", timestampTolera nce);
39 78
40 shouldBeEqualToNumber("iframeWindowEntries.length", 1); 79 // Test results are only significant if there's a gap between
41 if (iframeWindowEntries.length) { 80 // top window time and iframe window time.
42 shouldBeCloseTo("iframeWindowEntries[0].time", "iframeWindowTime", timestamp Tolerance); 81 assert_greater_than(topWindowTimeBeforeNotification, iframeWindowTimeAfterNoti fication,
43 } 82 » » "Time ranges for top and iframe windows are disjoint.");
44 waitForNotification(finishJSTest); 83
45 document.scrollingElement.scrollTop = 0; 84 assert_equals(topWindowEntries.length, 1, "Top window observer has one notific ation.");
85 assert_between_inclusive(
86 topWindowEntries[0].time,
87 topWindowTimeBeforeNotification,
88 topWindowTimeAfterNotification,
89 "Notification to top window observer is within the expected range.");
90
91 assert_equals(iframeWindowEntries.length, 1, "Iframe observer has one notifica tion.");
92 assert_between_inclusive(
93 iframeWindowEntries[0].time,
94 iframeWindowTimeBeforeNotification,
95 iframeWindowTimeAfterNotification,
96 "Notification to iframe observer is within the expected range.");
46 } 97 }
47
48 function runTest() {
49 var target = targetIframe.contentDocument.getElementById("target");
50 iframeScroller = targetIframe.contentDocument.scrollingElement;
51
52 // Observer created here, callback created in iframe context. Timestamps shou ld be
53 // from this window.
54 topWindowObserver = new IntersectionObserver(targetIframe.contentDocument.crea teObserverCallback(topWindowEntries), {});
55 topWindowObserver.observe(target);
56
57 // Callback created here, observer created in iframe. Timestamps should be
58 // from iframe window.
59 iframeWindowObserver = targetIframe.contentDocument.createObserver(function(ne wEntries) {
60 for (var i = 0; i < newEntries.length; i++)
61 iframeWindowEntries.push(newEntries[i]);
62 });
63 iframeWindowObserver.observe(target);
64
65 waitForNotification(step0);
66 }
67
68 onload = function() {
69 setTimeout(function() {
70 targetIframe = document.createElement("iframe");
71 targetIframe.src = "../resources/intersection-observer-timestamp-subframe.ht ml";
72 targetIframe.style = "height: 100px; overflow-y: scroll";
73 var afterFrame = document.getElementById("afterFrame");
74 afterFrame.parentNode.insertBefore(targetIframe, afterFrame);
75 targetIframe.onload = runTest;
76 }, 2.5 * timestampTolerance);
77 };
78
79 </script> 98 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698