Commit 42a11612 authored by jcampan@chromium.org's avatar jcampan@chromium.org

This CL makes a more generic browser test launcher and a DLL of the

interactive UI tests, so the interactive UI tests can be run isolated.

BUG=None
TEST=Run the the interactive ui tests with the new launcher:
     test_launcher --lib=interactive_ui_tests_dll

Review URL: http://codereview.chromium.org/197045

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25863 0039d316-1c4b-4281-b951-d872f2087c98
parent 02528ba2
......@@ -5327,10 +5327,10 @@
],
'defines': [ 'ALLOW_IN_PROC_BROWSER_TEST' ],
'sources': [
'test/browser/run_all_unittests.cc',
'test/browser/browser_test_launcher_out_of_proc.cc',
'test/browser/browser_test_runner.cc',
'test/browser/browser_test_runner.h',
'test/test_launcher/out_of_proc_test_runner.cc',
'test/test_launcher/test_runner.cc',
'test/test_launcher/test_runner.h',
'test/test_launcher/run_all_unittests.cc',
'test/unit/chrome_test_suite.h',
# browser_tests_sources is defined in 'variables' at the top of the
# file.
......@@ -5539,7 +5539,7 @@
'test/live_sync/live_bookmarks_sync_test.h',
'test/live_sync/profile_sync_service_test_harness.cc',
'test/live_sync/profile_sync_service_test_harness.h',
'test/browser/run_all_unittests.cc',
'test/test_launcher/run_all_unittests.cc',
'test/test_notification_tracker.cc',
'test/test_notification_tracker.h',
'test/testing_browser_process.h',
......@@ -5595,6 +5595,138 @@
}],
],
},
{
'target_name': 'interactive_ui_tests_dll',
# 'product_name': 'interactive_ui_tests',
'type': 'shared_library',
'msvs_guid': '04116FAF-DA17-46EE-B108-971FCF0F0AFC',
'dependencies': [
'chrome',
'chrome_resources',
'chrome_strings',
'debugger',
'test_support_common',
'test_support_ui',
'syncapi',
'../third_party/hunspell/hunspell.gyp:hunspell',
'../net/net.gyp:net_resources',
'../skia/skia.gyp:skia',
'../third_party/icu/icu.gyp:icui18n',
'../third_party/libpng/libpng.gyp:libpng',
'../third_party/libxml/libxml.gyp:libxml',
'../third_party/zlib/zlib.gyp:zlib',
'../testing/gtest.gyp:gtest',
'../third_party/npapi/npapi.gyp:npapi',
# run time dependency
'../webkit/webkit.gyp:webkit_resources',
],
'include_dirs': [
'..',
],
'defines': [ 'ALLOW_IN_PROC_BROWSER_TEST' ],
'sources': [
'browser/browser_focus_uitest.cc',
'browser/debugger/devtools_sanity_unittest.cc',
'browser/views/bookmark_bar_view_test.cc',
'browser/blocked_popup_container_interactive_uitest.cc',
'browser/views/find_bar_win_interactive_uitest.cc',
'browser/views/tabs/tab_dragging_test.cc',
'test/in_process_browser_test.cc',
'test/in_process_browser_test.h',
'test/interactive_ui/npapi_interactive_test.cc',
'test/interactive_ui/view_event_test_base.cc',
'test/interactive_ui/view_event_test_base.h',
'test/test_launcher/run_all_unittests.cc',
'test/test_launcher/test_runner.h',
'test/test_launcher/test_runner.cc',
'test/unit/chrome_test_suite.h',
],
'conditions': [
['OS=="linux"', {
'dependencies': [
'../build/linux/system.gyp:gtk',
],
'sources!': [
# TODO(port)
'browser/views/bookmark_bar_view_test.cc',
'browser/views/find_bar_win_interactive_uitest.cc',
'browser/views/tabs/tab_dragging_test.cc',
'test/interactive_ui/npapi_interactive_test.cc',
'test/interactive_ui/view_event_test_base.cc',
'test/interactive_ui/view_event_test_base.h',
],
}],
['target_arch!="x64"', {
'dependencies': [
# run time dependency
'../webkit/tools/test_shell/test_shell.gyp:npapi_test_plugin',
],
}],
['OS=="linux" and toolkit_views==1', {
'dependencies': [
'../views/views.gyp:views',
],
}],
['OS=="mac"', {
'sources!': [
# TODO(port)
'browser/browser_focus_uitest.cc',
'browser/debugger/devtools_sanity_unittest.cc',
'browser/views/bookmark_bar_view_test.cc',
'browser/blocked_popup_container_interactive_uitest.cc',
'browser/views/find_bar_win_interactive_uitest.cc',
'browser/views/tabs/tab_dragging_test.cc',
'test/interactive_ui/npapi_interactive_test.cc',
'test/interactive_ui/view_event_test_base.cc',
'test/interactive_ui/view_event_test_base.h',
],
}],
['OS=="win"', {
'include_dirs': [
'third_party/wtl/include',
],
'dependencies': [
'chrome_dll_version',
'crash_service', # run time dependency
'installer/installer.gyp:installer_util_strings',
'../views/views.gyp:views',
],
'sources': [
'../webkit/glue/resources/aliasb.cur',
'../webkit/glue/resources/cell.cur',
'../webkit/glue/resources/col_resize.cur',
'../webkit/glue/resources/copy.cur',
'../webkit/glue/resources/row_resize.cur',
'../webkit/glue/resources/vertical_text.cur',
'../webkit/glue/resources/zoom_in.cur',
'../webkit/glue/resources/zoom_out.cur',
'app/chrome_dll.rc',
'test/data/resource.rc',
# TODO: It would be nice to have these pulled in
# automatically from direct_dependent_settings in
# their various targets (net.gyp:net_resources, etc.),
# but that causes errors in other targets when
# resulting .res files get referenced multiple times.
'<(SHARED_INTERMEDIATE_DIR)/chrome/browser_resources.rc',
'<(SHARED_INTERMEDIATE_DIR)/chrome/common_resources.rc',
'<(SHARED_INTERMEDIATE_DIR)/chrome/renderer_resources.rc',
'<(SHARED_INTERMEDIATE_DIR)/net/net_resources.rc',
'<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_resources.rc',
],
'configurations': {
'Debug': {
'msvs_settings': {
'VCLinkerTool': {
'LinkIncremental': '<(msvs_large_module_debug_link_mode)',
},
},
},
},
}],
],
},
{
# Shared library used by the in-proc browser tests.
'target_name': 'browser_tests_dll',
......@@ -5631,9 +5763,9 @@
},
'defines': [ 'ALLOW_IN_PROC_BROWSER_TEST' ],
'sources': [
'test/browser/run_all_unittests.cc',
'test/in_process_browser_test.cc',
'test/in_process_browser_test.h',
'test/test_launcher/run_all_unittests.cc',
'test/unit/chrome_test_suite.h',
'test/ui_test_utils.cc',
'app/chrome_dll.rc',
......@@ -5668,9 +5800,9 @@
'..',
],
'sources': [
'test/browser/browser_test_launcher_in_proc.cc',
'test/browser/browser_test_runner.cc',
'test/browser/browser_test_runner.h',
'test/test_launcher/in_proc_test_runner.cc',
'test/test_launcher/test_runner.cc',
'test/test_launcher/test_runner.h',
],
'msvs_settings': {
'VCLinkerTool': {
......@@ -5679,6 +5811,23 @@
},
},
},
{
# Executable that runs the tests in-process (tests are bundled in a DLL).
'target_name': 'test_launcher',
'type': 'executable',
'msvs_guid': 'FA94F5AA-BC73-4926-A189-71FAA986C905',
'dependencies': [
'../base/base.gyp:base',
],
'include_dirs': [
'..',
],
'sources': [
'test/test_launcher/in_proc_test_runner.cc',
'test/test_launcher/test_runner.cc',
'test/test_launcher/test_runner.h',
],
},
{
'target_name': 'crash_service',
'type': 'executable',
......
......@@ -14,36 +14,37 @@
#include "base/process_util.h"
#include "base/string_util.h"
#include "chrome/test/browser/browser_test_runner.h"
#include "chrome/test/test_launcher/test_runner.h"
// This version of the browser test launcher loads a dynamic library containing
// the tests and executes the them in that library. When the test has been run
// the library is unloaded, to ensure atexit handlers are run and static
// This version of the test launcher loads a dynamic library containing the
// tests and executes the them in that library. When the test has been run the
// library is unloaded, to ensure atexit handlers are run and static
// initializers will be run again for the next test.
namespace {
const wchar_t* const kBrowserTesLibBaseName = L"browser_tests";
const wchar_t* const kLibNameFlag = L"lib";
const wchar_t* const kGTestListTestsFlag = L"gtest_list_tests";
class InProcBrowserTestRunner : public browser_tests::BrowserTestRunner {
class InProcTestRunner : public tests::TestRunner {
public:
InProcBrowserTestRunner() : dynamic_lib_(NULL), run_test_proc_(NULL) {
explicit InProcTestRunner(const std::wstring& lib_name)
: lib_name_(lib_name),
dynamic_lib_(NULL),
run_test_proc_(NULL) {
}
~InProcBrowserTestRunner() {
~InProcTestRunner() {
if (!dynamic_lib_)
return;
base::UnloadNativeLibrary(dynamic_lib_);
LOG(INFO) << "Unloaded " <<
base::GetNativeLibraryName(kBrowserTesLibBaseName);
LOG(INFO) << "Unloaded " << base::GetNativeLibraryName(lib_name_);
}
bool Init() {
FilePath lib_path;
CHECK(PathService::Get(base::FILE_EXE, &lib_path));
lib_path = lib_path.DirName().Append(
base::GetNativeLibraryName(kBrowserTesLibBaseName));
lib_path = lib_path.DirName().Append(base::GetNativeLibraryName(lib_name_));
LOG(INFO) << "Loading '" << lib_path.value() << "'";
......@@ -72,7 +73,7 @@ class InProcBrowserTestRunner : public browser_tests::BrowserTestRunner {
argv[0] = const_cast<char*>("");
argv[1] = const_cast<char*>(filter_flag.c_str());
// Always enable disabled tests. This method is not called with disabled
// tests unless this flag was specified to the browser test executable.
// tests unless this flag was specified to the test launcher.
argv[2] = "--gtest_also_run_disabled_tests";
return RunAsIs(3, argv) == 0;
}
......@@ -85,23 +86,27 @@ class InProcBrowserTestRunner : public browser_tests::BrowserTestRunner {
private:
typedef int (CDECL *RunTestProc)(int, char**);
std::wstring lib_name_;
base::NativeLibrary dynamic_lib_;
RunTestProc run_test_proc_;
DISALLOW_COPY_AND_ASSIGN(InProcBrowserTestRunner);
DISALLOW_COPY_AND_ASSIGN(InProcTestRunner);
};
class InProcBrowserTestRunnerFactory
: public browser_tests::BrowserTestRunnerFactory {
class InProcTestRunnerFactory : public tests::TestRunnerFactory {
public:
InProcBrowserTestRunnerFactory() { }
explicit InProcTestRunnerFactory(const std::wstring& lib_name)
: lib_name_(lib_name) {
}
virtual browser_tests::BrowserTestRunner* CreateBrowserTestRunner() const {
return new InProcBrowserTestRunner();
virtual tests::TestRunner* CreateTestRunner() const {
return new InProcTestRunner(lib_name_);
}
private:
DISALLOW_COPY_AND_ASSIGN(InProcBrowserTestRunnerFactory);
std::wstring lib_name_;
DISALLOW_COPY_AND_ASSIGN(InProcTestRunnerFactory);
};
} // namespace
......@@ -111,14 +116,20 @@ int main(int argc, char** argv) {
CommandLine::Init(argc, argv);
const CommandLine* command_line = CommandLine::ForCurrentProcess();
std::wstring lib_name = command_line->GetSwitchValue(kLibNameFlag);
if (lib_name.empty()) {
LOG(ERROR) << "No dynamic library name specified. You must specify one with"
" the --lib=<lib_name> option.";
return 1;
}
if (command_line->HasSwitch(kGTestListTestsFlag)) {
InProcBrowserTestRunner test_runner;
InProcTestRunner test_runner(lib_name);
if (!test_runner.Init())
return 1;
return test_runner.RunAsIs(argc, argv);
}
InProcBrowserTestRunnerFactory test_runner_factory;
return browser_tests::RunTests(test_runner_factory) ? 0 : 1;
InProcTestRunnerFactory test_runner_factory(lib_name);
return tests::RunTests(test_runner_factory) ? 0 : 1;
}
......@@ -8,23 +8,22 @@
#include "base/logging.h"
#include "base/process_util.h"
#include "chrome/test/browser/browser_test_runner.h"
#include "chrome/test/test_launcher/test_runner.h"
#include "chrome/test/unit/chrome_test_suite.h"
// This version of the browser test launcher forks a new process for each test
// it runs.
// This version of the test launcher forks a new process for each test it runs.
namespace {
const wchar_t* const kGTestListTestsFlag = L"gtest_list_tests";
const wchar_t* const kChildProcessFlag = L"child";
class OutOfProcBrowserTestRunner : public browser_tests::BrowserTestRunner {
class OutOfProcTestRunner : public tests::TestRunner {
public:
OutOfProcBrowserTestRunner() {
OutOfProcTestRunner() {
}
virtual ~OutOfProcBrowserTestRunner() {
virtual ~OutOfProcTestRunner() {
}
bool Init() {
......@@ -55,20 +54,19 @@ class OutOfProcBrowserTestRunner : public browser_tests::BrowserTestRunner {
}
private:
DISALLOW_COPY_AND_ASSIGN(OutOfProcBrowserTestRunner);
DISALLOW_COPY_AND_ASSIGN(OutOfProcTestRunner);
};
class OutOfProcBrowserTestRunnerFactory
: public browser_tests::BrowserTestRunnerFactory {
class OutOfProcTestRunnerFactory : public tests::TestRunnerFactory {
public:
OutOfProcBrowserTestRunnerFactory() { }
OutOfProcTestRunnerFactory() { }
virtual browser_tests::BrowserTestRunner* CreateBrowserTestRunner() const {
return new OutOfProcBrowserTestRunner();
virtual tests::TestRunner* CreateTestRunner() const {
return new OutOfProcTestRunner();
}
private:
DISALLOW_COPY_AND_ASSIGN(OutOfProcBrowserTestRunnerFactory);
DISALLOW_COPY_AND_ASSIGN(OutOfProcTestRunnerFactory);
};
} // namespace
......@@ -83,6 +81,6 @@ int main(int argc, char** argv) {
if (command_line->HasSwitch(kGTestListTestsFlag))
return ChromeTestSuite(argc, argv).Run();
OutOfProcBrowserTestRunnerFactory test_runner_factory;
return browser_tests::RunTests(test_runner_factory) ? 0 : 1;
OutOfProcTestRunnerFactory test_runner_factory;
return tests::RunTests(test_runner_factory) ? 0 : 1;
}
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/test/browser/browser_test_runner.h"
#include "chrome/test/test_launcher/test_runner.h"
#include <vector>
......@@ -23,9 +23,9 @@ const wchar_t* const kGTestRunDisabledTestsFlag =
// |command_line| should contain the command line used to start the browser
// test launcher, it is expected that it does not contain the
// --gtest_list_tests flag already.
// Note: we cannot implement this in-process for InProcessBrowserTestRunner as
// GTest prints to the stdout and there are no good way of temporarily
// redirecting outputs.
// Note: we cannot implement this in-process for InProcessTestRunner as GTest
// prints to the stdout and there are no good way of temporarily redirecting
// outputs.
bool GetTestList(const CommandLine& command_line,
std::vector<std::string>* test_list) {
DCHECK(!command_line.HasSwitch(kGTestListTestsFlag));
......@@ -72,15 +72,15 @@ bool GetTestList(const CommandLine& command_line,
} // namespace
namespace browser_tests {
namespace tests {
BrowserTestRunner::BrowserTestRunner() {
TestRunner::TestRunner() {
}
BrowserTestRunner::~BrowserTestRunner() {
TestRunner::~TestRunner() {
}
bool RunTests(const BrowserTestRunnerFactory& browser_test_runner_factory) {
bool RunTests(const TestRunnerFactory& test_runner_factory) {
const CommandLine* command_line = CommandLine::ForCurrentProcess();
DCHECK(!command_line->HasSwitch(kGTestListTestsFlag));
......@@ -102,8 +102,7 @@ bool RunTests(const BrowserTestRunnerFactory& browser_test_runner_factory) {
for (std::vector<std::string>::const_iterator iter = test_list.begin();
iter != test_list.end(); ++iter) {
std::string test_name = *iter;
scoped_ptr<BrowserTestRunner> test_runner(
browser_test_runner_factory.CreateBrowserTestRunner());
scoped_ptr<TestRunner> test_runner(test_runner_factory.CreateTestRunner());
if (!test_runner.get() || !test_runner->Init())
return false;
test_run_count++;
......
......@@ -2,34 +2,35 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_TEST_BROWSER_BROWSER_TEST_RUNNER_
#define CHROME_TEST_BROWSER_BROWSER_TEST_RUNNER_
#ifndef CHROME_TEST_TEST_LAUNCHER_TEST_RUNNER_
#define CHROME_TEST_TEST_LAUNCHER_TEST_RUNNER_
#include <string>
#include <vector>
#include "base/basictypes.h"
namespace browser_tests {
namespace tests {
class BrowserTestRunnerFactory;
class TestRunnerFactory;
// Runs the tests specified by the --gtest_filter flag specified in the command
// line that started this process.
// Returns true if all tests succeeded, false if there were no tests to run, or
// one or more tests failed, or if initialization failed.
// Results are printed to stdout.
bool RunTests(const BrowserTestRunnerFactory& browser_test_runner_factory);
bool RunTests(const TestRunnerFactory& test_runner_factory);
// This class defines a way to run browser tests.
// This class defines a way to run tests in an isolated environment (each test
// having its static variables uninitialized).
// There are 2 implementations, in-process and out-of-process.
class BrowserTestRunner {
class TestRunner {
public:
BrowserTestRunner();
virtual ~BrowserTestRunner();
TestRunner();
virtual ~TestRunner();
// Called once before the BrowserTestRunner is used. Gives it an opportunity
// to perform any requried initialization. Should return true if the
// Called once before the TestRunner is used. Gives it an opportunity to
// perform any requried initialization. Should return true if the
// initialization was successful.
virtual bool Init() = 0;
......@@ -38,14 +39,14 @@ class BrowserTestRunner {
virtual bool RunTest(const std::string& test_name) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(BrowserTestRunner);
DISALLOW_COPY_AND_ASSIGN(TestRunner);
};
class BrowserTestRunnerFactory {
class TestRunnerFactory {
public:
virtual BrowserTestRunner* CreateBrowserTestRunner() const = 0;
virtual TestRunner* CreateTestRunner() const = 0;
};
} // namespace
#endif // CHROME_TEST_BROWSER_BROWSER_TEST_RUNNER_
#endif // CHROME_TEST_TEST_LAUNCHER_TEST_RUNNER_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment