1 // svg/dynamic-updates tests set enablePixelTesting=true, as we want to dump text + pixel results
2 if (window
.testRunner
) {
3 if (window
.enablePixelTesting
)
4 testRunner
.dumpAsTextWithPixelResults();
6 testRunner
.dumpAsText();
9 function description(msg
)
11 // For MSIE 6 compatibility
12 var span
= document
.createElement("span");
13 span
.innerHTML
= '<p>' + msg
+ '</p><p>On success, you will see a series of "<span class="pass">PASS</span>" messages, followed by "<span class="pass">TEST COMPLETE</span>".</p>';
14 var description
= document
.getElementById("description");
15 if (description
.firstChild
)
16 description
.replaceChild(span
, description
.firstChild
);
18 description
.appendChild(span
);
23 var span
= document
.createElement("span");
24 document
.getElementById("console").appendChild(span
); // insert it first so XHTML knows the namespace
25 span
.innerHTML
= msg
+ '<br />';
28 function escapeHTML(text
)
30 return text
.replace(/&/g, "&").replace(/</g, "<").replace(/\0/g
, "\\0");
33 function testPassed(msg
)
35 debug('<span><span class="pass">PASS</span> ' + escapeHTML(msg
) + '</span>');
38 function testFailed(msg
)
40 debug('<span><span class="fail">FAIL</span> ' + escapeHTML(msg
) + '</span>');
43 function areArraysEqual(_a
, _b
)
46 if (_a
.length
!== _b
.length
)
48 for (var i
= 0; i
< _a
.length
; i
++)
57 function isMinusZero(n
)
59 // the only way to tell 0 from -0 in JS is the fact that 1/-0 is
60 // -Infinity instead of Infinity
61 return n
=== 0 && 1/n
< 0;
64 function isResultCorrect(_actual
, _expected
)
67 return _actual
=== _expected
&& (1/_actual) === (1/_expected
);
68 if (_actual
=== _expected
)
70 if (typeof(_expected
) == "number" && isNaN(_expected
))
71 return typeof(_actual
) == "number" && isNaN(_actual
);
72 if (Object
.prototype.toString
.call(_expected
) == Object
.prototype.toString
.call([]))
73 return areArraysEqual(_actual
, _expected
);
79 if (v
=== 0 && 1/v
< 0)
84 function evalAndLog(_a
)
86 if (typeof _a
!= "string")
87 debug("WARN: tryAndLog() expects a string argument");
89 // Log first in case things go horribly wrong or this causes a sync event.
96 testFailed(_a
+ " threw exception " + e
);
101 function shouldBe(_a
, _b
)
103 if (typeof _a
!= "string" || typeof _b
!= "string")
104 debug("WARN: shouldBe() expects string arguments");
115 testFailed(_a
+ " should be " + _bv
+ ". Threw exception " + exception
);
116 else if (isResultCorrect(_av
, _bv
))
117 testPassed(_a
+ " is " + _b
);
118 else if (typeof(_av
) == typeof(_bv
))
119 testFailed(_a
+ " should be " + _bv
+ ". Was " + stringify(_av
) + ".");
121 testFailed(_a
+ " should be " + _bv
+ " (of type " + typeof _bv
+ "). Was " + _av
+ " (of type " + typeof _av
+ ").");
124 function shouldBeTrue(_a
) { shouldBe(_a
, "true"); }
125 function shouldBeFalse(_a
) { shouldBe(_a
, "false"); }
126 function shouldBeNaN(_a
) { shouldBe(_a
, "NaN"); }
127 function shouldBeNull(_a
) { shouldBe(_a
, "null"); }
129 function shouldBeEqualToString(a
, b
)
131 var unevaledString
= '"' + b
.replace(/\\/g, "\\\\").replace(/"/g, "\"").replace(/\n/g, "\\n
").replace(/\r/g, "\\r
") + '"';
132 shouldBe(a, unevaledString);
135 function shouldEvaluateTo(actual, expected) {
136 // A general-purpose comparator. 'actual
' should be a string to be
137 // evaluated, as for shouldBe(). 'expected
' may be any type and will be
138 // used without being eval'ed
.
139 if (expected
== null) {
140 // Do this before the object test, since null is of type 'object'.
141 shouldBeNull(actual
);
142 } else if (typeof expected
== "undefined") {
143 shouldBeUndefined(actual
);
144 } else if (typeof expected
== "function") {
145 // All this fuss is to avoid the string-arg warning from shouldBe().
147 actualValue
= eval(actual
);
149 testFailed("Evaluating " + actual
+ ": Threw exception " + e
);
152 shouldBe("'" + actualValue
.toString().replace(/\n/g, "") + "'",
153 "'" + expected
.toString().replace(/\n/g, "") + "'");
154 } else if (typeof expected
== "object") {
155 shouldBeTrue(actual
+ " == '" + expected
+ "'");
156 } else if (typeof expected
== "string") {
157 shouldBe(actual
, expected
);
158 } else if (typeof expected
== "boolean") {
159 shouldBe("typeof " + actual
, "'boolean'");
161 shouldBeTrue(actual
);
163 shouldBeFalse(actual
);
164 } else if (typeof expected
== "number") {
165 shouldBe(actual
, stringify(expected
));
167 debug(expected
+ " is unknown type " + typeof expected
);
168 shouldBeTrue(actual
, "'" +expected
.toString() + "'");
172 function shouldBeNonZero(_a
)
183 testFailed(_a
+ " should be non-zero. Threw exception " + exception
);
185 testPassed(_a
+ " is non-zero.");
187 testFailed(_a
+ " should be non-zero. Was " + _av
);
190 function shouldBeNonNull(_a
)
201 testFailed(_a
+ " should be non-null. Threw exception " + exception
);
202 else if (_av
!= null)
203 testPassed(_a
+ " is non-null.");
205 testFailed(_a
+ " should be non-null. Was " + _av
);
208 function shouldBeUndefined(_a
)
219 testFailed(_a
+ " should be undefined. Threw exception " + exception
);
220 else if (typeof _av
== "undefined")
221 testPassed(_a
+ " is undefined.");
223 testFailed(_a
+ " should be undefined. Was " + _av
);
226 function shouldBeDefined(_a
)
237 testFailed(_a
+ " should be defined. Threw exception " + exception
);
238 else if (_av
!== undefined)
239 testPassed(_a
+ " is defined.");
241 testFailed(_a
+ " should be defined. Was " + _av
);
244 function shouldBeGreaterThanOrEqual(_a
, _b
) {
245 if (typeof _a
!= "string" || typeof _b
!= "string")
246 debug("WARN: shouldBeGreaterThanOrEqual expects string arguments");
258 testFailed(_a
+ " should be >= " + _b
+ ". Threw exception " + exception
);
259 else if (typeof _av
== "undefined" || _av
< _bv
)
260 testFailed(_a
+ " should be >= " + _b
+ ". Was " + _av
+ " (of type " + typeof _av
+ ").");
262 testPassed(_a
+ " is >= " + _b
);
265 function shouldThrowType(_a
, _e
)
276 if (exception
instanceof _e
)
277 testPassed(_a
+ " threw exception of type " + _e
.name
+ ".");
279 testFailed(_a
+ " should throw " + (typeof _e
== "undefined" ? "an exception" : _ev
) + ". Threw exception " + exception
+ ".");
281 testFailed(_a
+ " should throw an instance of " + _e
.name
);
285 if (typeof GCController
!== "undefined")
286 GCController
.collect();
291 var temp
= {i
: "ab" + i
+ (i
/ 100000)};
295 for (var i
= 0; i
< 1000; i
++)
300 // It's possible for an async test to call finishJSTest() before moz-test-post.js
302 function finishJSTest()
304 wasFinishJSTestCalled
= true;
305 if (!window
.wasPostTestScriptParsed
)
307 shouldBeTrue("successfullyParsed");
308 debug('<br /><span class="pass">TEST COMPLETE</span>');
309 if (window
.jsTestIsAsync
&& window
.testRunner
)
310 testRunner
.notifyDone();
316 debug
.apply(this, arguments
);
319 function assertEq(left
, right
, message
)
322 testPassed(left
+ " === " + right
);
326 testFailed("assertEq failed: " + left
+ "(of type " + (typeof left
) + ") !== " + right
+ "(of type " + (typeof right
) + ")");