OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 WebUI and unit tests. Generates C++ gtest wrappers | 7 * tests for 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 */ | 59 */ |
60 var typedeffedCppFixtures = {}; | 60 var typedeffedCppFixtures = {}; |
61 | 61 |
62 /** | 62 /** |
63 * Maintains a list of relative file paths to add to each gtest body | 63 * Maintains a list of relative file paths to add to each gtest body |
64 * for inclusion at runtime before running each JavaScript test. | 64 * for inclusion at runtime before running each JavaScript test. |
65 * @type {Array.<string>} | 65 * @type {Array.<string>} |
66 */ | 66 */ |
67 var genIncludes = []; | 67 var genIncludes = []; |
68 | 68 |
69 /** | |
70 * When true, add calls to set_preload_test_(fixture|name). | |
James Hawkins
2011/11/22 23:03:29
Document the rationale.
Sheridan Rawlins
2011/11/23 20:10:07
Done.
| |
71 * @type {boolean} | |
72 */ | |
73 var addSetPreloadInfo; | |
74 | |
69 // Generate the file to stdout. | 75 // Generate the file to stdout. |
70 print('// GENERATED FILE'); | 76 print('// GENERATED FILE'); |
71 print('// ' + arguments.join(' ')); | 77 print('// ' + arguments.join(' ')); |
72 print('// PLEASE DO NOT HAND EDIT!'); | 78 print('// PLEASE DO NOT HAND EDIT!'); |
73 print(); | 79 print(); |
74 | 80 |
75 // Output some C++ headers based upon the |testType|. | 81 // Output some C++ headers based upon the |testType|. |
76 // | 82 // |
77 // Currently supports: | 83 // Currently supports: |
78 // 'unit' - unit_tests harness, js2unit rule, V8UnitTest superclass. | 84 // 'unit' - unit_tests harness, js2unit rule, V8UnitTest superclass. |
79 // 'webui' - browser_tests harness, js2webui rule, WebUIBrowserTest superclass. | 85 // 'webui' - browser_tests harness, js2webui rule, WebUIBrowserTest superclass. |
80 if (testType === 'unit') { | 86 if (testType === 'unit') { |
81 print('#include "chrome/test/base/v8_unit_test.h"'); | 87 print('#include "chrome/test/base/v8_unit_test.h"'); |
82 testing.Test.prototype.typedefCppFixture = 'V8UnitTest'; | 88 testing.Test.prototype.typedefCppFixture = 'V8UnitTest'; |
83 testF = 'TEST_F'; | 89 testF = 'TEST_F'; |
90 addSetPreloadInfo = false; | |
84 } else { | 91 } else { |
85 print('#include "chrome/browser/ui/webui/web_ui_browsertest.h"'); | 92 print('#include "chrome/browser/ui/webui/web_ui_browsertest.h"'); |
86 testing.Test.prototype.typedefCppFixture = 'WebUIBrowserTest'; | 93 testing.Test.prototype.typedefCppFixture = 'WebUIBrowserTest'; |
87 testF = 'IN_PROC_BROWSER_TEST_F'; | 94 testF = 'IN_PROC_BROWSER_TEST_F'; |
95 addSetPreloadInfo = true; | |
88 } | 96 } |
89 print('#include "googleurl/src/gurl.h"'); | 97 print('#include "googleurl/src/gurl.h"'); |
90 print('#include "testing/gtest/include/gtest/gtest.h"'); | 98 print('#include "testing/gtest/include/gtest/gtest.h"'); |
91 print(); | 99 print(); |
92 | 100 |
93 /** | 101 /** |
94 * Convert the |includeFile| to paths appropriate for immediate | 102 * Convert the |includeFile| to paths appropriate for immediate |
95 * inclusion (path) and runtime inclusion (base). | 103 * inclusion (path) and runtime inclusion (base). |
96 * @param {string} includeFile The file to include. | 104 * @param {string} includeFile The file to include. |
97 * @return {{path: string, base: string}} Object describing the paths | 105 * @return {{path: string, base: string}} Object describing the paths |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 function(includeFile) { | 157 function(includeFile) { |
150 return includeFileToPaths(includeFile).base; | 158 return includeFileToPaths(includeFile).base; |
151 })); | 159 })); |
152 | 160 |
153 if (typedefCppFixture && !(testFixture in typedeffedCppFixtures)) { | 161 if (typedefCppFixture && !(testFixture in typedeffedCppFixtures)) { |
154 print('typedef ' + typedefCppFixture + ' ' + testFixture + ';'); | 162 print('typedef ' + typedefCppFixture + ' ' + testFixture + ';'); |
155 typedeffedCppFixtures[testFixture] = typedefCppFixture; | 163 typedeffedCppFixtures[testFixture] = typedefCppFixture; |
156 } | 164 } |
157 | 165 |
158 print(testF + '(' + testFixture + ', ' + testFunction + ') {'); | 166 print(testF + '(' + testFixture + ', ' + testFunction + ') {'); |
159 if (testGenPreamble) | |
160 testGenPreamble(testFixture, testFunction); | |
161 for (var i = 0; i < extraLibraries.length; i++) { | 167 for (var i = 0; i < extraLibraries.length; i++) { |
162 print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + | 168 print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + |
163 extraLibraries[i].replace(/\\/g, '/') + '")));'); | 169 extraLibraries[i].replace(/\\/g, '/') + '")));'); |
164 } | 170 } |
165 print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + | 171 print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + |
166 jsFileBase.replace(/\\/g, '/') + '")));'); | 172 jsFileBase.replace(/\\/g, '/') + '")));'); |
167 if (browsePreload) { | 173 if (addSetPreloadInfo) { |
168 print(' BrowsePreload(GURL("' + browsePreload + '"), "' + testFixture + | 174 print(' set_preload_test_fixture("' + testFixture + '");'); |
169 '", "' + testFunction + '");'); | 175 print(' set_preload_test_name("' + testFunction + '");'); |
170 } | 176 } |
177 if (testGenPreamble) | |
178 testGenPreamble(testFixture, testFunction); | |
179 if (browsePreload) | |
180 print(' BrowsePreload(GURL("' + browsePreload + '"));'); | |
171 if (browsePrintPreload) { | 181 if (browsePrintPreload) { |
172 print(' BrowsePrintPreload(GURL(WebUITestDataPathToURL(\n' + | 182 print(' BrowsePrintPreload(GURL(WebUITestDataPathToURL(\n' + |
173 ' FILE_PATH_LITERAL("' + browsePrintPreload + '"))),\n' + | 183 ' FILE_PATH_LITERAL("' + browsePrintPreload + '"))));'); |
174 ' "' + testFixture + '", "' + testFunction + '");'); | |
175 } | 184 } |
176 print(' ' + testPredicate + '(RunJavascriptTestF(' + isAsyncParam + | 185 print(' ' + testPredicate + '(RunJavascriptTestF(' + isAsyncParam + |
177 '"' + testFixture + '", ' + | 186 '"' + testFixture + '", ' + |
178 '"' + testFunction + '"));'); | 187 '"' + testFunction + '"));'); |
179 if (testGenPostamble) | 188 if (testGenPostamble) |
180 testGenPostamble(testFixture, testFunction); | 189 testGenPostamble(testFixture, testFunction); |
181 print('}'); | 190 print('}'); |
182 print(); | 191 print(); |
183 } | 192 } |
184 | 193 |
185 // Now that generation functions are defined, load in |jsFile|. | 194 // Now that generation functions are defined, load in |jsFile|. |
186 var js = read(jsFile); | 195 var js = read(jsFile); |
187 eval(js); | 196 eval(js); |
OLD | NEW |