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

Unified Diff: chrome/browser/resources/chromeos/chromevox/testing/chromevox_unittest_base.js

Issue 298653011: More ChromeVox tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update and temporarily remove one that doesn't pass anymore Created 6 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/browser/resources/chromeos/chromevox/testing/chromevox_unittest_base.js
diff --git a/chrome/browser/resources/chromeos/chromevox/testing/chromevox_unittest_base.js b/chrome/browser/resources/chromeos/chromevox/testing/chromevox_unittest_base.js
index 7030b1969578c7c836a256645258d5d4e5288fca..d2cb82a937563ebe2573ad17cc3a4b885901cc14 100644
--- a/chrome/browser/resources/chromeos/chromevox/testing/chromevox_unittest_base.js
+++ b/chrome/browser/resources/chromeos/chromevox/testing/chromevox_unittest_base.js
@@ -12,6 +12,71 @@ function $(id) {
}
/**
+ * Asserts that a given argument's value is undefined.
+ * @param {object} a The argument to check.
+ */
+function assertUndefined(a) {
+ if (a !== undefined) {
+ throw new Error('Assertion failed: expected undefined');
+ }
+}
+
+/**
+ * Asserts that a given function call raises an exception.
+ * @param {string} error The name of the exception we expect to throw.
+ * @param {Function} fn The function to call.
+ */
+function assertException(error, fn) {
+ try {
+ fn();
+ } catch (e) {
+ if (error && e.name != error) {
+ throw new Error('Expected to throw ' + error + ' but threw ' + e.name);
+ }
+
+ return true;
+ }
+
+ throw new Error('Expected to throw exception');
+}
+
+/**
+ * Assert that two arrays of strings are equal.
Peter Lundblad 2014/06/06 17:33:02 s/Assert/Asserts/
dmazzoni 2014/06/06 18:05:11 Done.
+ * @param {Array.<string>} array1 The expected array.
+ * @param {Array.<string>} array2 The test array.
+ */
+function assertEqualStringArrays(array1, array2) {
+ var same = true;
+ if (array1.length != array2.length) {
+ same = false;
+ }
+ for (var i = 0; i < Math.min(array1.length, array2.length); i++) {
+ if (array1[i].trim() != array2[i].trim()) {
+ same = false;
+ }
+ }
+ if (!same) {
+ throw new Error('Expected ' + JSON.stringify(array1) +
+ ', got ' + JSON.stringify(array2));
+ }
+}
+
+/**
+ * Assert that two objects have the same JSON serialization.
Peter Lundblad 2014/06/06 17:33:03 s/Assert/Asserts/
dmazzoni 2014/06/06 18:05:11 Done.
+ * @param {Object} obj1 The expected object.
+ * @param {Object} obj2 The actual object.
+ */
+function assertEqualsJSON(obj1, obj2) {
+ if (!eqJSON(obj1, obj2)) {
+ throw new Error('Expected ' + JSON.stringify(obj1) +
+ ', got ' + JSON.stringify(obj2));
+ }
+}
+
+assertSame = assertEquals;
+assertNotSame = assertNotEquals;
+
+/**
* Base test fixture for ChromeVox unit tests.
*
* Note that while conceptually these are unit tests, these tests need
@@ -30,9 +95,26 @@ ChromeVoxUnitTestBase.prototype = {
browsePreload: DUMMY_URL,
/**
+ * @override
+ * It doesn't make sense to run the accessibility audit on these tests,
+ * since many of them are deliberately testing inaccessible html.
+ */
+ runAccessibilityChecks: false,
+
+ /**
* Loads some inlined html into the current document, replacing
- * whatever was there previously. To use it, call it with the html
- * inside an inline comment, like this:
+ * whatever was there previously.
Peter Lundblad 2014/06/06 17:33:03 Document the argument.
dmazzoni 2014/06/06 18:05:11 Done.
+ */
+ loadHtml: function(html) {
+ document.open();
+ document.write(html);
+ document.close();
+ },
+
+ /**
+ * Loads some inlined html into the current document, replacing
+ * whatever was there previously. This version takes the html
+ * encoded as a comment inside a function, so you can use it like this:
*
* this.loadDoc(function() {/*!
* <p>Html goes here</p>
@@ -42,8 +124,6 @@ ChromeVoxUnitTestBase.prototype = {
var html = commentEncodedHtml.toString().
replace(/^[^\/]+\/\*!?/, '').
replace(/\*\/[^\/]+$/, '');
- document.open();
- document.write(html);
- document.close();
+ this.loadHtml(html);
}
};

Powered by Google App Engine
This is Rietveld 408576698