| 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
|
| +// 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) +
|
| + "\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) {
|
| + 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");
|
| + checkRect(expected['intersectionRect'], actual + ".intersectionRect");
|
| + checkRect(expected['rootBounds'], actual + ".rootBounds");
|
| + var actual_target = eval(actual + ".target");
|
| + 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);
|
| + for (var i = startFrom; i < max; i++)
|
| + checkEntry(expected[i], actual + "[" + i + "]");
|
| +}
|
|
|