Index: chrome/test/data/webui/webui_resource_test.js |
diff --git a/chrome/test/data/webui/webui_resource_test.js b/chrome/test/data/webui/webui_resource_test.js |
index 1cd3aececc419ad5a203ebd29e5c470051e5fc48..485b3dbbb51692dbf9cfdd4de7c2409b926d79f5 100644 |
--- a/chrome/test/data/webui/webui_resource_test.js |
+++ b/chrome/test/data/webui/webui_resource_test.js |
@@ -57,7 +57,7 @@ function assertNotEqual(reference, observed, opt_message) { |
} |
/** |
- * Verifies that a test evaluation results in an assertion failure. |
+ * Verifies that a test evaluation results in an exception. |
* @param {!Function} f The test function. |
*/ |
function assertThrows(f) { |
@@ -72,15 +72,35 @@ function assertThrows(f) { |
} |
/** |
+ * Verifies that the contents of the expected and observed arrays match. |
+ * @param {Array} expected The expected result. |
+ * @param {Array} observed The actual result. |
+ */ |
+function assertArrayEquals(expected, observed) { |
+ var v1 = Array.prototype.slice.call(expected); |
+ var v2 = Array.prototype.slice.call(observed); |
+ var equal = v1.length == v2.length; |
+ if (equal) { |
+ for (var i = 0; i < v1.length; i++) { |
+ if (v1[i] !== v2[i]) { |
Dan Beam
2013/06/20 17:57:46
what if v1[i] is a (non-null) object or array? sh
arv (Not doing code reviews)
2013/06/20 18:35:33
We should not recurse. Recursion should be done in
|
+ equal = false; |
+ break; |
+ } |
+ } |
+ } |
+ if (!equal) { |
+ var message = 'Assertion Failed\n Observed: ' + v2 + |
+ '\n Expected: ' + v1; |
Dan Beam
2013/06/20 17:57:46
nit:
var message =
['Assertion Failed', 'Obser
kevers
2013/06/20 18:41:37
Done.
|
+ throw new Error(message); |
+ } |
+} |
+ |
+/** |
* Runs all functions starting with test and reports success or |
* failure of the test suite. |
*/ |
function runTests() { |
var tests = []; |
- |
- if (window.setUp) |
- window.setUp(); |
- |
var success = true; |
for (var name in window) { |
if (typeof window[name] == 'function' && /^test/.test(name)) |
@@ -92,17 +112,17 @@ function runTests() { |
} |
for (var i = 0; i < tests.length; i++) { |
try { |
+ if (window.setUp) |
+ window.setUp(); |
window[tests[i]](); |
} catch (err) { |
console.error('Failure in test ' + tests[i] + '\n' + err); |
console.log(err.stack); |
success = false; |
} |
+ if (window.tearDown) |
+ window.tearDown(); |
} |
- |
- if (window.tearDown) |
- window.tearDown(); |
- |
endTests(success); |
} |