OLD | NEW |
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 /** | 69 /** |
70 * C++ gtest macro to use for TEST_F depending on |testType|. | 70 * C++ gtest macro to use for TEST_F depending on |testType|. |
71 * @type {string} ('TEST_F'|'IN_PROC_BROWSER_TEST_F') | 71 * @type {string} ('TEST_F'|'IN_PROC_BROWSER_TEST_F') |
72 */ | 72 */ |
73 var testF; | 73 var testF; |
74 | 74 |
75 /** | 75 /** |
76 * Keeps track of whether a typedef has been generated for each test | 76 * Keeps track of whether a typedef has been generated for each test |
77 * fixture. | 77 * fixture. |
78 * @type {Object.<string, string>} | 78 * @type {Object<string, string>} |
79 */ | 79 */ |
80 var typedeffedCppFixtures = {}; | 80 var typedeffedCppFixtures = {}; |
81 | 81 |
82 /** | 82 /** |
83 * Maintains a list of relative file paths to add to each gtest body | 83 * Maintains a list of relative file paths to add to each gtest body |
84 * for inclusion at runtime before running each JavaScript test. | 84 * for inclusion at runtime before running each JavaScript test. |
85 * @type {Array.<string>} | 85 * @type {Array<string>} |
86 */ | 86 */ |
87 var genIncludes = []; | 87 var genIncludes = []; |
88 | 88 |
89 /** | 89 /** |
90 * When true, add calls to set_preload_test_(fixture|name). This is needed when | 90 * When true, add calls to set_preload_test_(fixture|name). This is needed when |
91 * |testType| === 'webui' to send an injection message before the page loads, | 91 * |testType| === 'webui' to send an injection message before the page loads, |
92 * but is not required or supported by any other test type. | 92 * but is not required or supported by any other test type. |
93 * @type {boolean} | 93 * @type {boolean} |
94 */ | 94 */ |
95 var addSetPreloadInfo; | 95 var addSetPreloadInfo; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 return { | 174 return { |
175 path: jsFile.replace(/[^\/\\]+$/, includeFile), | 175 path: jsFile.replace(/[^\/\\]+$/, includeFile), |
176 base: jsFileBase.replace(/[^\/\\]+$/, includeFile), | 176 base: jsFileBase.replace(/[^\/\\]+$/, includeFile), |
177 }; | 177 }; |
178 } | 178 } |
179 | 179 |
180 | 180 |
181 /** | 181 /** |
182 * Maps object names to the path to the file that provides them. | 182 * Maps object names to the path to the file that provides them. |
183 * Populated from the |depsFile| if any. | 183 * Populated from the |depsFile| if any. |
184 * @type {Object.<string, string>} | 184 * @type {Object<string, string>} |
185 */ | 185 */ |
186 var dependencyProvidesToPaths = {}; | 186 var dependencyProvidesToPaths = {}; |
187 | 187 |
188 /** | 188 /** |
189 * Maps dependency path names to object names required by the file. | 189 * Maps dependency path names to object names required by the file. |
190 * Populated from the |depsFile| if any. | 190 * Populated from the |depsFile| if any. |
191 * @type {Object.<string, Array.<string>>} | 191 * @type {Object<string, Array<string>>} |
192 */ | 192 */ |
193 var dependencyPathsToRequires = {}; | 193 var dependencyPathsToRequires = {}; |
194 | 194 |
195 if (depsFile) { | 195 if (depsFile) { |
196 var goog = goog || {}; | 196 var goog = goog || {}; |
197 /** | 197 /** |
198 * Called by the javascript in the deps file to add modules and their | 198 * Called by the javascript in the deps file to add modules and their |
199 * dependencies. | 199 * dependencies. |
200 * @param {string} path Relative path to the file. | 200 * @param {string} path Relative path to the file. |
201 * @param Array.<string> provides Objects provided by this file. | 201 * @param Array<string> provides Objects provided by this file. |
202 * @param Array.<string> requires Objects required by this file. | 202 * @param Array<string> requires Objects required by this file. |
203 */ | 203 */ |
204 goog.addDependency = function(path, provides, requires) { | 204 goog.addDependency = function(path, provides, requires) { |
205 provides.forEach(function(provide) { | 205 provides.forEach(function(provide) { |
206 dependencyProvidesToPaths[provide] = path; | 206 dependencyProvidesToPaths[provide] = path; |
207 }); | 207 }); |
208 dependencyPathsToRequires[path] = requires; | 208 dependencyPathsToRequires[path] = requires; |
209 }; | 209 }; |
210 | 210 |
211 // Read and eval the deps file. It should only contain goog.addDependency | 211 // Read and eval the deps file. It should only contain goog.addDependency |
212 // calls. | 212 // calls. |
213 eval(read(depsFile)); | 213 eval(read(depsFile)); |
214 } | 214 } |
215 | 215 |
216 /** | 216 /** |
217 * Resolves a list of libraries to an ordered list of paths to load by the | 217 * Resolves a list of libraries to an ordered list of paths to load by the |
218 * generated C++. The input should contain object names provided | 218 * generated C++. The input should contain object names provided |
219 * by the deps file. Dependencies will be resolved and included in the | 219 * by the deps file. Dependencies will be resolved and included in the |
220 * correct order, meaning that the returned array may contain more entries | 220 * correct order, meaning that the returned array may contain more entries |
221 * than the input. | 221 * than the input. |
222 * @param {Array.<string>} deps List of dependencies. | 222 * @param {Array<string>} deps List of dependencies. |
223 * @return {Array.<string>} List of paths to load. | 223 * @return {Array<string>} List of paths to load. |
224 */ | 224 */ |
225 function resolveClosureModuleDeps(deps) { | 225 function resolveClosureModuleDeps(deps) { |
226 if (!depsFile && deps.length > 0) { | 226 if (!depsFile && deps.length > 0) { |
227 print('Can\'t have closure dependencies without a deps file.'); | 227 print('Can\'t have closure dependencies without a deps file.'); |
228 quit(-1); | 228 quit(-1); |
229 } | 229 } |
230 var resultPaths = []; | 230 var resultPaths = []; |
231 var addedPaths = {}; | 231 var addedPaths = {}; |
232 | 232 |
233 function addPath(path) { | 233 function addPath(path) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 replace(/\s+$/, ''); | 295 replace(/\s+$/, ''); |
296 GEN(code); | 296 GEN(code); |
297 } | 297 } |
298 | 298 |
299 /** | 299 /** |
300 * Generate includes for the current |jsFile| by including them | 300 * Generate includes for the current |jsFile| by including them |
301 * immediately and at runtime. | 301 * immediately and at runtime. |
302 * The paths are allowed to be: | 302 * The paths are allowed to be: |
303 * 1. relative to the root src directory (i.e. similar to #include's). | 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. | 304 * 2. relative to the directory specified in the GYP rule for the file. |
305 * @param {Array.<string>} includes Paths to JavaScript files to | 305 * @param {Array<string>} includes Paths to JavaScript files to |
306 * include immediately and at runtime. | 306 * include immediately and at runtime. |
307 */ | 307 */ |
308 function GEN_INCLUDE(includes) { | 308 function GEN_INCLUDE(includes) { |
309 for (var i = 0; i < includes.length; i++) { | 309 for (var i = 0; i < includes.length; i++) { |
310 var includePaths = includeFileToPaths(includes[i]); | 310 var includePaths = includeFileToPaths(includes[i]); |
311 var js = read(includePaths.path); | 311 var js = read(includePaths.path); |
312 ('global', eval)(js); | 312 ('global', eval)(js); |
313 genIncludes.push(includePaths.base); | 313 genIncludes.push(includePaths.base); |
314 } | 314 } |
315 } | 315 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 '"' + testFunction + '"));'); | 368 '"' + testFunction + '"));'); |
369 if (testGenPostamble) | 369 if (testGenPostamble) |
370 testGenPostamble(testFixture, testFunction); | 370 testGenPostamble(testFixture, testFunction); |
371 print('}'); | 371 print('}'); |
372 print(); | 372 print(); |
373 } | 373 } |
374 | 374 |
375 // Now that generation functions are defined, load in |jsFile|. | 375 // Now that generation functions are defined, load in |jsFile|. |
376 var js = read(jsFile); | 376 var js = read(jsFile); |
377 eval(js); | 377 eval(js); |
OLD | NEW |