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). This is needed when |
| 71 * |testType| === 'browser' to send an injection message before the page loads, |
| 72 * but is not required or supported for |testType| === 'unit'. |
| 73 * @type {boolean} |
| 74 */ |
| 75 var addSetPreloadInfo; |
| 76 |
69 // Generate the file to stdout. | 77 // Generate the file to stdout. |
70 print('// GENERATED FILE'); | 78 print('// GENERATED FILE'); |
71 print('// ' + arguments.join(' ')); | 79 print('// ' + arguments.join(' ')); |
72 print('// PLEASE DO NOT HAND EDIT!'); | 80 print('// PLEASE DO NOT HAND EDIT!'); |
73 print(); | 81 print(); |
74 | 82 |
75 // Output some C++ headers based upon the |testType|. | 83 // Output some C++ headers based upon the |testType|. |
76 // | 84 // |
77 // Currently supports: | 85 // Currently supports: |
78 // 'unit' - unit_tests harness, js2unit rule, V8UnitTest superclass. | 86 // 'unit' - unit_tests harness, js2unit rule, V8UnitTest superclass. |
79 // 'webui' - browser_tests harness, js2webui rule, WebUIBrowserTest superclass. | 87 // 'webui' - browser_tests harness, js2webui rule, WebUIBrowserTest superclass. |
80 if (testType === 'unit') { | 88 if (testType === 'unit') { |
81 print('#include "chrome/test/base/v8_unit_test.h"'); | 89 print('#include "chrome/test/base/v8_unit_test.h"'); |
82 testing.Test.prototype.typedefCppFixture = 'V8UnitTest'; | 90 testing.Test.prototype.typedefCppFixture = 'V8UnitTest'; |
83 testF = 'TEST_F'; | 91 testF = 'TEST_F'; |
| 92 addSetPreloadInfo = false; |
84 } else { | 93 } else { |
85 print('#include "chrome/browser/ui/webui/web_ui_browsertest.h"'); | 94 print('#include "chrome/browser/ui/webui/web_ui_browsertest.h"'); |
86 testing.Test.prototype.typedefCppFixture = 'WebUIBrowserTest'; | 95 testing.Test.prototype.typedefCppFixture = 'WebUIBrowserTest'; |
87 testF = 'IN_PROC_BROWSER_TEST_F'; | 96 testF = 'IN_PROC_BROWSER_TEST_F'; |
| 97 addSetPreloadInfo = true; |
88 } | 98 } |
89 print('#include "googleurl/src/gurl.h"'); | 99 print('#include "googleurl/src/gurl.h"'); |
90 print('#include "testing/gtest/include/gtest/gtest.h"'); | 100 print('#include "testing/gtest/include/gtest/gtest.h"'); |
91 print(); | 101 print(); |
92 | 102 |
93 /** | 103 /** |
94 * Convert the |includeFile| to paths appropriate for immediate | 104 * Convert the |includeFile| to paths appropriate for immediate |
95 * inclusion (path) and runtime inclusion (base). | 105 * inclusion (path) and runtime inclusion (base). |
96 * @param {string} includeFile The file to include. | 106 * @param {string} includeFile The file to include. |
97 * @return {{path: string, base: string}} Object describing the paths | 107 * @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) { | 159 function(includeFile) { |
150 return includeFileToPaths(includeFile).base; | 160 return includeFileToPaths(includeFile).base; |
151 })); | 161 })); |
152 | 162 |
153 if (typedefCppFixture && !(testFixture in typedeffedCppFixtures)) { | 163 if (typedefCppFixture && !(testFixture in typedeffedCppFixtures)) { |
154 print('typedef ' + typedefCppFixture + ' ' + testFixture + ';'); | 164 print('typedef ' + typedefCppFixture + ' ' + testFixture + ';'); |
155 typedeffedCppFixtures[testFixture] = typedefCppFixture; | 165 typedeffedCppFixtures[testFixture] = typedefCppFixture; |
156 } | 166 } |
157 | 167 |
158 print(testF + '(' + testFixture + ', ' + testFunction + ') {'); | 168 print(testF + '(' + testFixture + ', ' + testFunction + ') {'); |
159 if (testGenPreamble) | |
160 testGenPreamble(testFixture, testFunction); | |
161 for (var i = 0; i < extraLibraries.length; i++) { | 169 for (var i = 0; i < extraLibraries.length; i++) { |
162 print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + | 170 print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + |
163 extraLibraries[i].replace(/\\/g, '/') + '")));'); | 171 extraLibraries[i].replace(/\\/g, '/') + '")));'); |
164 } | 172 } |
165 print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + | 173 print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + |
166 jsFileBase.replace(/\\/g, '/') + '")));'); | 174 jsFileBase.replace(/\\/g, '/') + '")));'); |
167 if (browsePreload) { | 175 if (addSetPreloadInfo) { |
168 print(' BrowsePreload(GURL("' + browsePreload + '"), "' + testFixture + | 176 print(' set_preload_test_fixture("' + testFixture + '");'); |
169 '", "' + testFunction + '");'); | 177 print(' set_preload_test_name("' + testFunction + '");'); |
170 } | 178 } |
| 179 if (testGenPreamble) |
| 180 testGenPreamble(testFixture, testFunction); |
| 181 if (browsePreload) |
| 182 print(' BrowsePreload(GURL("' + browsePreload + '"));'); |
171 if (browsePrintPreload) { | 183 if (browsePrintPreload) { |
172 print(' BrowsePrintPreload(GURL(WebUITestDataPathToURL(\n' + | 184 print(' BrowsePrintPreload(GURL(WebUITestDataPathToURL(\n' + |
173 ' FILE_PATH_LITERAL("' + browsePrintPreload + '"))),\n' + | 185 ' FILE_PATH_LITERAL("' + browsePrintPreload + '"))));'); |
174 ' "' + testFixture + '", "' + testFunction + '");'); | |
175 } | 186 } |
176 print(' ' + testPredicate + '(RunJavascriptTestF(' + isAsyncParam + | 187 print(' ' + testPredicate + '(RunJavascriptTestF(' + isAsyncParam + |
177 '"' + testFixture + '", ' + | 188 '"' + testFixture + '", ' + |
178 '"' + testFunction + '"));'); | 189 '"' + testFunction + '"));'); |
179 if (testGenPostamble) | 190 if (testGenPostamble) |
180 testGenPostamble(testFixture, testFunction); | 191 testGenPostamble(testFixture, testFunction); |
181 print('}'); | 192 print('}'); |
182 print(); | 193 print(); |
183 } | 194 } |
184 | 195 |
185 // Now that generation functions are defined, load in |jsFile|. | 196 // Now that generation functions are defined, load in |jsFile|. |
186 var js = read(jsFile); | 197 var js = read(jsFile); |
187 eval(js); | 198 eval(js); |
OLD | NEW |