diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-28 17:17:10 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-28 17:17:10 +0000 |
commit | 76fdc21de47ba710cd71f1d06ca55362b118c390 (patch) | |
tree | d9ec9563c0229fbce61def9bb34b24bf713c11a5 /chrome/test/browser | |
parent | e19516d9748c6bfc5798880dc0bbe03374d722c4 (diff) | |
download | chromium_src-76fdc21de47ba710cd71f1d06ca55362b118c390.zip chromium_src-76fdc21de47ba710cd71f1d06ca55362b118c390.tar.gz chromium_src-76fdc21de47ba710cd71f1d06ca55362b118c390.tar.bz2 |
Relanding this:
This patch adds a new kind of tests: browser tests.
They are intended to provide an alternative to the UI tests, hopefully helping
with flackiness.
These tests are in-process browser test.
There are 2 projects to build the tests:
- the browser_test.dll that contains the tests, the gtest framework and the
browser classes.
- the browser_test_launcher.exe.
The launcher loads the browser_test.dll for each test, run the test and then
unloads the DLL. This insures the static initializers are run before each test
and that any atexit handler is invoked properly.
This is Windows only for now.
BUG=9764
TEST=Run browser_test.exe
TBR=maruel
Review URL: http://codereview.chromium.org/99097
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14738 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/browser')
-rw-r--r-- | chrome/test/browser/browser_tests_dll.vcproj | 304 | ||||
-rw-r--r-- | chrome/test/browser/browser_tests_launcher.cc | 174 | ||||
-rw-r--r-- | chrome/test/browser/browser_tests_launcher.vcproj | 160 | ||||
-rw-r--r-- | chrome/test/browser/run_all_unittests.cc | 45 |
4 files changed, 683 insertions, 0 deletions
diff --git a/chrome/test/browser/browser_tests_dll.vcproj b/chrome/test/browser/browser_tests_dll.vcproj new file mode 100644 index 0000000..8c1658f --- /dev/null +++ b/chrome/test/browser/browser_tests_dll.vcproj @@ -0,0 +1,304 @@ +<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="browser_tests_dll"
+ ProjectGUID="{D7589D0D-304E-4589-85A4-153B7D84B07F}"
+ RootNamespace="browser_tests_dll"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ <ToolFile
+ RelativePath="..\..\tools\build\win\version.rules"
+ />
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ ConfigurationType="2"
+ InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\debug.vsprops;$(SolutionDir)..\testing\using_gtest.vsprops;$(SolutionDir)installer\util\using_util.vsprops;$(SolutionDir)..\third_party\ffmpeg\using_ffmpeg.vsprops;$(SolutionDir)..\third_party\libpng\using_libpng.vsprops;$(SolutionDir)..\third_party\zlib\using_zlib.vsprops;$(SolutionDir)..\skia\using_skia.vsprops;$(SolutionDir)..\third_party\libxml\build\using_libxml.vsprops;$(SolutionDir)..\third_party\icu38\build\using_icu.vsprops;$(SolutionDir)..\third_party\npapi\using_npapi.vsprops;$(SolutionDir)tools\build\win\browser_tests_dll.vsprops;$(SolutionDir)tools\build\win\precompiled_wtl.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="Version"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)\browser_tests.dll"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ ConfigurationType="2"
+ InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\testing\using_gtest.vsprops;$(SolutionDir)installer\util\using_util.vsprops;$(SolutionDir)..\third_party\ffmpeg\using_ffmpeg.vsprops;$(SolutionDir)..\third_party\libpng\using_libpng.vsprops;$(SolutionDir)..\third_party\zlib\using_zlib.vsprops;$(SolutionDir)..\skia\using_skia.vsprops;$(SolutionDir)..\third_party\libxml\build\using_libxml.vsprops;$(SolutionDir)..\third_party\icu38\build\using_icu.vsprops;$(SolutionDir)..\third_party\npapi\using_npapi.vsprops;$(SolutionDir)tools\build\win\browser_tests_dll.vsprops;$(SolutionDir)tools\build\win\precompiled_wtl.vsprops;$(SolutionDir)..\build\release.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="Version"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)\browser_tests.dll"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Common"
+ >
+ <File
+ RelativePath="..\unit\chrome_test_suite.h"
+ >
+ </File>
+ <File
+ RelativePath="..\in_process_browser_test.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\in_process_browser_test.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\tools\build\win\precompiled_wtl.cc"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="1"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="1"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\..\tools\build\win\precompiled_wtl.h"
+ >
+ </File>
+ <File
+ RelativePath=".\run_all_unittests.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\ui_test_utils.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\ui_test_utils.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="TestSSL"
+ >
+ <File
+ RelativePath="..\..\browser\ssl\ssl_browser_tests.cc"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="resources"
+ >
+ <File
+ RelativePath="..\..\..\webkit\glue\resources\aliasb.cur"
+ >
+ </File>
+ <File
+ RelativePath="$(OutDir)\grit_derived_sources\browser_resources.rc"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\webkit\glue\resources\cell.cur"
+ >
+ </File>
+ <File
+ RelativePath="..\..\app\chrome_dll.rc"
+ >
+ </File>
+ <File
+ RelativePath="..\..\app\chrome_dll_resource.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\app\chrome_dll_version.rc.version"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\webkit\glue\resources\col_resize.cur"
+ >
+ </File>
+ <File
+ RelativePath="$(OutDir)\grit_derived_sources\common_resources.rc"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\webkit\glue\resources\copy.cur"
+ >
+ </File>
+ <File
+ RelativePath="$(OutDir)\grit_derived_sources\debugger_resources.rc"
+ >
+ </File>
+ <File
+ RelativePath="$(OutDir)\obj\global_intermediate\net\net_resources.rc"
+ >
+ </File>
+ <File
+ RelativePath="$(OutDir)\grit_derived_sources\renderer_resources.rc"
+ >
+ </File>
+ <File
+ RelativePath="..\data\resource.h"
+ >
+ </File>
+ <File
+ RelativePath="..\data\resource.rc"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\webkit\glue\resources\row_resize.cur"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\webkit\glue\resources\vertical_text.cur"
+ >
+ </File>
+ <File
+ RelativePath="$(OutDir)\grit_derived_sources\webkit_resources.rc"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\webkit\glue\resources\zoom_in.cur"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\webkit\glue\resources\zoom_out.cur"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="TestFindInPage"
+ >
+ <File
+ RelativePath="..\..\browser\views\find_bar_win_browsertest.cc"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/chrome/test/browser/browser_tests_launcher.cc b/chrome/test/browser/browser_tests_launcher.cc new file mode 100644 index 0000000..34ec60c --- /dev/null +++ b/chrome/test/browser/browser_tests_launcher.cc @@ -0,0 +1,174 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <windows.h> + +#include <vector> + +#include "base/command_line.h" +#include "base/logging.h" +#include "base/process_util.h" +#include "base/string_util.h" + +namespace { + +const wchar_t* const kBrowserTestDLLName = L"browser_tests.dll"; +const wchar_t* const kGTestListTestsFlag = L"gtest_list_tests"; +} + +// TestEnvContext takes care of loading/unloading the DLL containing the tests. +class TestEnvContext { + public: + TestEnvContext() + : module_(NULL), + run_test_proc_(NULL) { + } + + ~TestEnvContext() { + if (!module_) + return; + BOOL r = ::FreeLibrary(module_); + DCHECK(r); + LOG(INFO) << "Unloaded " << kBrowserTestDLLName; + } + + bool Init() { + module_ = ::LoadLibrary(kBrowserTestDLLName); + if (!module_) { + LOG(ERROR) << "Failed to find " << kBrowserTestDLLName; + return false; + } + + run_test_proc_ = reinterpret_cast<RunTestProc>( + ::GetProcAddress(module_, "RunTests")); + if (!run_test_proc_) { + LOG(ERROR) << + "Failed to find RunTest function in " << kBrowserTestDLLName; + return false; + } + + return true; + } + + // Returns true if the test succeeded, false if it failed. + bool RunTest(const std::string& test_name) { + std::string filter_flag = StringPrintf("--gtest_filter=%s", + test_name.c_str()); + char* argv[2]; + argv[0] = ""; + argv[1] = const_cast<char*>(filter_flag.c_str()); + return RunAsIs(2, argv) == 0; + } + + // Calls-in to GTest with the arguments we were started with. + int RunAsIs(int argc, char** argv) { + return (run_test_proc_)(argc, argv); + } + + private: + typedef int (__cdecl *RunTestProc)(int, char**); + + HMODULE module_; + RunTestProc run_test_proc_; +}; + +// Retrieves the list of tests to run. +// Simply uses the --gtest_list_tests option which honor the filter. +// Sadly there is no dry-run option (or willingness to get such an option) in +// GTest. So we'll have to process disabled and repeat options ourselves. +bool GetTestList(const CommandLine& command_line, + std::vector<std::string>* test_list) { + DCHECK(!command_line.HasSwitch(kGTestListTestsFlag)); + + // Run ourselves with the --gtest_list_tests option and read the output. + std::wstring new_command_line = command_line.command_line_string() + L" --" + + kGTestListTestsFlag; + std::string output; + if (!base::GetAppOutput(new_command_line, &output)) + return false; + + // Now let's parse the returned output. + // It looks like: + // TestCase. + // Test1 + // Test2 + // OtherTestCase. + // FooTest + // ... + std::vector<std::string> lines; + SplitString(output, '\n', &lines); + + std::string test_case; + for (std::vector<std::string>::const_iterator iter = lines.begin(); + iter != lines.end(); ++iter) { + std::string line = *iter; + if (line.empty()) + continue; // Just ignore empty lines if any. + + if (line[line.size() - 1] == '.') { + // This is a new test case. + test_case = line; + continue; + } + // We are dealing with a test. + test_list->push_back(test_case + line); + } + return true; +} + +int main(int argc, char** argv) { + CommandLine::Init(argc, argv); + const CommandLine* command_line = CommandLine::ForCurrentProcess(); + + if (command_line->HasSwitch(kGTestListTestsFlag)) { + TestEnvContext test_context; + if (!test_context.Init()) + return 1; + return test_context.RunAsIs(argc, argv); + } + + // First let's get the list of tests we need to run. + std::vector<std::string> test_list; + if (!GetTestList(*command_line, &test_list)) { + printf("Failed to retrieve the tests to run.\n"); + return 0; + } + + if (test_list.empty()) { + printf("No tests to run.\n"); + return 0; + } + + // Run the tests. + int test_run_count = 0; + std::vector<std::string> failed_tests; + for (std::vector<std::string>::const_iterator iter = test_list.begin(); + iter != test_list.end(); ++iter) { + std::string test_name = *iter; + TestEnvContext test_context; + if (!test_context.Init()) + return 1; + test_run_count++; + if (!test_context.RunTest(test_name.c_str())) { + if (std::find(failed_tests.begin(), failed_tests.end(), test_name) == + failed_tests.end()) { + failed_tests.push_back(*iter); + } + } + } + + printf("%d test%s run\n", test_run_count, test_run_count > 1 ? "s" : ""); + printf("%d test%s failed\n", failed_tests.size(), + failed_tests.size() > 1 ? "s" : ""); + if (failed_tests.empty()) + return 0; + + printf("Failing tests:\n"); + for (std::vector<std::string>::const_iterator iter = failed_tests.begin(); + iter != failed_tests.end(); ++iter) { + printf("%s\n", iter->c_str()); + } + + return 1; +} diff --git a/chrome/test/browser/browser_tests_launcher.vcproj b/chrome/test/browser/browser_tests_launcher.vcproj new file mode 100644 index 0000000..ee1c651 --- /dev/null +++ b/chrome/test/browser/browser_tests_launcher.vcproj @@ -0,0 +1,160 @@ +<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="browser_tests_launcher"
+ ProjectGUID="{9B87804D-2502-480B-95AE-5A572CE91809}"
+ RootNamespace="browser_tests_launcher"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ <ToolFile
+ RelativePath="..\..\tools\build\win\version.rules"
+ />
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\debug.vsprops;$(SolutionDir)installer\util\using_util.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="Version"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)\browser_tests.exe"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\release.vsprops;$(SolutionDir)installer\util\using_util.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="Version"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)\browser_tests.exe"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <File
+ RelativePath=".\browser_tests_launcher.cc"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/chrome/test/browser/run_all_unittests.cc b/chrome/test/browser/run_all_unittests.cc new file mode 100644 index 0000000..f8f7d57 --- /dev/null +++ b/chrome/test/browser/run_all_unittests.cc @@ -0,0 +1,45 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/string_util.h" +#include "chrome/test/unit/chrome_test_suite.h" + +#if defined(OS_WIN) +#define DLLEXPORT __declspec(dllexport) +#elif +#define DLLEXPORT +#endif + +// We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. +extern "C" { +DLLEXPORT int __cdecl RunTests(int argc, char **argv) { + return ChromeTestSuite(argc, argv).Run(); +} +} + +#if defined(OS_WIN) +BOOL WINAPI DllMain(HINSTANCE dll_module, DWORD reason, LPVOID reserved) { + if (reason == DLL_PROCESS_DETACH) { + // The CRichEditCtrl (used by the omnibox) calls OleInitialize, but somehow + // does not always calls OleUninitialize, causing an unbalanced Ole + // initialization that triggers a DCHECK in ScopedOleInitializer the next + // time we run a test. + // This behavior has been seen on some Vista boxes, but not all of them. + // There is a flag to prevent Ole initialization in CRichEditCtrl (see + // http://support.microsoft.com/kb/238989), but it is set to 0 in recent + // Windows versions. + // This is a dirty hack to make sure the OleCount is back to 0 in all cases, + // so the next test will have Ole unitialized, as expected. + + if (OleInitialize(NULL) == S_FALSE) { + // We were already initialized, balance that extra-initialization. + OleUninitialize(); + } + // Balance the OleInitialize from the above test. + OleUninitialize(); + } + return TRUE; +} + +#endif |