Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5453)

Unified Diff: chrome/test/data/webui/webui_resource_test.js

Issue 17315020: Port passing closure tests for cr.ui framework to browser tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..0554d39385e8c375b1593c5bbce9c61b79b0bdf6 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,51 @@ function assertThrows(f) {
}
/**
+ * Verifies that a function evaluation does not throw an exception.
+ * @param {!Function} The test function.
+ */
arv (Not doing code reviews) 2013/06/20 14:26:24 This is generally not a useful assertion function
kevers 2013/06/20 14:59:28 Removed.
+function assertNotThrows(f) {
+ var triggeredError = false;
+ try {
+ f();
+ } catch(err) {
+ triggeredError = true;
+ console.log(err.stack);
+ }
+ if (triggeredError)
+ throw new Error('Assertion Failed: exception thrown.');
+}
+
+/**
+ * Verifies that the contents of the expected and observed arrays match.
+ * @param {Array.<Object>} expected The expected result.
arv (Not doing code reviews) 2013/06/20 14:26:24 {Array} since the array can contain any value
kevers 2013/06/20 14:59:28 Done.
+ * @param {Array.<Object>} observed The actual result.
+ */
+function assertArrayEquals(expected, observed) {
+ var v1 = Array.prototype.concat.call(expected);
+ var v2 = Array.prototype.concat.call(observed);
arv (Not doing code reviews) 2013/06/20 14:26:24 not concat... use slice. slice is generic, concat
kevers 2013/06/20 14:59:28 Done.
+ var equal = v1.length == v2.length;
+ if (equal) {
+ for (var i = 0; i < v1.length; i++) {
+ if (v1[i] !== v2[i]) {
+ equal = false;
+ break;
+ }
+ }
+ }
+ if (!equal) {
+ var message = 'Assertion Failed\n Observed: ' + v2 +
+ '\n Expected: ' + v1;
+ 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 +128,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);
}
« no previous file with comments | « chrome/test/data/webui/webui_resource_browsertest.cc ('k') | ui/webui/resources/js/cr/event_target_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698