summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordtseng@chromium.org <dtseng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-23 22:22:45 +0000
committerdtseng@chromium.org <dtseng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-23 22:22:45 +0000
commit59c4c2d1d830a216e56e039ab489d479f69eb1c5 (patch)
treeb3e2502d84cd3641d67fb99972adc9a14dc22bc8
parent4c33a9bb794b2dcb1b251c5354b5d6d9721f68d9 (diff)
downloadchromium_src-59c4c2d1d830a216e56e039ab489d479f69eb1c5.zip
chromium_src-59c4c2d1d830a216e56e039ab489d479f69eb1c5.tar.gz
chromium_src-59c4c2d1d830a216e56e039ab489d479f69eb1c5.tar.bz2
Allow for C++ style GEN_INCLUDE path sematnics.
Review URL: https://codereview.chromium.org/342483005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279199 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/resources/chromeos/chromevox/testing/chromevox_unittest_base.js71
-rw-r--r--chrome/test/base/js2gtest.js23
2 files changed, 25 insertions, 69 deletions
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 ff3e3ff..e2e81dd 100644
--- a/chrome/browser/resources/chromeos/chromevox/testing/chromevox_unittest_base.js
+++ b/chrome/browser/resources/chromeos/chromevox/testing/chromevox_unittest_base.js
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+GEN_INCLUDE([
+ 'chrome/browser/resources/chromeos/chromevox/testing/assert_additions.js']);
+
/**
* Shortcut for document.getElementById.
* @param {string} id of the element.
@@ -12,74 +15,6 @@ 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} msg The message to print if this fails.
- * @param {Function} fn The function to call.
- * @param {string} error The name of the exception we expect to throw.
- * @return {boolean} True if it throws the exception.
- */
-function assertException(msg, fn, error) {
- try {
- fn();
- } catch (e) {
- if (error && e.name != error) {
- throw new Error('Expected to throw ' + error + ' but threw ' + e.name +
- ' - ' + msg);
- }
-
- return true;
- }
-
- throw new Error('Expected to throw exception');
-}
-
-/**
- * Asserts that two arrays of strings are equal.
- * @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));
- }
-}
-
-/**
- * Asserts that two objects have the same JSON serialization.
- * @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
diff --git a/chrome/test/base/js2gtest.js b/chrome/test/base/js2gtest.js
index 1aba2ff..c20b934 100644
--- a/chrome/test/base/js2gtest.js
+++ b/chrome/test/base/js2gtest.js
@@ -36,6 +36,13 @@ var jsFile = arguments[1];
var jsFileBase = arguments[2];
/**
+ * The cwd, as determined by the paths of |jsFile| and |jsFileBase|.
+ * This is usually relative to the root source directory and points to the
+ * directory where the GYP rule processing the js file lives.
+ */
+var jsDirBase = jsFileBase.replace(jsFile, '');
+
+/**
* Path to Closure library style deps.js file.
* @type {string?}
*/
@@ -150,9 +157,20 @@ function maybeGenHeader(testFixture) {
* inclusion (path) and runtime inclusion (base).
* @param {string} includeFile The file to include.
* @return {{path: string, base: string}} Object describing the paths
- * for |includeFile|.
+ * for |includeFile|. |path| is relative to cwd; |base| is relative to
+ * source root.
*/
function includeFileToPaths(includeFile) {
+ if (includeFile.indexOf(jsDirBase) == 0) {
+ // The caller supplied a path relative to root source.
+ var relPath = includeFile.replace(jsDirBase, '');
+ return {
+ path: relPath,
+ base: jsDirBase + relPath
+ };
+ }
+
+ // The caller supplied a path relative to the input js file's directory (cwd).
return {
path: jsFile.replace(/[^\/\\]+$/, includeFile),
base: jsFileBase.replace(/[^\/\\]+$/, includeFile),
@@ -281,6 +299,9 @@ function GEN_BLOCK(commentEncodedCode) {
/**
* Generate includes for the current |jsFile| by including them
* immediately and at runtime.
+ * The paths are allowed to be:
+ * 1. relative to the root src directory (i.e. similar to #include's).
+ * 2. relative to the directory specified in the GYP rule for the file.
* @param {Array.<string>} includes Paths to JavaScript files to
* include immediately and at runtime.
*/