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 if (arguments.length < 4) { | 4 if (arguments.length < 4) { |
5 print('usage: ' + | 5 print('usage: ' + |
6 arguments[0] + ' path-to-testfile.js testfile.js output.cc test-type'); | 6 arguments[0] + ' path-to-testfile.js testfile.js output.cc test-type'); |
7 quit(-1); | 7 quit(-1); |
8 } | 8 } |
9 var jsFile = arguments[1]; | 9 var jsFile = arguments[1]; |
10 var jsFileBase = arguments[2]; | 10 var jsFileBase = arguments[2]; |
11 var outputFile = arguments[3]; | 11 var outputFile = arguments[3]; |
12 var testType = arguments[4]; | 12 var testType = arguments[4]; |
13 var testF; | |
14 var typedeffedCppFixtures = {}; | |
15 var genIncludes = []; | |
13 | 16 |
14 // Generate the file to stdout. | 17 // Generate the file to stdout. |
15 print('// GENERATED FILE'); | 18 print('// GENERATED FILE'); |
16 print('// ' + arguments.join(' ')); | 19 print('// ' + arguments.join(' ')); |
17 print('// PLEASE DO NOT HAND EDIT!'); | 20 print('// PLEASE DO NOT HAND EDIT!'); |
18 print(); | 21 print(); |
19 | 22 |
20 var testF; | |
21 | |
22 if (testType === 'unit') { | 23 if (testType === 'unit') { |
23 print('#include "chrome/test/base/v8_unit_test.h"'); | 24 print('#include "chrome/test/base/v8_unit_test.h"'); |
24 testing.Test.prototype.typedefCppFixture = 'V8UnitTest'; | 25 testing.Test.prototype.typedefCppFixture = 'V8UnitTest'; |
25 testF = 'TEST_F'; | 26 testF = 'TEST_F'; |
26 } else { | 27 } else { |
27 print('#include "chrome/browser/ui/webui/web_ui_browsertest.h"'); | 28 print('#include "chrome/browser/ui/webui/web_ui_browsertest.h"'); |
28 testing.Test.prototype.typedefCppFixture = 'WebUIBrowserTest'; | 29 testing.Test.prototype.typedefCppFixture = 'WebUIBrowserTest'; |
29 testF = 'IN_PROC_BROWSER_TEST_F'; | 30 testF = 'IN_PROC_BROWSER_TEST_F'; |
30 } | 31 } |
31 print('#include "googleurl/src/gurl.h"'); | 32 print('#include "googleurl/src/gurl.h"'); |
32 print('#include "testing/gtest/include/gtest/gtest.h"'); | 33 print('#include "testing/gtest/include/gtest/gtest.h"'); |
33 print(); | 34 print(); |
34 | 35 |
36 function incFileToPaths(includeFile) { | |
dpapad
2011/11/03 16:14:34
Prefer the full name includeFileToPaths over the a
Sheridan Rawlins
2011/11/05 16:51:25
FWIW, this is javascript
http://google-styleguide.
Sheridan Rawlins
2011/11/05 22:28:02
Hmm... missed the document part... tackling in th
| |
37 return { | |
38 path: jsFile.replace(/[^\/]+$/, includeFile), | |
39 base: jsFileBase.replace(/[^\/]+$/, includeFile), | |
40 }; | |
41 } | |
42 | |
35 function GEN(code) { | 43 function GEN(code) { |
36 print(code); | 44 print(code); |
37 } | 45 } |
38 | 46 |
39 var typedeffedCppFixtures = {}; | 47 function GEN_INCLUDE(includes) { |
48 for(var i = 0; i < includes.length; ++i) { | |
dpapad
2011/11/03 16:14:34
Space after for.
arv (Not doing code reviews)
2011/11/03 19:04:12
nit
i++
Sheridan Rawlins
2011/11/05 16:51:25
Done.
Sheridan Rawlins
2011/11/05 16:51:25
Done.
| |
49 var incPaths = incFileToPaths(includes[i]); | |
50 var js = read(incPaths.path); | |
51 eval(js); | |
arv (Not doing code reviews)
2011/11/03 19:04:12
I assume we don't want to eval this in the scope o
Sheridan Rawlins
2011/11/05 16:51:25
Done.
| |
52 genIncludes = genIncludes.concat(incPaths.base); | |
arv (Not doing code reviews)
2011/11/03 19:04:12
push?
Sheridan Rawlins
2011/11/05 16:51:25
Yeah, that's what I wanted, but the thing being pu
Sheridan Rawlins
2011/11/05 22:28:02
Sorry, I guess in this loop, it's a singular item.
| |
53 } | |
54 } | |
40 | 55 |
41 function TEST_F(testFixture, testFunction, testBody) { | 56 function TEST_F(testFixture, testFunction, testBody) { |
42 var browsePreload = this[testFixture].prototype.browsePreload; | 57 var browsePreload = this[testFixture].prototype.browsePreload; |
arv (Not doing code reviews)
2011/11/09 03:02:06
var proto = this[testFixture].prototype;
| |
43 var browsePrintPreload = this[testFixture].prototype.browsePrintPreload; | 58 var browsePrintPreload = this[testFixture].prototype.browsePrintPreload; |
44 var testGenPreamble = this[testFixture].prototype.testGenPreamble; | 59 var testGenPreamble = this[testFixture].prototype.testGenPreamble; |
45 var testGenPostamble = this[testFixture].prototype.testGenPostamble; | 60 var testGenPostamble = this[testFixture].prototype.testGenPostamble; |
46 var typedefCppFixture = this[testFixture].prototype.typedefCppFixture; | 61 var typedefCppFixture = this[testFixture].prototype.typedefCppFixture; |
47 var isAsyncParam = testType === 'unit' ? '' : | 62 var isAsyncParam = testType === 'unit' ? '' : |
48 this[testFixture].prototype.isAsync + ', '; | 63 this[testFixture].prototype.isAsync + ', '; |
49 var testShouldFail = this[testFixture].prototype.testShouldFail; | 64 var testShouldFail = this[testFixture].prototype.testShouldFail; |
50 var testPredicate = testShouldFail ? 'ASSERT_FALSE' : 'ASSERT_TRUE'; | 65 var testPredicate = testShouldFail ? 'ASSERT_FALSE' : 'ASSERT_TRUE'; |
66 var addLibraries = genIncludes.concat( | |
67 this[testFixture].prototype.addLibraries.map( | |
arv (Not doing code reviews)
2011/11/03 19:04:12
This looks strange. Why are we getting this from t
Sheridan Rawlins
2011/11/05 16:51:25
I wanted to give the best of both worlds:
1) GEN_I
Sheridan Rawlins
2011/11/05 22:28:02
Or was your concern with using the prototype? If
arv (Not doing code reviews)
2011/11/09 03:02:06
I found it strange that you interact with the prot
| |
68 function(incFile) { | |
69 return incFileToPaths(incFile).base; | |
70 })); | |
51 | 71 |
52 if (typedefCppFixture && !(testFixture in typedeffedCppFixtures)) { | 72 if (typedefCppFixture && !(testFixture in typedeffedCppFixtures)) { |
53 print('typedef ' + typedefCppFixture + ' ' + testFixture + ';'); | 73 print('typedef ' + typedefCppFixture + ' ' + testFixture + ';'); |
54 typedeffedCppFixtures[testFixture] = typedefCppFixture; | 74 typedeffedCppFixtures[testFixture] = typedefCppFixture; |
55 } | 75 } |
56 | 76 |
57 print(testF + '(' + testFixture + ', ' + testFunction + ') {'); | 77 print(testF + '(' + testFixture + ', ' + testFunction + ') {'); |
58 if (testGenPreamble) | 78 if (testGenPreamble) |
59 testGenPreamble(testFixture, testFunction); | 79 testGenPreamble(testFixture, testFunction); |
80 for(var i = 0; i < addLibraries.length; ++i) { | |
dpapad
2011/11/03 16:14:34
Space after for.
Sheridan Rawlins
2011/11/05 16:51:25
Done.
| |
81 print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + | |
82 addLibraries[i].replace(/\\/g, '/') + '")));'); | |
83 } | |
60 print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + | 84 print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + |
61 jsFileBase.replace(/\\/g, '/') + '")));'); | 85 jsFileBase.replace(/\\/g, '/') + '")));'); |
62 if (browsePreload) { | 86 if (browsePreload) { |
63 print(' BrowsePreload(GURL("' + browsePreload + '"), "' + testFixture + | 87 print(' BrowsePreload(GURL("' + browsePreload + '"), "' + testFixture + |
64 '", "' + testFunction + '");'); | 88 '", "' + testFunction + '");'); |
65 } | 89 } |
66 if (browsePrintPreload) { | 90 if (browsePrintPreload) { |
67 print(' BrowsePrintPreload(GURL(WebUITestDataPathToURL(\n' + | 91 print(' BrowsePrintPreload(GURL(WebUITestDataPathToURL(\n' + |
68 ' FILE_PATH_LITERAL("' + browsePrintPreload + '"))),\n' + | 92 ' FILE_PATH_LITERAL("' + browsePrintPreload + '"))),\n' + |
69 ' "' + testFixture + '", "' + testFunction + '");'); | 93 ' "' + testFixture + '", "' + testFunction + '");'); |
70 } | 94 } |
71 print(' ' + testPredicate + '(RunJavascriptTestF(' + isAsyncParam + | 95 print(' ' + testPredicate + '(RunJavascriptTestF(' + isAsyncParam + |
72 '"' + testFixture + '", ' + | 96 '"' + testFixture + '", ' + |
73 '"' + testFunction + '"));'); | 97 '"' + testFunction + '"));'); |
74 if (testGenPostamble) | 98 if (testGenPostamble) |
75 testGenPostamble(testFixture, testFunction); | 99 testGenPostamble(testFixture, testFunction); |
76 print('}'); | 100 print('}'); |
77 print(); | 101 print(); |
78 } | 102 } |
79 | 103 |
80 var js = read(jsFile); | 104 var js = read(jsFile); |
81 eval(js); | 105 eval(js); |
OLD | NEW |