Index: third_party/WebKit/LayoutTests/intersection-observer/same-document-root.html |
diff --git a/third_party/WebKit/LayoutTests/intersection-observer/same-document-root.html b/third_party/WebKit/LayoutTests/intersection-observer/same-document-root.html |
index 990be02ebb9ed4b0aecff01da1ca13eb64b19df7..628b37ee9d1f7a21386817f5d1dfd75a8567db1a 100644 |
--- a/third_party/WebKit/LayoutTests/intersection-observer/same-document-root.html |
+++ b/third_party/WebKit/LayoutTests/intersection-observer/same-document-root.html |
@@ -1,110 +1,108 @@ |
<!DOCTYPE html> |
-<script src="../resources/js-test.js"></script> |
-<script src="../resources/intersection-observer-helper-functions.js"></script> |
-<div 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="root" style="display: inline-block; overflow-y: scroll; height: 200px; border: 3px solid black"> |
<div style="width:100px; height: 300px;"></div> |
<div id="target" style="background-color: green; width:100px; height:100px"></div> |
</div> |
-<div style="width:100%;height:700px;"></div> |
+<div id="trailing-space" style="width:100%;height:700px;"></div> |
<script> |
-description("Simple intersection observer test with explicit root and target in the same document."); |
-var target = document.getElementById("target"); |
-var root = document.getElementById("root"); |
-var entries = []; |
-var observer = new IntersectionObserver( |
- changes => { entries = entries.concat(changes) }, |
- { root: document.getElementById("root") } |
-); |
+function waitForNotification(f) { |
+ requestAnimationFrame(() => { |
+ setTimeout(() => { |
+ setTimeout(f); |
+ }); |
+ }); |
+} |
onload = function() { |
+ var t = async_test("Simple intersection observer test with explicit root and target in the same document."); |
+ |
+ 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."); |
+ |
+ var target = document.getElementById("target"); |
+ var root = document.getElementById("root"); |
+ var entries = []; |
+ var observer = new IntersectionObserver(function(changes) { |
+ entries = entries.concat(changes) |
+ }, { root: document.getElementById("root") }); |
observer.observe(target); |
entries = entries.concat(observer.takeRecords()); |
- shouldBeEqualToNumber("entries.length", 0); |
+ test(function() { assert_equals(entries.length, 0) }, "No initial notifications."); |
waitForNotification(step0); |
-} |
-// Test that notifications are not generated when the target is overflow clipped by the root. |
-function step0() { |
- shouldBeEqualToNumber("entries.length", 0); |
- document.scrollingElement.scrollTop = 600; |
- waitForNotification(step1); |
-} |
+ function checkEntry(i, expected) { |
+ test(function() { assert_equals(entries.length, i+1) }, String(i+1) + " notification(s)."); |
+ if (expected && entries.length > i) { |
+ test(function() { assert_equals(entries[i].boundingClientRect.left, expected[0]) }, |
+ "entries[" + i + "].boundingClientRect.left == " + expected[0]); |
+ test(function() { assert_equals(entries[i].boundingClientRect.right, expected[1]) }, |
+ "entries[" + i + "].boundingClientRect.right == " + expected[1]); |
+ test(function() { assert_equals(entries[i].boundingClientRect.top, expected[2]) }, |
+ "entries[" + i + "].boundingClientRect.top == " + expected[2]); |
+ test(function() { assert_equals(entries[i].boundingClientRect.bottom, expected[3]) }, |
+ "entries[" + i + "].boundingClientRect.bottom == " + expected[3]); |
+ test(function() { assert_equals(entries[i].intersectionRect.left, expected[4]) }, |
+ "entries[" + i + "].intersectionRect.left == " + expected[4]); |
+ test(function() { assert_equals(entries[i].intersectionRect.right, expected[5]) }, |
+ "entries[" + i + "].intersectionRect.right == " + expected[5]); |
+ test(function() { assert_equals(entries[i].intersectionRect.top, expected[6]) }, |
+ "entries[" + i + "].intersectionRect.top == " + expected[6]); |
+ test(function() { assert_equals(entries[i].intersectionRect.bottom, expected[7]) }, |
+ "entries[" + i + "].intersectionRect.bottom == " + expected[7]); |
+ test(function() { assert_equals(entries[i].rootBounds.left, expected[8]) }, |
+ "entries[" + i + "].rootBounds.left == " + expected[8]); |
+ test(function() { assert_equals(entries[i].rootBounds.right, expected[9]) }, |
+ "entries[" + i + "].rootBounds.right == " + expected[9]); |
+ test(function() { assert_equals(entries[i].rootBounds.top, expected[10]) }, |
+ "entries[" + i + "].rootBounds.top == " + expected[10]); |
+ test(function() { assert_equals(entries[i].rootBounds.bottom, expected[11]) }, |
+ "entries[" + i + "].rootBounds.bottom == " + expected[11]); |
+ test(function() { assert_true(entries[i].target === expected[12]) }, |
+ "entries[" + i + "].target === " + expected[12]); |
+ } |
+ } |
-function step1() { |
- shouldBeEqualToNumber("entries.length", 0); |
- root.scrollTop = 150; |
- waitForNotification(step2); |
-} |
+ function step0() { |
+ test(function() { assert_equals(entries.length, 0) }, "No notifications after first rAF."); |
+ document.scrollingElement.scrollTop = 600; |
+ waitForNotification(step1); |
+ } |
-function step2() { |
- shouldBeEqualToNumber("entries.length", 1); |
- if (entries.length > 0) { |
- shouldBeEqualToNumber("entries[0].boundingClientRect.left", 11); |
- shouldBeEqualToNumber("entries[0].boundingClientRect.right", 111); |
- shouldBeEqualToNumber("entries[0].boundingClientRect.top", 261); |
- shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 361); |
- shouldBeEqualToNumber("entries[0].intersectionRect.left", 11); |
- shouldBeEqualToNumber("entries[0].intersectionRect.right", 111); |
- shouldBeEqualToNumber("entries[0].intersectionRect.top", 261); |
- shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 311); |
- shouldBeEqualToNumber("entries[0].rootBounds.left", 11); |
- shouldBeEqualToNumber("entries[0].rootBounds.right", 111); |
- shouldBeEqualToNumber("entries[0].rootBounds.top", 111); |
- shouldBeEqualToNumber("entries[0].rootBounds.bottom", 311); |
- shouldEvaluateToSameObject("entries[0].target", target); |
+ function step1() { |
+ test(function() { assert_equals(entries.length, 0) }, "No notifications after scrolling window."); |
+ root.scrollTop = 150; |
+ waitForNotification(step2); |
} |
- document.scrollingElement.scrollTop = 0; |
- waitForNotification(step3); |
-} |
-function step3() { |
- shouldBeEqualToNumber("entries.length", 1); |
- root.scrollTop = 0; |
- waitForNotification(step4); |
-} |
+ function step2() { |
+ checkEntry(0, [11, 111, 261, 361, 11, 111, 261, 311, 11, 111, 111, 311, target]); |
+ document.scrollingElement.scrollTop = 0; |
+ waitForNotification(step3); |
+ } |
-function step4() { |
- shouldBeEqualToNumber("entries.length", 2); |
- if (entries.length > 1) { |
- shouldBeEqualToNumber("entries[1].boundingClientRect.left", 11); |
- shouldBeEqualToNumber("entries[1].boundingClientRect.right", 111); |
- shouldBeEqualToNumber("entries[1].boundingClientRect.top", 1011); |
- shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 1111); |
- shouldBeEqualToNumber("entries[1].intersectionRect.left", 0); |
- shouldBeEqualToNumber("entries[1].intersectionRect.right", 0); |
- shouldBeEqualToNumber("entries[1].intersectionRect.top", 0); |
- shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 0); |
- shouldBeEqualToNumber("entries[1].rootBounds.left", 11); |
- shouldBeEqualToNumber("entries[1].rootBounds.right", 111); |
- shouldBeEqualToNumber("entries[1].rootBounds.top", 711); |
- shouldBeEqualToNumber("entries[1].rootBounds.bottom", 911); |
- shouldEvaluateToSameObject("entries[1].target", target); |
+ function step3() { |
+ checkEntry(0); |
+ root.scrollTop = 0; |
+ waitForNotification(step4); |
} |
- root.scrollTop = 150; |
- waitForNotification(step5); |
-} |
-// This tests that notifications are generated even when the root element is off screen. |
-function step5() { |
- shouldBeEqualToNumber("entries.length", 3); |
- if (entries.length > 2) { |
- shouldBeEqualToNumber("entries[2].boundingClientRect.left", 11); |
- shouldBeEqualToNumber("entries[2].boundingClientRect.right", 111); |
- shouldBeEqualToNumber("entries[2].boundingClientRect.top", 861); |
- shouldBeEqualToNumber("entries[2].boundingClientRect.bottom", 961); |
- shouldBeEqualToNumber("entries[2].intersectionRect.left", 11); |
- shouldBeEqualToNumber("entries[2].intersectionRect.right", 111); |
- shouldBeEqualToNumber("entries[2].intersectionRect.top", 861); |
- shouldBeEqualToNumber("entries[2].intersectionRect.bottom", 911); |
- shouldBeEqualToNumber("entries[2].rootBounds.left", 11); |
- shouldBeEqualToNumber("entries[2].rootBounds.right", 111); |
- shouldBeEqualToNumber("entries[2].rootBounds.top", 711); |
- shouldBeEqualToNumber("entries[2].rootBounds.bottom", 911); |
- shouldEvaluateToSameObject("entries[2].target", target); |
+ function step4() { |
+ checkEntry(1, [11, 111, 1011, 1111, 0, 0, 0, 0, 11, 111, 711, 911, target]); |
+ root.scrollTop = 150; |
+ waitForNotification(step5); |
} |
- finishJSTest(); |
-} |
+ // This tests that notifications are generated even when the root element is off screen. |
+ function step5() { |
+ checkEntry(2, [11, 111, 861, 961, 11, 111, 861, 911, 11, 111, 711, 911, target]); |
+ document.getElementById("leading-space").style.height = ""; |
+ document.getElementById("trailing-space").style.height = ""; |
+ t.done(); |
+ } |
+}; |
</script> |