1 if (window.layoutTestController)
2 layoutTestController.dumpAsText();
4 function description(msg)
6 // For MSIE 6 compatibility
7 var span = document.createElement("span");
8 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>';
9 var description = document.getElementById("description");
10 if (description.firstChild)
11 description.replaceChild(span, description.firstChild);
13 description.appendChild(span);
18 var span = document.createElement("span");
19 span.innerHTML = msg + '<br>';
20 document.getElementById("console").appendChild(span);
23 function escapeHTML(text)
25 return text.replace(/&/g, "&").replace(/</g, "<");
28 function testPassed(msg)
30 debug('<span class="pass">PASS</span> ' + escapeHTML(msg) + '</span>');
33 function testFailed(msg)
35 debug('<span class="fail">FAIL</span> ' + escapeHTML(msg) + '</span>');
38 function areArraysEqual(_a, _b)
40 if (_a.length !== _b.length)
42 for (var i = 0; i < _a.length; i++)
48 function isResultCorrect(_actual, _expected)
50 if (_actual === _expected)
52 if (typeof(_expected) == "number" && isNaN(_expected))
53 return typeof(_actual) == "number" && isNaN(_actual);
54 if (Object.prototype.toString.call(_expected) == Object.prototype.toString.call([]))
55 return areArraysEqual(_actual, _expected);
59 function shouldBe(_a, _b)
61 if (typeof _a != "string" || typeof _b != "string")
62 debug("WARN: shouldBe() expects string arguments");
73 testFailed(_a + " should be " + _bv + ". Threw exception " + exception);
74 else if (isResultCorrect(_av, _bv))
75 testPassed(_a + " is " + _b);
76 else if (typeof(_av) == typeof(_bv))
77 testFailed(_a + " should be " + _bv + ". Was " + _av + ".");
79 testFailed(_a + " should be " + _bv + " (of type " + typeof _bv + "). Was " + _av + " (of type " + typeof _av + ").");
82 function shouldBeTrue(_a) { shouldBe(_a, "true"); }
83 function shouldBeFalse(_a) { shouldBe(_a, "false"); }
84 function shouldBeNaN(_a) { shouldBe(_a, "NaN"); }
86 function shouldBeUndefined(_a)
97 testFailed(_a + " should be undefined. Threw exception " + exception);
98 else if (typeof _av == "undefined")
99 testPassed(_a + " is undefined.");
101 testFailed(_a + " should be undefined. Was " + _av);
105 function shouldThrow(_a, _e)
120 if (typeof _e == "undefined" || exception == _ev)
121 testPassed(_a + " threw exception " + exception + ".");
123 testFailed(_a + " should throw exception " + _ev + ". Threw exception " + exception + ".");
124 } else if (typeof _av == "undefined")
125 testFailed(_a + " should throw exception " + _e + ". Was undefined.");
127 testFailed(_a + " should throw exception " + _e + ". Was " + _av + ".");