Chromium Code Reviews| Index: chrome/test/base/js2gtest.js |
| diff --git a/chrome/test/base/js2gtest.js b/chrome/test/base/js2gtest.js |
| index 9cf8fef1ffd7970a453bcb7fd841aae2f5c2b199..0d573c8925d7275ed8638253e21bca3f10508683 100644 |
| --- a/chrome/test/base/js2gtest.js |
| +++ b/chrome/test/base/js2gtest.js |
| @@ -4,7 +4,7 @@ |
| /** |
| * @fileoverview Generator script for creating gtest-style JavaScript |
| - * tests for WebUI and unit tests. Generates C++ gtest wrappers |
| + * tests for extensions, WebUI and unit tests. Generates C++ gtest wrappers |
| * which will invoke the appropriate JavaScript for each test. |
| * @author scr@chromium.org (Sheridan Rawlins) |
| * @see WebUI testing: http://goo.gl/ZWFXF |
| @@ -49,7 +49,7 @@ var outputFile = arguments[4]; |
| /** |
| * Type of this test. |
| - * @type {string} ('unit'| 'webui') |
| + * @type {string} ('extension' | 'unit' | 'webui') |
|
Peter Lundblad
2014/06/11 16:45:07
Add code to validate that the test is one of these
Peter Lundblad
2014/06/11 16:45:07
Add code to validate that the test is one of these
Peter Lundblad
2014/06/11 16:45:07
Add code to validate that the test is one of these
David Tseng
2014/06/11 17:52:55
Sure ok.
|
| */ |
| var testType = arguments[5]; |
| @@ -76,36 +76,69 @@ var genIncludes = []; |
| /** |
| * When true, add calls to set_preload_test_(fixture|name). This is needed when |
| * |testType| === 'browser' to send an injection message before the page loads, |
| - * but is not required or supported for |testType| === 'unit'. |
| + * but is not required or supported for |testType| === 'extension' or |
|
Peter Lundblad
2014/06/11 16:45:07
nit: Is this comment out of date talking about typ
Peter Lundblad
2014/06/11 16:45:07
nit: Is this comment out of date talking about typ
Peter Lundblad
2014/06/11 16:45:07
nit: Is this comment out of date talking about typ
David Tseng
2014/06/11 17:52:55
Updated.
|
| + * |testType| === 'unit'. |
| * @type {boolean} |
| */ |
| var addSetPreloadInfo; |
| -// Generate the file to stdout. |
| -print('// GENERATED FILE'); |
| -print('// ' + arguments.join(' ')); |
| -print('// PLEASE DO NOT HAND EDIT!'); |
| -print(); |
| - |
| -// Output some C++ headers based upon the |testType|. |
| -// |
| -// Currently supports: |
| -// 'unit' - unit_tests harness, js2unit rule, V8UnitTest superclass. |
| -// 'webui' - browser_tests harness, js2webui rule, WebUIBrowserTest superclass. |
| -if (testType === 'unit') { |
| - print('#include "chrome/test/base/v8_unit_test.h"'); |
| - testing.Test.prototype.typedefCppFixture = 'V8UnitTest'; |
| - testF = 'TEST_F'; |
| - addSetPreloadInfo = false; |
| -} else { |
| - print('#include "chrome/test/base/web_ui_browser_test.h"'); |
| - testing.Test.prototype.typedefCppFixture = 'WebUIBrowserTest'; |
| - testF = 'IN_PROC_BROWSER_TEST_F'; |
| - addSetPreloadInfo = true; |
| +/** |
| + * Whether cc headers need to be generated. |
| + * @type {boolean} |
| + */ |
| +var needGenHeader = true; |
| + |
| +/** |
| + * Helpful hint pointing back to the source js. |
| + * @type {string} |
| + */ |
| +var argHint = '// ' + this['arguments'].join(' '); |
| + |
| + |
| +/** |
| + * Generates the header of the cc file to stdout. |
| + * @param {string} testFixture Name of test fixture. |
| + */ |
| +function maybeGenHeader(testFixture) { |
| + if (!needGenHeader) |
| + return; |
| + needGenHeader = false; |
| + print('// GENERATED FILE'); |
| + print(argHint); |
| + print('// PLEASE DO NOT HAND EDIT!'); |
| + print(); |
| + |
| + // Output some C++ headers based upon the |testType|. |
| + // |
| + // Currently supports: |
| + // 'extension' - browser_tests harness, js2extension rule, |
| + // ExtensionJSBrowserTest superclass. |
| + // 'unit' - unit_tests harness, js2unit rule, V8UnitTest superclass. |
| + // 'webui' - browser_tests harness, js2webui rule, WebUIBrowserTest |
| + // superclass. |
| + if (testType === 'extension') { |
| + print('#include "chrome/test/base/extension_js_browser_test.h"'); |
| + testing.Test.prototype.typedefCppFixture = 'ExtensionJSBrowserTest'; |
| + addSetPreloadInfo = false; |
| + testF = 'IN_PROC_BROWSER_TEST_F'; |
| + } else if (testType === 'unit') { |
| + print('#include "chrome/test/base/v8_unit_test.h"'); |
| + testing.Test.prototype.typedefCppFixture = 'V8UnitTest'; |
| + testF = 'TEST_F'; |
| + addSetPreloadInfo = false; |
| + } else { |
| + print('#include "chrome/test/base/web_ui_browser_test.h"'); |
| + testing.Test.prototype.typedefCppFixture = 'WebUIBrowserTest'; |
| + testF = 'IN_PROC_BROWSER_TEST_F'; |
| + addSetPreloadInfo = true; |
| + } |
| + print('#include "url/gurl.h"'); |
| + print('#include "testing/gtest/include/gtest/gtest.h"'); |
| + if (this[testFixture].prototype.testGenCppIncludes) |
| + this[testFixture].prototype.testGenCppIncludes(); |
| + print(); |
| } |
| -print('#include "url/gurl.h"'); |
| -print('#include "testing/gtest/include/gtest/gtest.h"'); |
| -print(); |
| + |
| /** |
| * Convert the |includeFile| to paths appropriate for immediate |
| @@ -224,6 +257,22 @@ function GEN(code) { |
| } |
| /** |
| + * Outputs |commentEncodedCode| by converting it to a js fragment. |
| + * @param {function} commentEncodedCode A function in the following format (note |
| + * the space in '/ *' and '* /' should be removed to form a comment delimiter): |
| + * function() {/ *! my_cpp_code.DoSomething(); * / |
| + * Code between / *! and * / will be extracted and written to stdout. |
| + */ |
| +function GEN_BLOCK(commentEncodedCode) { |
| + var code = commentEncodedCode.toString(). |
| + replace(/^[^\/]+\/\*!?/, ''). |
| + replace(/\*\/[^\/]+$/, ''). |
| + replace(/^\n|\n$/, ''). |
| + replace(/\s+$/, ''); |
| + GEN(code); |
| +} |
| + |
| +/** |
| * Generate includes for the current |jsFile| by including them |
| * immediately and at runtime. |
| * @param {Array.<string>} includes Paths to JavaScript files to |
| @@ -246,6 +295,7 @@ function GEN_INCLUDE(includes) { |
| * @param {Function} testBody The function body to execute for this test. |
| */ |
| function TEST_F(testFixture, testFunction, testBody) { |
| + maybeGenHeader(testFixture); |
|
Peter Lundblad
2014/06/11 16:45:07
Does the defered generation of the file header pla
David Tseng
2014/06/11 17:52:55
I haven't had any problems; was there a specific c
|
| var browsePreload = this[testFixture].prototype.browsePreload; |
| var browsePrintPreload = this[testFixture].prototype.browsePrintPreload; |
| var testGenPreamble = this[testFixture].prototype.testGenPreamble; |