Index: third_party/WebKit/LayoutTests/intersection-observer/containing-block.html |
diff --git a/third_party/WebKit/LayoutTests/intersection-observer/containing-block.html b/third_party/WebKit/LayoutTests/intersection-observer/containing-block.html |
index 5df7cb87c9673d76f3428414c3f20fa920f65131..8059337aebad5fe5afc37304c8c69002585a4852 100644 |
--- a/third_party/WebKit/LayoutTests/intersection-observer/containing-block.html |
+++ b/third_party/WebKit/LayoutTests/intersection-observer/containing-block.html |
@@ -1,6 +1,6 @@ |
<!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 { |
width: 200px; |
@@ -19,74 +19,87 @@ |
</div> |
<script> |
-description("Test that no notifications are generated when root is not in the containing block chain of target."); |
-var root = document.getElementById("root"); |
-var target = document.getElementById("target"); |
-var entries = []; |
- |
-var observer = new IntersectionObserver( |
- changes => { entries.push(...changes) }, |
- { root: root } |
-); |
+function waitForNotification(f) { |
+ requestAnimationFrame(() => { |
+ setTimeout(() => { |
+ setTimeout(f); |
+ }); |
+ }); |
+} |
onload = function() { |
+ var t = async_test("Test that no notifications are generated when root is not in the containing block chain of target."); |
+ |
+ 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 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); |
- shouldBeEqualToNumber("entries.length", 0); |
+ entries = entries.concat(observer.takeRecords()); |
+ test(function() { assert_equals(entries.length, 0) }, "No initial notifications."); |
target.style.top = "10px"; |
waitForNotification(step1); |
-}; |
-function step1() { |
- shouldBeEqualToNumber("entries.length", 1); |
- if (entries.length > 0) { |
- shouldBeEqualToNumber("entries[0].boundingClientRect.left", 58); |
- shouldBeEqualToNumber("entries[0].boundingClientRect.right", 158); |
- shouldBeEqualToNumber("entries[0].boundingClientRect.top", 18); |
- shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 118); |
- shouldBeEqualToNumber("entries[0].intersectionRect.left", 58); |
- shouldBeEqualToNumber("entries[0].intersectionRect.right", 158); |
- shouldBeEqualToNumber("entries[0].intersectionRect.top", 18); |
- shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 118); |
- shouldBeEqualToNumber("entries[0].rootBounds.left", 8); |
- shouldBeEqualToNumber("entries[0].rootBounds.right", 193); |
- shouldBeEqualToNumber("entries[0].rootBounds.top", 8); |
- shouldBeEqualToNumber("entries[0].rootBounds.bottom", 208); |
- shouldEvaluateToSameObject("entries[0].target", target); |
+ 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]); |
+ } |
} |
- target.style.top = "250px"; |
- waitForNotification(step2); |
-} |
-function step2() { |
- shouldBeEqualToNumber("entries.length", 2); |
- if (entries.length > 1) { |
- shouldBeEqualToNumber("entries[1].boundingClientRect.left", 58); |
- shouldBeEqualToNumber("entries[1].boundingClientRect.right", 158); |
- shouldBeEqualToNumber("entries[1].boundingClientRect.top", 258); |
- shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 358); |
- 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", 8); |
- shouldBeEqualToNumber("entries[1].rootBounds.right", 193); |
- shouldBeEqualToNumber("entries[1].rootBounds.top", 8); |
- shouldBeEqualToNumber("entries[1].rootBounds.bottom", 208); |
- shouldEvaluateToSameObject("entries[1].target", target); |
+ function step1() { |
+ checkEntry(0, [58, 158, 18, 118, 58, 158, 18, 118, 8, 193, 8, 208, target]); |
+ target.style.top = "250px"; |
+ waitForNotification(step2); |
} |
- root.style.position = "static"; |
- target.style.top = "10px"; |
- waitForNotification(step3); |
-} |
-function step3() { |
- shouldBeEqualToNumber("entries.length", 2); |
- target.style.top = "250px"; |
- waitForNotification(step4); |
-} |
+ function step2() { |
+ checkEntry(1, [58, 158, 258, 358, 0, 0, 0, 0, 8, 193, 8, 208, target]); |
+ root.style.position = "static"; |
+ target.style.top = "10px"; |
+ waitForNotification(step3); |
+ } |
-function step4() { |
- shouldBeEqualToNumber("entries.length", 2); |
- finishJSTest(); |
-} |
+ function step3() { |
+ checkEntry(1); |
+ target.style.top = "250px"; |
+ waitForNotification(step4); |
+ } |
+ |
+ function step4() { |
+ checkEntry(1); |
+ target.style.top = "0"; |
+ t.done(); |
+ } |
+}; |
</script> |