Index: third_party/WebKit/LayoutTests/intersection-observer/timestamp.html |
diff --git a/third_party/WebKit/LayoutTests/intersection-observer/timestamp.html b/third_party/WebKit/LayoutTests/intersection-observer/timestamp.html |
index 8d061a94337a050d3f07bf4cb2d395a763fedb7a..28cc29b79d6cc453290c20b845434377281d876a 100644 |
--- a/third_party/WebKit/LayoutTests/intersection-observer/timestamp.html |
+++ b/third_party/WebKit/LayoutTests/intersection-observer/timestamp.html |
@@ -1,79 +1,114 @@ |
<!DOCTYPE html> |
-<script src="../resources/js-test.js"></script> |
-<script src="../resources/intersection-observer-helper-functions.js"></script> |
-<div id="beforeFrame" style="width:100%; height:700px;"></div> |
-<div id="afterFrame" style="width:100%; height:700px;"></div> |
+<script src="../resources/testharness.js"></script> |
+<script src="../resources/testharnessreport.js"></script> |
+ |
+<div id="leading-space" style="width:100%; height:700px;"></div> |
+<div id="trailing-space" style="width:100%; height:700px;"></div> |
<script> |
-description("Test that intersection observer time is relative to time in the callback context."); |
-var topWindowEntries = []; |
-var iframeWindowEntries = []; |
-var topWindowObserver; |
-var iframeWindowObserver; |
-var targetIframe; |
-var iframeScroller; |
-var topWindowTime; |
-var iframeWindowTime; |
-var timestampTolerance = 24; |
- |
-function step0() { |
- // Test results are only significant if there's a sufficient gap between |
- // top window time and iframe window time. |
- topWindowTime = performance.now(); |
- iframeWindowTime = targetIframe.contentWindow.performance.now(); |
- shouldBeGreaterThan("topWindowTime - iframeWindowTime", "2.5 * timestampTolerance"); |
- |
- shouldBeEqualToNumber("topWindowEntries.length", 0); |
- shouldBeEqualToNumber("iframeWindowEntries.length", 0); |
- document.scrollingElement.scrollTop = 200; |
- iframeScroller.scrollTop = 250; |
- waitForNotification(step1); |
+function waitForNotification(f) { |
+ requestAnimationFrame(() => { |
+ setTimeout(() => { |
+ setTimeout(f); |
+ }); |
+ }); |
} |
-function step1() { |
- topWindowTime = performance.now(); |
- iframeWindowTime = targetIframe.contentWindow.performance.now(); |
- shouldBeEqualToNumber("topWindowEntries.length", 1); |
- if (topWindowEntries.length) |
- shouldBeCloseTo("topWindowEntries[0].time", "topWindowTime", timestampTolerance); |
+onload = function() { |
+ var t = async_test("Test that intersection observer time is relative to time in the callback context."); |
+ |
+ test(function() { assert_equals(window.innerWidth, 800) }, "Window must be 800 pixels wide."); |
+ test(function() { assert_equals(window.innerHeight, 600) }, "Window must be 600 pixels high."); |
+ |
+ // Pick this number to be comfortably greater than the length of two frames at 60Hz. |
+ var timeSkew = 40; |
+ |
+ var topWindowEntries = []; |
+ var iframeWindowEntries = []; |
+ var targetIframe; |
+ var topWindowTimeBeforeNotification; |
+ var iframeWindowTimeBeforeNotification; |
+ |
+ setTimeout(function() { |
+ targetIframe = document.createElement("iframe"); |
+ targetIframe.src = "resources/timestamp-subframe.html"; |
+ var trailingSpace = document.getElementById("trailing-space"); |
+ trailingSpace.parentNode.insertBefore(targetIframe, trailingSpace); |
+ targetIframe.onload = step0; |
+ }, timeSkew); |
+ |
+ function step0() { |
+ var target = targetIframe.contentDocument.getElementById("target"); |
+ var iframeScroller = targetIframe.contentDocument.scrollingElement; |
+ |
+ // Observer created here, callback created in iframe context. Timestamps should be |
+ // from this window. |
+ var observer = new IntersectionObserver( |
+ targetIframe.contentDocument.createObserverCallback(topWindowEntries), {}); |
+ observer.observe(target); |
- shouldBeEqualToNumber("iframeWindowEntries.length", 1); |
- if (iframeWindowEntries.length) { |
- shouldBeCloseTo("iframeWindowEntries[0].time", "iframeWindowTime", timestampTolerance); |
+ // Callback created here, observer created in iframe. Timestamps should be |
+ // from iframe window. |
+ observer = targetIframe.contentDocument.createObserver(function(newEntries) { |
+ for (var i = 0; i < newEntries.length; i++) |
+ iframeWindowEntries.push(newEntries[i]); |
+ }); |
+ observer.observe(target); |
+ waitForNotification(step1); |
} |
- waitForNotification(finishJSTest); |
- document.scrollingElement.scrollTop = 0; |
-} |
-function runTest() { |
- var target = targetIframe.contentDocument.getElementById("target"); |
- iframeScroller = targetIframe.contentDocument.scrollingElement; |
+ function step1() { |
+ test(function() { |
+ assert_equals(topWindowEntries.length, 0); |
+ }, "No notifications to top window observer."); |
+ test(function() { |
+ assert_equals(iframeWindowEntries.length, 0); |
+ }, "No notifications to iframe observer."); |
+ document.scrollingElement.scrollTop = 200; |
+ targetIframe.contentDocument.scrollingElement.scrollTop = 250; |
+ topWindowTimeBeforeNotification = performance.now(); |
+ iframeWindowTimeBeforeNotification = targetIframe.contentWindow.performance.now(); |
+ waitForNotification(step2); |
+ } |
- // Observer created here, callback created in iframe context. Timestamps should be |
- // from this window. |
- topWindowObserver = new IntersectionObserver(targetIframe.contentDocument.createObserverCallback(topWindowEntries), {}); |
- topWindowObserver.observe(target); |
+ function step2() { |
+ var topWindowTimeAfterNotification = performance.now(); |
+ var iframeWindowTimeAfterNotification = targetIframe.contentWindow.performance.now(); |
- // Callback created here, observer created in iframe. Timestamps should be |
- // from iframe window. |
- iframeWindowObserver = targetIframe.contentDocument.createObserver(function(newEntries) { |
- for (var i = 0; i < newEntries.length; i++) |
- iframeWindowEntries.push(newEntries[i]); |
- }); |
- iframeWindowObserver.observe(target); |
+ // Test results are only significant if there's a gap between |
+ // top window time and iframe window time. |
+ test(function() { |
+ assert_greater_than(topWindowTimeBeforeNotification, iframeWindowTimeAfterNotification); |
+ }, "Time ranges for top and iframe windows are disjoint."); |
- waitForNotification(step0); |
-} |
+ test(function() { |
+ assert_equals(topWindowEntries.length, 1) |
+ }, "Top window observer has one notification."); |
+ if (topWindowEntries.length > 0) { |
+ test(function() { |
+ assert_between_inclusive( |
+ topWindowEntries[0].time, |
+ topWindowTimeBeforeNotification, |
+ topWindowTimeAfterNotification); |
+ }, "Notification to top window observer is within the expected range."); |
+ } |
-onload = function() { |
- setTimeout(function() { |
- targetIframe = document.createElement("iframe"); |
- targetIframe.src = "../resources/intersection-observer-timestamp-subframe.html"; |
- targetIframe.style = "height: 100px; overflow-y: scroll"; |
- var afterFrame = document.getElementById("afterFrame"); |
- afterFrame.parentNode.insertBefore(targetIframe, afterFrame); |
- targetIframe.onload = runTest; |
- }, 2.5 * timestampTolerance); |
-}; |
+ test(function() { |
+ assert_equals(iframeWindowEntries.length, 1) |
+ }, "Iframe observer has one notification."); |
+ if (iframeWindowEntries.length > 0) { |
+ test(function() { |
+ assert_between_inclusive( |
+ iframeWindowEntries[0].time, |
+ iframeWindowTimeBeforeNotification, |
+ iframeWindowTimeAfterNotification); |
+ }, "Notification to iframe observer is within the expected range."); |
+ } |
+ document.getElementById("leading-space").style.height = ""; |
+ document.getElementById("trailing-space").style.height = ""; |
+ document.scrollingElement.scrollTop = 0; |
+ t.done(); |
+ } |
+}; |
</script> |