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

Unified Diff: third_party/WebKit/LayoutTests/intersection-observer/helper-functions.js

Issue 1449623002: IntersectionObserver: second cut. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Implemented root margin Created 5 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/helper-functions.js
diff --git a/third_party/WebKit/LayoutTests/intersection-observer/helper-functions.js b/third_party/WebKit/LayoutTests/intersection-observer/helper-functions.js
new file mode 100644
index 0000000000000000000000000000000000000000..9b7cf243fbe894f5cfb6936d17f537df31a9bc34
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/intersection-observer/helper-functions.js
@@ -0,0 +1,66 @@
+// Some of the js-test.js boilerplate will add stuff to the top of the document early
+// enough to screw with frame offsets that are measured by the test. Delay all that
esprehn 2015/12/12 00:14:12 hmmm...
+// jazz until the actual test code is finished.
+setPrintTestResultsLazily();
+var delayDescription = description;
+var descriptionString = "";
+var delayIsSuccessfullyParsed = isSuccessfullyParsed;
+var isSuccessfullyParsed = function() {}
+var description = function(msg) { descriptionString = msg }
+
+if (window.testRunner)
+ testRunner.waitUntilDone();
+
+function rectToString(rect) {
+ return "[" + rect.left + ", " + rect.right + ", " + rect.top + ", " + rect.bottom + "]";
+}
+
+function entryToString(entry) {
+ var ratio = ((entry.intersectionRect.width * entry.intersectionRect.height) /
+ (entry.boundingClientRect.width * entry.boundingClientRect.height));
+ return (
+ "boundingClientRect=" + rectToString(entry.boundingClientRect) +
+ "\nintersectionRect=" + rectToString(entry.intersectionRect) +
esprehn 2015/12/12 00:14:12 I'd put each of these on a line, and put a separat
szager1 2015/12/16 19:15:33 Done.
+ "\nvisibleRatio=" + ratio +
+ "\nrootBounds=" + rectToString(entry.rootBounds) +
+ "\ntarget=" + entry.target +
+ "\ntime=" + entry.time);
+}
+
+function finishTest() {
+ if (descriptionString)
+ delayDescription(descriptionString);
+ delayIsSuccessfullyParsed();
+ finishJSTest();
+ if (window.testRunner)
+ testRunner.notifyDone();
+}
+
+function rectToString(rect) {
esprehn 2015/12/12 00:14:12 defined twice in this file
szager1 2015/12/16 19:15:33 Fixed.
+ return "[" + rect.left + ", " + rect.right + ", " + rect.top + ", " + rect.bottom + "]";
+}
+
+function checkRect(expected, actual) {
+ shouldBeEqualToNumber(actual + ".left", expected[0]);
+ shouldBeEqualToNumber(actual + ".right", expected[1]);
+ shouldBeEqualToNumber(actual + ".top", expected[2]);
+ shouldBeEqualToNumber(actual + ".bottom", expected[3]);
+}
+
+function checkEntry(expected, actual) {
+ checkRect(expected['boundingClientRect'], actual + ".boundingClientRect");
esprehn 2015/12/12 00:14:12 .boundingClientRect, why the backets?
szager1 2015/12/16 19:15:33 Fixed.
+ checkRect(expected['intersectionRect'], actual + ".intersectionRect");
esprehn 2015/12/12 00:14:12 ditto, why the brackets?
szager1 2015/12/16 19:15:33 Fixed.
+ checkRect(expected['rootBounds'], actual + ".rootBounds");
+ var actual_target = eval(actual + ".target");
esprehn 2015/12/12 00:14:12 can we avoid this eval and just list all the right
szager1 2015/12/16 19:15:33 Added a method to js-test.js to avoid doing the ev
+ if (isResultCorrect(actual_target, expected['target']))
+ testPassed(actual + ".target is " + expected);
+ else
+ testFailed(actual + ".target should be " + stringify(expected) + ". Was " + actual_target + ".");
+}
+
+function checkResults(expected, actual, startFrom = 0) {
+ shouldBeEqualToNumber(actual + ".length", expected.length);
+ var max = Math.min(eval(actual + ".length"), expected.length);
esprehn 2015/12/12 00:14:12 don't eval, the test should contain the statements
szager1 2015/12/16 19:15:33 Done.
+ for (var i = startFrom; i < max; i++)
+ checkEntry(expected[i], actual + "[" + i + "]");
+}

Powered by Google App Engine
This is Rietveld 408576698