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 | |
esprehn
2015/12/12 00:14:12
hmmm...
| |
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) + | |
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.
| |
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) { | |
esprehn
2015/12/12 00:14:12
defined twice in this file
szager1
2015/12/16 19:15:33
Fixed.
| |
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"); | |
esprehn
2015/12/12 00:14:12
.boundingClientRect, why the backets?
szager1
2015/12/16 19:15:33
Fixed.
| |
52 checkRect(expected['intersectionRect'], actual + ".intersectionRect"); | |
esprehn
2015/12/12 00:14:12
ditto, why the brackets?
szager1
2015/12/16 19:15:33
Fixed.
| |
53 checkRect(expected['rootBounds'], actual + ".rootBounds"); | |
54 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
| |
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); | |
esprehn
2015/12/12 00:14:12
don't eval, the test should contain the statements
szager1
2015/12/16 19:15:33
Done.
| |
64 for (var i = startFrom; i < max; i++) | |
65 checkEntry(expected[i], actual + "[" + i + "]"); | |
66 } | |
OLD | NEW |