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

Unified Diff: third_party/WebKit/LayoutTests/intersection-observer/multiple-thresholds.html

Issue 2560253004: IntersectionObserver: convert tests to testharness.js (Closed)
Patch Set: rebase Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/intersection-observer/multiple-thresholds.html
diff --git a/third_party/WebKit/LayoutTests/intersection-observer/multiple-thresholds.html b/third_party/WebKit/LayoutTests/intersection-observer/multiple-thresholds.html
index a8622e5ab891922179d0c265abe997ba423aa408..fba2c45142d5b26a6e859ca2c63e5f546f6eb8b4 100644
--- a/third_party/WebKit/LayoutTests/intersection-observer/multiple-thresholds.html
+++ b/third_party/WebKit/LayoutTests/intersection-observer/multiple-thresholds.html
@@ -1,205 +1,135 @@
<!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="target" style="background-color: green; width:100px; height:100px"></div>
-<div style="width:100%; height:700px;"></div>
+<div id="trailing-space" style="width:100%; height:700px;"></div>
<script>
-description("Intersection observer test with multiple thresholds.");
-var target = document.getElementById("target");
-var entries = [];
-var observer = new IntersectionObserver(
- changes => { entries = entries.concat(changes) },
- { threshold: [0, 0.25, 0.5, 0.75, 1] }
-);
+function waitForNotification(f) {
+ requestAnimationFrame(() => {
+ setTimeout(() => {
+ setTimeout(f);
+ });
+ });
+}
onload = function() {
+ var t = async_test("Intersection observer test with multiple thresholds.");
+
+ 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 entries = [];
+ var observer = new IntersectionObserver(function(changes) {
+ entries = entries.concat(changes)
+ }, { threshold: [0, 0.25, 0.5, 0.75, 1] });
observer.observe(target);
entries = entries.concat(observer.takeRecords());
- shouldBeEqualToNumber("entries.length", 0);
+ test(function() { assert_equals(entries.length, 0) }, "No initial notifications.");
waitForNotification(step0);
-}
-function step0() {
- shouldBeEqualToNumber("entries.length", 0);
- document.scrollingElement.scrollTop = 120;
- waitForNotification(step1);
-}
+ function rectArea(rect) {
+ return (rect.left - rect.right) * (rect.bottom - rect.top);
+ }
-function step1() {
- shouldBeEqualToNumber("entries.length", 1);
- if (entries.length > 0) {
- shouldBeEqualToNumber("entries[0].boundingClientRect.left", 8);
- shouldBeEqualToNumber("entries[0].boundingClientRect.right", 108);
- shouldBeEqualToNumber("entries[0].boundingClientRect.top", 588);
- shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 688);
- shouldBeEqualToNumber("entries[0].intersectionRect.left", 8);
- shouldBeEqualToNumber("entries[0].intersectionRect.right", 108);
- shouldBeEqualToNumber("entries[0].intersectionRect.top", 588);
- shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 600);
- shouldBeEqualToNumber("entries[0].rootBounds.left", 0);
- shouldBeEqualToNumber("entries[0].rootBounds.right", 785);
- shouldBeEqualToNumber("entries[0].rootBounds.top", 0);
- shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600);
- shouldBeCloseTo("entries[0].intersectionRatio", intersectionRatio(entries[0]), .0001);
- shouldEvaluateToSameObject("entries[0].target", target);
+ function intersectionRatio(entry) {
+ var targetArea = rectArea(entry.boundingClientRect);
+ if (!targetArea)
+ return 0;
+ return rectArea(entry.intersectionRect) / targetArea;
}
- document.scrollingElement.scrollTop = 160;
- waitForNotification(step2);
-}
-function step2() {
- shouldBeEqualToNumber("entries.length", 2);
- if (entries.length > 1) {
- shouldBeEqualToNumber("entries[1].boundingClientRect.left", 8);
- shouldBeEqualToNumber("entries[1].boundingClientRect.right", 108);
- shouldBeEqualToNumber("entries[1].boundingClientRect.top", 548);
- shouldBeEqualToNumber("entries[1].boundingClientRect.bottom", 648);
- shouldBeEqualToNumber("entries[1].intersectionRect.left", 8);
- shouldBeEqualToNumber("entries[1].intersectionRect.right", 108);
- shouldBeEqualToNumber("entries[1].intersectionRect.top", 548);
- shouldBeEqualToNumber("entries[1].intersectionRect.bottom", 600);
- shouldBeEqualToNumber("entries[1].rootBounds.left", 0);
- shouldBeEqualToNumber("entries[1].rootBounds.right", 785);
- shouldBeEqualToNumber("entries[1].rootBounds.top", 0);
- shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600);
- shouldBeCloseTo("entries[1].intersectionRatio", intersectionRatio(entries[1]), .0001);
- shouldEvaluateToSameObject("entries[1].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]);
+ test(function() { assert_approx_equals(entries[i].intersectionRatio,
+ intersectionRatio(entries[i]), .0001) },
+ "entries[" + i + "].intersectionRatio ~= " + intersectionRatio(entries[i]));
+ }
}
- document.scrollingElement.scrollTop = 200;
- waitForNotification(step3);
-}
-function step3() {
- shouldBeEqualToNumber("entries.length", 3);
- if (entries.length > 2) {
- shouldBeEqualToNumber("entries[2].boundingClientRect.left", 8);
- shouldBeEqualToNumber("entries[2].boundingClientRect.right", 108);
- shouldBeEqualToNumber("entries[2].boundingClientRect.top", 508);
- shouldBeEqualToNumber("entries[2].boundingClientRect.bottom", 608);
- shouldBeEqualToNumber("entries[2].intersectionRect.left", 8);
- shouldBeEqualToNumber("entries[2].intersectionRect.right", 108);
- shouldBeEqualToNumber("entries[2].intersectionRect.top", 508);
- shouldBeEqualToNumber("entries[2].intersectionRect.bottom", 600);
- shouldBeEqualToNumber("entries[2].rootBounds.left", 0);
- shouldBeEqualToNumber("entries[2].rootBounds.right", 785);
- shouldBeEqualToNumber("entries[2].rootBounds.top", 0);
- shouldBeEqualToNumber("entries[2].rootBounds.bottom", 600);
- shouldBeCloseTo("entries[2].intersectionRatio", intersectionRatio(entries[2]), .0001);
- shouldEvaluateToSameObject("entries[2].target", target);
+ function step0() {
+ test(function() { assert_equals(entries.length, 0) }, "No notifications after first rAF.");
+ document.scrollingElement.scrollTop = 120;
+ waitForNotification(step1);
}
- document.scrollingElement.scrollTop = 240;
- waitForNotification(step4);
-}
-function step4() {
- shouldBeEqualToNumber("entries.length", 4);
- if (entries.length > 3) {
- shouldBeEqualToNumber("entries[3].boundingClientRect.left", 8);
- shouldBeEqualToNumber("entries[3].boundingClientRect.right", 108);
- shouldBeEqualToNumber("entries[3].boundingClientRect.top", 468);
- shouldBeEqualToNumber("entries[3].boundingClientRect.bottom", 568);
- shouldBeEqualToNumber("entries[3].intersectionRect.left", 8);
- shouldBeEqualToNumber("entries[3].intersectionRect.right", 108);
- shouldBeEqualToNumber("entries[3].intersectionRect.top", 468);
- shouldBeEqualToNumber("entries[3].intersectionRect.bottom", 568);
- shouldBeEqualToNumber("entries[3].rootBounds.left", 0);
- shouldBeEqualToNumber("entries[3].rootBounds.right", 785);
- shouldBeEqualToNumber("entries[3].rootBounds.top", 0);
- shouldBeEqualToNumber("entries[3].rootBounds.bottom", 600);
- shouldBeCloseTo("entries[3].intersectionRatio", intersectionRatio(entries[3]), .0001);
- shouldEvaluateToSameObject("entries[3].target", target);
+ function step1() {
+ checkEntry(0, [8, 108, 588, 688, 8, 108, 588, 600, 0, 785, 0, 600, target]);
+ document.scrollingElement.scrollTop = 160;
+ waitForNotification(step2);
}
- document.scrollingElement.scrollTop = 740;
- waitForNotification(step5);
-}
-function step5() {
- shouldBeEqualToNumber("entries.length", 5);
- if (entries.length > 4) {
- shouldBeEqualToNumber("entries[4].boundingClientRect.left", 8);
- shouldBeEqualToNumber("entries[4].boundingClientRect.right", 108);
- shouldBeEqualToNumber("entries[4].boundingClientRect.top", -32);
- shouldBeEqualToNumber("entries[4].boundingClientRect.bottom", 68);
- shouldBeEqualToNumber("entries[4].intersectionRect.left", 8);
- shouldBeEqualToNumber("entries[4].intersectionRect.right", 108);
- shouldBeEqualToNumber("entries[4].intersectionRect.top", 0);
- shouldBeEqualToNumber("entries[4].intersectionRect.bottom", 68);
- shouldBeEqualToNumber("entries[4].rootBounds.left", 0);
- shouldBeEqualToNumber("entries[4].rootBounds.right", 785);
- shouldBeEqualToNumber("entries[4].rootBounds.top", 0);
- shouldBeEqualToNumber("entries[4].rootBounds.bottom", 600);
- shouldBeCloseTo("entries[4].intersectionRatio", intersectionRatio(entries[4]), .0001);
- shouldEvaluateToSameObject("entries[4].target", target);
+ function step2() {
+ checkEntry(1, [8, 108, 548, 648, 8, 108, 548, 600, 0, 785, 0, 600, target]);
+ document.scrollingElement.scrollTop = 200;
+ waitForNotification(step3);
}
- document.scrollingElement.scrollTop = 760;
- waitForNotification(step6);
-}
-function step6() {
- shouldBeEqualToNumber("entries.length", 6);
- if (entries.length > 5) {
- shouldBeEqualToNumber("entries[5].boundingClientRect.left", 8);
- shouldBeEqualToNumber("entries[5].boundingClientRect.right", 108);
- shouldBeEqualToNumber("entries[5].boundingClientRect.top", -52);
- shouldBeEqualToNumber("entries[5].boundingClientRect.bottom", 48);
- shouldBeEqualToNumber("entries[5].intersectionRect.left", 8);
- shouldBeEqualToNumber("entries[5].intersectionRect.right", 108);
- shouldBeEqualToNumber("entries[5].intersectionRect.top", 0);
- shouldBeEqualToNumber("entries[5].intersectionRect.bottom", 48);
- shouldBeEqualToNumber("entries[5].rootBounds.left", 0);
- shouldBeEqualToNumber("entries[5].rootBounds.right", 785);
- shouldBeEqualToNumber("entries[5].rootBounds.top", 0);
- shouldBeEqualToNumber("entries[5].rootBounds.bottom", 600);
- shouldBeCloseTo("entries[5].intersectionRatio", intersectionRatio(entries[5]), .0001);
- shouldEvaluateToSameObject("entries[5].target", target);
+ function step3() {
+ checkEntry(2, [8, 108, 508, 608, 8, 108, 508, 600, 0, 785, 0, 600, target]);
+ document.scrollingElement.scrollTop = 240;
+ waitForNotification(step4);
}
- document.scrollingElement.scrollTop = 800;
- waitForNotification(step7);
-}
-function step7() {
- shouldBeEqualToNumber("entries.length", 7);
- if (entries.length > 6) {
- shouldBeEqualToNumber("entries[6].boundingClientRect.left", 8);
- shouldBeEqualToNumber("entries[6].boundingClientRect.right", 108);
- shouldBeEqualToNumber("entries[6].boundingClientRect.top", -92);
- shouldBeEqualToNumber("entries[6].boundingClientRect.bottom", 8);
- shouldBeEqualToNumber("entries[6].intersectionRect.left", 8);
- shouldBeEqualToNumber("entries[6].intersectionRect.right", 108);
- shouldBeEqualToNumber("entries[6].intersectionRect.top", 0);
- shouldBeEqualToNumber("entries[6].intersectionRect.bottom", 8);
- shouldBeEqualToNumber("entries[6].rootBounds.left", 0);
- shouldBeEqualToNumber("entries[6].rootBounds.right", 785);
- shouldBeEqualToNumber("entries[6].rootBounds.top", 0);
- shouldBeEqualToNumber("entries[6].rootBounds.bottom", 600);
- shouldBeCloseTo("entries[6].intersectionRatio", intersectionRatio(entries[6]), .0001);
- shouldEvaluateToSameObject("entries[6].target", target);
+ function step4() {
+ checkEntry(3, [8, 108, 468, 568, 8, 108, 468, 568, 0, 785, 0, 600, target]);
+ document.scrollingElement.scrollTop = 740;
+ waitForNotification(step5);
}
- document.scrollingElement.scrollTop = 820;
- waitForNotification(step8);
-}
-function step8() {
- shouldBeEqualToNumber("entries.length", 8);
- if (entries.length > 7) {
- shouldBeEqualToNumber("entries[7].boundingClientRect.left", 8);
- shouldBeEqualToNumber("entries[7].boundingClientRect.right", 108);
- shouldBeEqualToNumber("entries[7].boundingClientRect.top", -112);
- shouldBeEqualToNumber("entries[7].boundingClientRect.bottom", -12);
- shouldBeEqualToNumber("entries[7].intersectionRect.left", 0);
- shouldBeEqualToNumber("entries[7].intersectionRect.right", 0);
- shouldBeEqualToNumber("entries[7].intersectionRect.top", 0);
- shouldBeEqualToNumber("entries[7].intersectionRect.bottom", 0);
- shouldBeEqualToNumber("entries[7].rootBounds.left", 0);
- shouldBeEqualToNumber("entries[7].rootBounds.right", 785);
- shouldBeEqualToNumber("entries[7].rootBounds.top", 0);
- shouldBeEqualToNumber("entries[7].rootBounds.bottom", 600);
- shouldBeCloseTo("entries[7].intersectionRatio", intersectionRatio(entries[7]), .0001);
- shouldEvaluateToSameObject("entries[7].target", target);
+ function step5() {
+ checkEntry(4, [8, 108, -32, 68, 8, 108, 0, 68, 0, 785, 0, 600, target]);
+ document.scrollingElement.scrollTop = 760;
+ waitForNotification(step6);
}
- finishJSTest();
- document.scrollingElement.scrollTop = 0;
-}
+
+ function step6() {
+ checkEntry(5, [8, 108, -52, 48, 8, 108, 0, 48, 0, 785, 0, 600, target]);
+ document.scrollingElement.scrollTop = 800;
+ waitForNotification(step7);
+ }
+
+ function step7() {
+ checkEntry(6, [8, 108, -92, 8, 8, 108, 0, 8, 0, 785, 0, 600, target]);
+ document.scrollingElement.scrollTop = 820;
+ waitForNotification(step8);
+ }
+
+ function step8() {
+ checkEntry(7, [8, 108, -112, -12, 0, 0, 0, 0, 0, 785, 0, 600, target]);
+ document.getElementById("leading-space").style.height = "";
+ document.getElementById("trailing-space").style.height = "";
+ document.scrollingElement.scrollTop = 0;
+ t.done();
+ }
+};
</script>

Powered by Google App Engine
This is Rietveld 408576698