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

Unified Diff: chrome/test/base/js2gtest.js

Issue 1145243006: Port chromevox build to GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@externs
Patch Set: Unshare some vars, add TODO for the rest. Created 5 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/base/js2gtest.js
diff --git a/chrome/test/base/js2gtest.js b/chrome/test/base/js2gtest.js
index 41a54d5bb4e35a47b67980ec628900b6f7a29b0a..fcde0e35b526e24e7d96e4be408c7562756f3b41 100644
--- a/chrome/test/base/js2gtest.js
+++ b/chrome/test/base/js2gtest.js
@@ -36,13 +36,6 @@ 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?}
*/
@@ -153,27 +146,24 @@ function maybeGenHeader(testFixture) {
/**
+ * @type {Array<{path: string, base: string>}
+ */
+var pathStack = [];
+
+
+/**
* Convert the |includeFile| to paths appropriate for immediate
* inclusion (path) and runtime inclusion (base).
* @param {string} includeFile The file to include.
* @return {{path: string, base: string}} Object describing the paths
* for |includeFile|. |path| is relative to cwd; |base| is relative to
- * source root.
+ * 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).
+ paths = pathStack[pathStack.length - 1];
return {
- path: jsFile.replace(/[^\/\\]+$/, includeFile),
- base: jsFileBase.replace(/[^\/\\]+$/, includeFile),
+ path: paths.path.replace(/[^\/\\]+$/, includeFile),
+ base: paths.base.replace(/[^\/\\]+$/, includeFile),
};
}
@@ -299,9 +289,7 @@ 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.
+ * The paths must be relative to the directory of the current file.
* @param {Array<string>} includes Paths to JavaScript files to
* include immediately and at runtime.
*/
@@ -309,7 +297,9 @@ function GEN_INCLUDE(includes) {
for (var i = 0; i < includes.length; i++) {
var includePaths = includeFileToPaths(includes[i]);
var js = read(includePaths.path);
+ pathStack.push(includePaths);
('global', eval)(js);
+ pathStack.pop();
genIncludes.push(includePaths.base);
}
}
@@ -374,4 +364,6 @@ function TEST_F(testFixture, testFunction, testBody) {
// Now that generation functions are defined, load in |jsFile|.
var js = read(jsFile);
+pathStack.push({path: jsFile, base: jsFileBase});
eval(js);
+pathStack.pop();

Powered by Google App Engine
This is Rietveld 408576698