Index: third_party/WebKit/LayoutTests/intersection-observer/unclipped-root.html |
diff --git a/third_party/WebKit/LayoutTests/intersection-observer/unclipped-root.html b/third_party/WebKit/LayoutTests/intersection-observer/unclipped-root.html |
index c11ae11ee565e5d6642f9580e35b6aa9a0ccf768..f805c6a6d521d61fff66c2065db9b8559175c48c 100644 |
--- a/third_party/WebKit/LayoutTests/intersection-observer/unclipped-root.html |
+++ b/third_party/WebKit/LayoutTests/intersection-observer/unclipped-root.html |
@@ -1,6 +1,7 @@ |
<!DOCTYPE html> |
-<script src="../resources/js-test.js"></script> |
-<script src="../resources/intersection-observer-helper-functions.js"></script> |
+<script src="../resources/testharness.js"></script> |
+<script src="../resources/testharnessreport.js"></script> |
+ |
<style> |
#root { |
overflow: visible; |
@@ -19,46 +20,69 @@ |
</div> |
<script> |
-description("Test that border bounding box is used to calculate intersection with a non-scrolling root."); |
-var target = document.getElementById("target"); |
-var root = document.getElementById("root"); |
-var entries = []; |
-var observer = new IntersectionObserver( |
- changes => { entries.push(...changes) }, |
- { root: document.getElementById("root") } |
-); |
+function waitForNotification(f) { |
+ requestAnimationFrame(() => { |
+ setTimeout(() => { |
+ setTimeout(f); |
+ }); |
+ }); |
+} |
onload = function() { |
+ var t = async_test("Test that border bounding box is used to calculate intersection with a non-scrolling root."); |
+ var root = document.getElementById("root"); |
+ var target = document.getElementById("target"); |
+ var entries = []; |
+ var observer = new IntersectionObserver(function(changes) { |
+ entries = entries.concat(changes) |
+ }, {root: root}); |
observer.observe(target); |
- entries.push(...observer.takeRecords()); |
- shouldBeEqualToNumber("entries.length", 0); |
+ entries = entries.concat(observer.takeRecords()); |
+ test(function() { assert_equals(entries.length, 0) }, "No initial notifications."); |
waitForNotification(step0); |
-} |
-function step0() { |
- shouldBeEqualToNumber("entries.length", 0); |
- target.style.transform = "translateY(195px)"; |
- 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", 1); |
- if (entries.length > 0) { |
- shouldBeEqualToNumber("entries[0].boundingClientRect.left", 15); |
- shouldBeEqualToNumber("entries[0].boundingClientRect.right", 115); |
- shouldBeEqualToNumber("entries[0].boundingClientRect.top", 210); |
- shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 310); |
- shouldBeEqualToNumber("entries[0].intersectionRect.left", 15); |
- shouldBeEqualToNumber("entries[0].intersectionRect.right", 115); |
- shouldBeEqualToNumber("entries[0].intersectionRect.top", 210); |
- shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 222); |
- shouldBeEqualToNumber("entries[0].rootBounds.left", 8); |
- shouldBeEqualToNumber("entries[0].rootBounds.right", 222); |
- shouldBeEqualToNumber("entries[0].rootBounds.top", 8); |
- shouldBeEqualToNumber("entries[0].rootBounds.bottom", 222); |
- shouldEvaluateToSameObject("entries[0].target", target); |
+ function step0() { |
+ test(function() { assert_equals(entries.length, 0) }, "No notifications after first rAF."); |
+ target.style.transform = "translateY(195px)"; |
+ waitForNotification(step1); |
} |
- finishJSTest(); |
-} |
+ function step1() { |
+ checkEntry(0, [15, 115, 210, 310, 15, 115, 210, 222, 8, 222, 8, 222, target]); |
+ target.style.transform = ""; |
+ t.done(); |
+ } |
+}; |
</script> |