OLD | NEW |
(Empty) | |
| 1 // Some of the js-test.js boilerplate will add stuff to the top of the document
early |
| 2 // enough to screw with frame offsets that are measured by the test. Delay all
that |
| 3 // jazz until the actual test code is finished. |
| 4 setPrintTestResultsLazily(); |
| 5 var delayDescription = description; |
| 6 var descriptionString = ""; |
| 7 var delayIsSuccessfullyParsed = isSuccessfullyParsed; |
| 8 var isSuccessfullyParsed = function() {} |
| 9 var description = function(msg) { descriptionString = msg } |
| 10 |
| 11 if (window.testRunner) |
| 12 testRunner.waitUntilDone(); |
| 13 |
| 14 function rectToString(rect) { |
| 15 return "[" + rect.left + ", " + rect.right + ", " + rect.top + ", " + rect.bot
tom + "]"; |
| 16 } |
| 17 |
| 18 function entryToString(entry) { |
| 19 var ratio = ((entry.intersectionRect.width * entry.intersectionRect.height) / |
| 20 (entry.boundingClientRect.width * entry.boundingClientRect.height
)); |
| 21 return ( |
| 22 "boundingClientRect=" + rectToString(entry.boundingClientRect) + |
| 23 "\nintersectionRect=" + rectToString(entry.intersectionRect) + |
| 24 "\nvisibleRatio=" + ratio + |
| 25 "\nrootBounds=" + rectToString(entry.rootBounds) + |
| 26 "\ntarget=" + entry.target + |
| 27 "\ntime=" + entry.time); |
| 28 } |
| 29 |
| 30 function finishTest() { |
| 31 if (descriptionString) |
| 32 delayDescription(descriptionString); |
| 33 delayIsSuccessfullyParsed(); |
| 34 finishJSTest(); |
| 35 if (window.testRunner) |
| 36 testRunner.notifyDone(); |
| 37 } |
| 38 |
| 39 function rectToString(rect) { |
| 40 return "[" + rect.left + ", " + rect.right + ", " + rect.top + ", " + rect.bot
tom + "]"; |
| 41 } |
| 42 |
| 43 function checkRect(expected, actual) { |
| 44 shouldBeEqualToNumber(actual + ".left", expected[0]); |
| 45 shouldBeEqualToNumber(actual + ".right", expected[1]); |
| 46 shouldBeEqualToNumber(actual + ".top", expected[2]); |
| 47 shouldBeEqualToNumber(actual + ".bottom", expected[3]); |
| 48 } |
| 49 |
| 50 function checkEntry(expected, actual) { |
| 51 checkRect(expected['boundingClientRect'], actual + ".boundingClientRect"); |
| 52 checkRect(expected['intersectionRect'], actual + ".intersectionRect"); |
| 53 checkRect(expected['rootBounds'], actual + ".rootBounds"); |
| 54 var actual_target = eval(actual + ".target"); |
| 55 if (isResultCorrect(actual_target, expected['target'])) |
| 56 testPassed(actual + ".target is " + expected); |
| 57 else |
| 58 testFailed(actual + ".target should be " + stringify(expected) + ". Was " +
actual_target + "."); |
| 59 } |
| 60 |
| 61 function checkResults(expected, actual, startFrom = 0) { |
| 62 shouldBeEqualToNumber(actual + ".length", expected.length); |
| 63 var max = Math.min(eval(actual + ".length"), expected.length); |
| 64 for (var i = startFrom; i < max; i++) |
| 65 checkEntry(expected[i], actual + "[" + i + "]"); |
| 66 } |
OLD | NEW |