Skip to content

Commit

Permalink
Add command-line arguments to js2gtest generated tests.
Browse files Browse the repository at this point in the history
This will allow testing behavior behind a flag using
generated WebUIBrowserTests (specifically, this is to
unblock Polymer browser tests for projects behind flags,
e.g. --enable-md-settings or --enable-media-router).

js2gtest tests can specify their flags on their test
fixture's prototype, e.g.:
  ...
  browsePreload: 'chrome://md-settings',
  commandLineSwitches: [{
    switchName: '--some-switch',
    switchValue: 'someValue'
  }, {
    switchName: '--enable-boolean-switch'
  }],
  ...

Review URL: https://codereview.chromium.org/1196513002

Cr-Commit-Position: refs/heads/master@{#335894}
  • Loading branch information
michaelpg authored and Commit bot committed Jun 24, 2015
1 parent 0bd5fd7 commit 9e84be4
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions chrome/test/base/js2gtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,13 @@ function maybeGenHeader(testFixture) {
}
print('#include "url/gurl.h"');
print('#include "testing/gtest/include/gtest/gtest.h"');
if (testFixture && this[testFixture].prototype.testGenCppIncludes)
this[testFixture].prototype.testGenCppIncludes();
// Add includes specified by test fixture.
if (testFixture) {
if (this[testFixture].prototype.testGenCppIncludes)
this[testFixture].prototype.testGenCppIncludes();
if (this[testFixture].prototype.commandLineSwitches)
print('#include "base/command_line.h"');
}
print();
}

Expand Down Expand Up @@ -340,7 +345,24 @@ function TEST_F(testFixture, testFunction, testBody) {
resolveClosureModuleDeps(this[testFixture].prototype.closureModuleDeps));

if (typedefCppFixture && !(testFixture in typedeffedCppFixtures)) {
print('typedef ' + typedefCppFixture + ' ' + testFixture + ';');
var switches = this[testFixture].prototype.commandLineSwitches;
if (!switches || !switches.length || typedefCppFixture == 'V8UnitTest') {
print('typedef ' + typedefCppFixture + ' ' + testFixture + ';');
} else {
// Make the testFixture a class inheriting from the base fixture.
print('class ' + testFixture + ' : public ' + typedefCppFixture + ' {');
print(' private:');
// Override SetUpCommandLine and add each switch.
print(' void');
print(' SetUpCommandLine(base::CommandLine* command_line) override {');
for (var i = 0; i < switches.length; i++) {
print(' command_line->AppendSwitchASCII(');
print(' "' + switches[i].switchName + '",');
print(' "' + (switches[i].switchValue || '') + '");');
}
print(' }');
print('};');
}
typedeffedCppFixtures[testFixture] = typedefCppFixture;
}

Expand Down

0 comments on commit 9e84be4

Please sign in to comment.