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

Unified Diff: third_party/WebKit/LayoutTests/intersection-observer/shadow-content.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/shadow-content.html
diff --git a/third_party/WebKit/LayoutTests/intersection-observer/shadow-content.html b/third_party/WebKit/LayoutTests/intersection-observer/shadow-content.html
index 7a990e30f803604f5774af20ae4425a5999ba42c..89ebf87463b964bc5c457e9d4293976715f60e43 100644
--- a/third_party/WebKit/LayoutTests/intersection-observer/shadow-content.html
+++ b/third_party/WebKit/LayoutTests/intersection-observer/shadow-content.html
@@ -1,44 +1,74 @@
<!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>
+
<div id="host"></div>
<script>
-description("Tests that observations can be made across shadow DOM boundaries.");
-var entries = [];
-var target;
-var observer = new IntersectionObserver(changes => { entries = entries.concat(changes) });
-
-onload = function() {
- let shadowHost = document.getElementById("host");
- let shadowRoot = shadowHost.createShadowRoot();
- target = document.createElement('div');
+function waitForNotification(f) {
+ requestAnimationFrame(() => {
+ setTimeout(() => {
+ setTimeout(f);
+ });
+ });
+}
+
+onload = function() { waitForNotification(function() {
+ var t = async_test("Tests that observations can be made across shadow DOM boundaries.");
+
+ 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 shadowHost = document.getElementById("host");
+ var shadowRoot = shadowHost.createShadowRoot();
+ var target = document.createElement('div');
target.style.cssText = "background-color: green; width:100px; height:100px";
shadowRoot.appendChild(target);
- observer.observe(target);
+ var entries = [];
+ var observer = new IntersectionObserver(function(changes) {
+ entries = entries.concat(changes)
+ });
+ observer.observe(target);
entries = entries.concat(observer.takeRecords());
- shouldBeEqualToNumber("entries.length", 0);
- waitForNotification(step1);
-};
-
-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", 8);
- shouldBeEqualToNumber("entries[0].boundingClientRect.bottom", 108);
- shouldBeEqualToNumber("entries[0].intersectionRect.left", 8);
- shouldBeEqualToNumber("entries[0].intersectionRect.right", 108);
- shouldBeEqualToNumber("entries[0].intersectionRect.top", 8);
- shouldBeEqualToNumber("entries[0].intersectionRect.bottom", 108);
- shouldBeEqualToNumber("entries[0].rootBounds.left", 0);
- shouldBeEqualToNumber("entries[0].rootBounds.right", 800);
- shouldBeEqualToNumber("entries[0].rootBounds.top", 0);
- shouldBeEqualToNumber("entries[0].rootBounds.bottom", 600);
- shouldEvaluateToSameObject("entries[0].target", target);
+ test(function() { assert_equals(entries.length, 0) }, "No initial notifications.");
+ waitForNotification(step0);
+
+ 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]);
+ }
}
- finishJSTest();
-}
+
+ function step0() {
+ checkEntry(0, [8, 108, 8, 108, 8, 108, 8, 108, 0, 800, 0, 600, target]);
+ t.done();
+ }
+})};
</script>

Powered by Google App Engine
This is Rietveld 408576698