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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Generator script for creating gtest-style JavaScript 6 * @fileoverview Generator script for creating gtest-style JavaScript
7 * tests for extensions, WebUI and unit tests. Generates C++ gtest wrappers 7 * tests for extensions, WebUI and unit tests. Generates C++ gtest wrappers
8 * which will invoke the appropriate JavaScript for each test. 8 * which will invoke the appropriate JavaScript for each test.
9 * @author scr@chromium.org (Sheridan Rawlins) 9 * @author scr@chromium.org (Sheridan Rawlins)
10 * @see WebUI testing: http://goo.gl/ZWFXF 10 * @see WebUI testing: http://goo.gl/ZWFXF
(...skipping 18 matching lines...) Expand all
29 var jsFile = arguments[1]; 29 var jsFile = arguments[1];
30 30
31 /** 31 /**
32 * Relative path to the test input file appropriate for use in the 32 * Relative path to the test input file appropriate for use in the
33 * C++ TestFixture's addLibrary method. 33 * C++ TestFixture's addLibrary method.
34 * @type {string} 34 * @type {string}
35 */ 35 */
36 var jsFileBase = arguments[2]; 36 var jsFileBase = arguments[2];
37 37
38 /** 38 /**
39 * The cwd, as determined by the paths of |jsFile| and |jsFileBase|.
40 * This is usually relative to the root source directory and points to the
41 * directory where the GYP rule processing the js file lives.
42 */
43 var jsDirBase = jsFileBase.replace(jsFile, '');
44
45 /**
46 * Path to Closure library style deps.js file. 39 * Path to Closure library style deps.js file.
47 * @type {string?} 40 * @type {string?}
48 */ 41 */
49 var depsFile = arguments[3]; 42 var depsFile = arguments[3];
50 43
51 /** 44 /**
52 * Path to C++ file generation is outputting to. 45 * Path to C++ file generation is outputting to.
53 * @type {string} 46 * @type {string}
54 */ 47 */
55 var outputFile = arguments[4]; 48 var outputFile = arguments[4];
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 139 }
147 print('#include "url/gurl.h"'); 140 print('#include "url/gurl.h"');
148 print('#include "testing/gtest/include/gtest/gtest.h"'); 141 print('#include "testing/gtest/include/gtest/gtest.h"');
149 if (testFixture && this[testFixture].prototype.testGenCppIncludes) 142 if (testFixture && this[testFixture].prototype.testGenCppIncludes)
150 this[testFixture].prototype.testGenCppIncludes(); 143 this[testFixture].prototype.testGenCppIncludes();
151 print(); 144 print();
152 } 145 }
153 146
154 147
155 /** 148 /**
149 * @type {Array<{path: string, base: string>}
150 */
151 var pathStack = [];
152
153
154 /**
156 * Convert the |includeFile| to paths appropriate for immediate 155 * Convert the |includeFile| to paths appropriate for immediate
157 * inclusion (path) and runtime inclusion (base). 156 * inclusion (path) and runtime inclusion (base).
158 * @param {string} includeFile The file to include. 157 * @param {string} includeFile The file to include.
159 * @return {{path: string, base: string}} Object describing the paths 158 * @return {{path: string, base: string}} Object describing the paths
160 * for |includeFile|. |path| is relative to cwd; |base| is relative to 159 * for |includeFile|. |path| is relative to cwd; |base| is relative to
161 * source root. 160 * source root.
162 */ 161 */
163 function includeFileToPaths(includeFile) { 162 function includeFileToPaths(includeFile) {
164 if (includeFile.indexOf(jsDirBase) == 0) { 163 paths = pathStack[pathStack.length - 1];
165 // The caller supplied a path relative to root source.
166 var relPath = includeFile.replace(jsDirBase, '');
167 return {
168 path: relPath,
169 base: jsDirBase + relPath
170 };
171 }
172
173 // The caller supplied a path relative to the input js file's directory (cwd).
174 return { 164 return {
175 path: jsFile.replace(/[^\/\\]+$/, includeFile), 165 path: paths.path.replace(/[^\/\\]+$/, includeFile),
176 base: jsFileBase.replace(/[^\/\\]+$/, includeFile), 166 base: paths.base.replace(/[^\/\\]+$/, includeFile),
177 }; 167 };
178 } 168 }
179 169
180 170
181 /** 171 /**
182 * Maps object names to the path to the file that provides them. 172 * Maps object names to the path to the file that provides them.
183 * Populated from the |depsFile| if any. 173 * Populated from the |depsFile| if any.
184 * @type {Object<string>} 174 * @type {Object<string>}
185 */ 175 */
186 var dependencyProvidesToPaths = {}; 176 var dependencyProvidesToPaths = {};
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 replace(/^[^\/]+\/\*!?/, ''). 282 replace(/^[^\/]+\/\*!?/, '').
293 replace(/\*\/[^\/]+$/, ''). 283 replace(/\*\/[^\/]+$/, '').
294 replace(/^\n|\n$/, ''). 284 replace(/^\n|\n$/, '').
295 replace(/\s+$/, ''); 285 replace(/\s+$/, '');
296 GEN(code); 286 GEN(code);
297 } 287 }
298 288
299 /** 289 /**
300 * Generate includes for the current |jsFile| by including them 290 * Generate includes for the current |jsFile| by including them
301 * immediately and at runtime. 291 * immediately and at runtime.
302 * The paths are allowed to be: 292 * The paths must be relative to the directory of the current file.
303 * 1. relative to the root src directory (i.e. similar to #include's).
304 * 2. relative to the directory specified in the GYP rule for the file.
305 * @param {Array<string>} includes Paths to JavaScript files to 293 * @param {Array<string>} includes Paths to JavaScript files to
306 * include immediately and at runtime. 294 * include immediately and at runtime.
307 */ 295 */
308 function GEN_INCLUDE(includes) { 296 function GEN_INCLUDE(includes) {
309 for (var i = 0; i < includes.length; i++) { 297 for (var i = 0; i < includes.length; i++) {
310 var includePaths = includeFileToPaths(includes[i]); 298 var includePaths = includeFileToPaths(includes[i]);
311 var js = read(includePaths.path); 299 var js = read(includePaths.path);
300 pathStack.push(includePaths);
312 ('global', eval)(js); 301 ('global', eval)(js);
302 pathStack.pop();
313 genIncludes.push(includePaths.base); 303 genIncludes.push(includePaths.base);
314 } 304 }
315 } 305 }
316 306
317 /** 307 /**
318 * Generate gtest-style TEST_F definitions for C++ with a body that 308 * Generate gtest-style TEST_F definitions for C++ with a body that
319 * will invoke the |testBody| for |testFixture|.|testFunction|. 309 * will invoke the |testBody| for |testFixture|.|testFunction|.
320 * @param {string} testFixture The name of this test's fixture. 310 * @param {string} testFixture The name of this test's fixture.
321 * @param {string} testFunction The name of this test's function. 311 * @param {string} testFunction The name of this test's function.
322 * @param {Function} testBody The function body to execute for this test. 312 * @param {Function} testBody The function body to execute for this test.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 '"' + testFixture + '", ' + 357 '"' + testFixture + '", ' +
368 '"' + testFunction + '"));'); 358 '"' + testFunction + '"));');
369 if (testGenPostamble) 359 if (testGenPostamble)
370 testGenPostamble(testFixture, testFunction); 360 testGenPostamble(testFixture, testFunction);
371 print('}'); 361 print('}');
372 print(); 362 print();
373 } 363 }
374 364
375 // Now that generation functions are defined, load in |jsFile|. 365 // Now that generation functions are defined, load in |jsFile|.
376 var js = read(jsFile); 366 var js = read(jsFile);
367 pathStack.push({path: jsFile, base: jsFileBase});
377 eval(js); 368 eval(js);
369 pathStack.pop();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698