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

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

Issue 320753002: Support javascript gtests in an extension background page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: WS Created 6 years, 6 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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
dmazzoni 2014/06/09 06:59:46 Update this top comment too
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
11 * @see gtest documentation: http://goo.gl/Ujj3H 11 * @see gtest documentation: http://goo.gl/Ujj3H
12 * @see chrome/chrome_tests.gypi 12 * @see chrome/chrome_tests.gypi
13 * @see tools/gypv8sh.py 13 * @see tools/gypv8sh.py
14 */ 14 */
15 15
16 // Arguments from rules in chrome_tests.gypi are passed in through 16 // Arguments from rules in chrome_tests.gypi are passed in through
17 // python script gypv8sh.py. 17 // python script gypv8sh.py.
(...skipping 24 matching lines...) Expand all
42 var depsFile = arguments[3]; 42 var depsFile = arguments[3];
43 43
44 /** 44 /**
45 * Path to C++ file generation is outputting to. 45 * Path to C++ file generation is outputting to.
46 * @type {string} 46 * @type {string}
47 */ 47 */
48 var outputFile = arguments[4]; 48 var outputFile = arguments[4];
49 49
50 /** 50 /**
51 * Type of this test. 51 * Type of this test.
52 * @type {string} ('unit'| 'webui') 52 * @type {string} ('unit'| 'webui')
dmazzoni 2014/06/09 06:59:46 Update this too
53 */ 53 */
54 var testType = arguments[5]; 54 var testType = arguments[5];
55 55
56 /** 56 /**
57 * C++ gtest macro to use for TEST_F depending on |testType|. 57 * C++ gtest macro to use for TEST_F depending on |testType|.
58 * @type {string} ('TEST_F'|'IN_PROC_BROWSER_TEST_F') 58 * @type {string} ('TEST_F'|'IN_PROC_BROWSER_TEST_F')
59 */ 59 */
60 var testF; 60 var testF;
61 61
62 /** 62 /**
63 * Keeps track of whether a typedef has been generated for each test 63 * Keeps track of whether a typedef has been generated for each test
64 * fixture. 64 * fixture.
65 * @type {Object.<string, string>} 65 * @type {Object.<string, string>}
66 */ 66 */
67 var typedeffedCppFixtures = {}; 67 var typedeffedCppFixtures = {};
68 68
69 /** 69 /**
70 * Maintains a list of relative file paths to add to each gtest body 70 * Maintains a list of relative file paths to add to each gtest body
71 * for inclusion at runtime before running each JavaScript test. 71 * for inclusion at runtime before running each JavaScript test.
72 * @type {Array.<string>} 72 * @type {Array.<string>}
73 */ 73 */
74 var genIncludes = []; 74 var genIncludes = [];
75 75
76 /** 76 /**
77 * When true, add calls to set_preload_test_(fixture|name). This is needed when 77 * When true, add calls to set_preload_test_(fixture|name). This is needed when
78 * |testType| === 'browser' to send an injection message before the page loads, 78 * |testType| === 'browser' to send an injection message before the page loads,
79 * but is not required or supported for |testType| === 'unit'. 79 * but is not required or supported for |testType| === 'chromevox' or
80 * |testType| === 'unit'.
80 * @type {boolean} 81 * @type {boolean}
81 */ 82 */
82 var addSetPreloadInfo; 83 var addSetPreloadInfo;
83 84
84 // Generate the file to stdout. 85 // Generate the file to stdout.
85 print('// GENERATED FILE'); 86 print('// GENERATED FILE');
86 print('// ' + arguments.join(' ')); 87 print('// ' + arguments.join(' '));
87 print('// PLEASE DO NOT HAND EDIT!'); 88 print('// PLEASE DO NOT HAND EDIT!');
88 print(); 89 print();
89 90
90 // Output some C++ headers based upon the |testType|. 91 // Output some C++ headers based upon the |testType|.
91 // 92 //
92 // Currently supports: 93 // Currently supports:
94 // 'chromevox' - browser_tests harness, js2chromevox rule, ChromeVoxBrowserTest
95 // superclass.
93 // 'unit' - unit_tests harness, js2unit rule, V8UnitTest superclass. 96 // 'unit' - unit_tests harness, js2unit rule, V8UnitTest superclass.
94 // 'webui' - browser_tests harness, js2webui rule, WebUIBrowserTest superclass. 97 // 'webui' - browser_tests harness, js2webui rule, WebUIBrowserTest superclass.
95 if (testType === 'unit') { 98 if (testType === 'chromevox') {
99 print('#include "chrome/browser/resources/chromeos/chromevox/' +
100 'chromevox_browsertest.h"');
101 testing.Test.prototype.typedefCppFixture = 'ChromeVoxBrowserTest';
102 addSetPreloadInfo = false;
103 testF = 'IN_PROC_BROWSER_TEST_F';
104 } else if (testType === 'unit') {
96 print('#include "chrome/test/base/v8_unit_test.h"'); 105 print('#include "chrome/test/base/v8_unit_test.h"');
97 testing.Test.prototype.typedefCppFixture = 'V8UnitTest'; 106 testing.Test.prototype.typedefCppFixture = 'V8UnitTest';
98 testF = 'TEST_F'; 107 testF = 'TEST_F';
99 addSetPreloadInfo = false; 108 addSetPreloadInfo = false;
100 } else { 109 } else {
101 print('#include "chrome/test/base/web_ui_browser_test.h"'); 110 print('#include "chrome/test/base/web_ui_browser_test.h"');
102 testing.Test.prototype.typedefCppFixture = 'WebUIBrowserTest'; 111 testing.Test.prototype.typedefCppFixture = 'WebUIBrowserTest';
103 testF = 'IN_PROC_BROWSER_TEST_F'; 112 testF = 'IN_PROC_BROWSER_TEST_F';
104 addSetPreloadInfo = true; 113 addSetPreloadInfo = true;
105 } 114 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 '"' + testFunction + '"));'); 300 '"' + testFunction + '"));');
292 if (testGenPostamble) 301 if (testGenPostamble)
293 testGenPostamble(testFixture, testFunction); 302 testGenPostamble(testFixture, testFunction);
294 print('}'); 303 print('}');
295 print(); 304 print();
296 } 305 }
297 306
298 // Now that generation functions are defined, load in |jsFile|. 307 // Now that generation functions are defined, load in |jsFile|.
299 var js = read(jsFile); 308 var js = read(jsFile);
300 eval(js); 309 eval(js);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698