Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: chrome/test/base/js2gtest.js

Issue 8418015: Allow javascript unit tests using webui test_api framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 < 3) { 4 if (arguments.length < 4) {
5 print('usage: ' + 5 print('usage: ' +
6 arguments[0] + ' path-to-testfile.js testfile.js [output.cc]'); 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 13
13 // Generate the file to stdout. 14 // Generate the file to stdout.
14 print('// GENERATED FILE'); 15 print('// GENERATED FILE');
15 print('// ' + arguments.join(' ')); 16 print('// ' + arguments.join(' '));
16 print('// PLEASE DO NOT HAND EDIT!'); 17 print('// PLEASE DO NOT HAND EDIT!');
17 print(); 18 print();
18 print('#include "chrome/browser/ui/webui/web_ui_browsertest.h"'); 19
20 var testF;
21
22 if (testType === 'unit') {
23 print('#include "chrome/test/base/v8_unit_test.h"');
24 testing.Test.prototype.typedefCppFixture = 'V8UnitTest';
25 testF = 'TEST_F';
26 } else {
27 print('#include "chrome/browser/ui/webui/web_ui_browsertest.h"');
28 testing.Test.prototype.typedefCppFixture = 'WebUIBrowserTest';
29 testF = 'IN_PROC_BROWSER_TEST_F';
30 }
19 print('#include "googleurl/src/gurl.h"'); 31 print('#include "googleurl/src/gurl.h"');
20 print('#include "testing/gtest/include/gtest/gtest.h"'); 32 print('#include "testing/gtest/include/gtest/gtest.h"');
21 print(); 33 print();
22 34
23 function GEN(code) { 35 function GEN(code) {
24 print(code); 36 print(code);
25 } 37 }
26 38
27 var typedeffedCppFixtures = {}; 39 var typedeffedCppFixtures = {};
28 40
29 function TEST_F(testFixture, testFunction, testBody) { 41 function TEST_F(testFixture, testFunction, testBody) {
30 var browsePreload = this[testFixture].prototype.browsePreload; 42 var browsePreload = this[testFixture].prototype.browsePreload;
31 var browsePrintPreload = this[testFixture].prototype.browsePrintPreload; 43 var browsePrintPreload = this[testFixture].prototype.browsePrintPreload;
32 var testGenPreamble = this[testFixture].prototype.testGenPreamble; 44 var testGenPreamble = this[testFixture].prototype.testGenPreamble;
33 var testGenPostamble = this[testFixture].prototype.testGenPostamble; 45 var testGenPostamble = this[testFixture].prototype.testGenPostamble;
34 var typedefCppFixture = this[testFixture].prototype.typedefCppFixture; 46 var typedefCppFixture = this[testFixture].prototype.typedefCppFixture;
35 var isAsync = this[testFixture].prototype.isAsync; 47 var isAsyncParam = testType === 'unit' ? '' :
48 this[testFixture].prototype.isAsync + ', ';
36 var testShouldFail = this[testFixture].prototype.testShouldFail; 49 var testShouldFail = this[testFixture].prototype.testShouldFail;
37 var testPredicate = testShouldFail ? 'ASSERT_FALSE' : 'ASSERT_TRUE'; 50 var testPredicate = testShouldFail ? 'ASSERT_FALSE' : 'ASSERT_TRUE';
38 51
39 if (typedefCppFixture && !(testFixture in typedeffedCppFixtures)) { 52 if (typedefCppFixture && !(testFixture in typedeffedCppFixtures)) {
40 print('typedef ' + typedefCppFixture + ' ' + testFixture + ';'); 53 print('typedef ' + typedefCppFixture + ' ' + testFixture + ';');
41 typedeffedCppFixtures[testFixture] = typedefCppFixture; 54 typedeffedCppFixtures[testFixture] = typedefCppFixture;
42 } 55 }
43 56
44 print('IN_PROC_BROWSER_TEST_F(' + testFixture + ', ' + testFunction + ') {'); 57 print(testF + '(' + testFixture + ', ' + testFunction + ') {');
45 if (testGenPreamble) 58 if (testGenPreamble)
46 testGenPreamble(testFixture, testFunction); 59 testGenPreamble(testFixture, testFunction);
47 print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + 60 print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' +
48 jsFileBase.replace(/\\/g, '/') + '")));'); 61 jsFileBase.replace(/\\/g, '/') + '")));');
49 if (browsePreload) { 62 if (browsePreload) {
50 print(' BrowsePreload(GURL("' + browsePreload + '"), "' + testFixture + 63 print(' BrowsePreload(GURL("' + browsePreload + '"), "' + testFixture +
51 '", "' + testFunction + '");'); 64 '", "' + testFunction + '");');
52 } 65 }
53 if (browsePrintPreload) { 66 if (browsePrintPreload) {
54 print(' BrowsePrintPreload(GURL(WebUITestDataPathToURL(\n' + 67 print(' BrowsePrintPreload(GURL(WebUITestDataPathToURL(\n' +
55 ' FILE_PATH_LITERAL("' + browsePrintPreload + '"))),\n' + 68 ' FILE_PATH_LITERAL("' + browsePrintPreload + '"))),\n' +
56 ' "' + testFixture + '", "' + testFunction + '");'); 69 ' "' + testFixture + '", "' + testFunction + '");');
57 } 70 }
58 print(' ' + testPredicate + '(RunJavascriptTestF(' + isAsync + ', ' + 71 print(' ' + testPredicate + '(RunJavascriptTestF(' + isAsyncParam +
59 '"' + testFixture + '", ' + 72 '"' + testFixture + '", ' +
60 '"' + testFunction + '"));'); 73 '"' + testFunction + '"));');
61 if (testGenPostamble) 74 if (testGenPostamble)
62 testGenPostamble(testFixture, testFunction); 75 testGenPostamble(testFixture, testFunction);
63 print('}'); 76 print('}');
64 print(); 77 print();
65 } 78 }
66 79
67 var js = read(jsFile); 80 var js = read(jsFile);
68 eval(js); 81 eval(js);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698