Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / chrome_frame / test / run_all_unittests.cc
blob55e21cc06467401a18c6fa89f29bee6e21cf2c63
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
3 // found in the LICENSE file.
5 #include <atlbase.h>
7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h"
9 #include "base/process_util.h"
10 #include "base/test/test_suite.h"
11 #include "base/threading/platform_thread.h"
12 #include "base/win/scoped_com_initializer.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "chrome/common/metrics/entropy_provider.h"
15 #include "chrome/test/logging/win/test_log_collector.h"
16 #include "chrome_frame/crash_server_init.h"
17 #include "chrome_frame/test/chrome_frame_test_utils.h"
18 #include "chrome_frame/test/chrome_frame_ui_test_utils.h"
19 #include "chrome_frame/test/ie_configurator.h"
20 #include "chrome_frame/test/test_scrubber.h"
21 #include "chrome_frame/test_utils.h"
22 #include "chrome_frame/utils.h"
24 // To enable ATL-based code to run in this module
25 class ChromeFrameUnittestsModule
26 : public CAtlExeModuleT<ChromeFrameUnittestsModule> {
27 public:
28 // Called at static init time, for versions of ATL included in VS2008 and
29 // earlier only. The default implementation initializes COM in MTA mode,
30 // which we don't want. We could init STA mode here, but since we have to
31 // init in main() for VS2010 and above anyway, we simply do nothing, since
32 // nothing needs COM before main() runs.
33 static HRESULT InitializeCom() { return S_OK; }
34 static void UninitializeCom() {}
37 ChromeFrameUnittestsModule _AtlModule;
39 const char kNoCrashService[] = "no-crash-service";
40 const char kNoLogCollector[] = "no-log-collector";
41 const char kNoRegistrationSwitch[] = "no-registration";
43 void PureCall() {
44 __debugbreak();
47 int main(int argc, char **argv) {
48 // For ATL in VS2010 and up, ChromeFrameUnittestsModule::InitializeCom() is
49 // not called, so we init COM here.
50 base::win::ScopedCOMInitializer com_initializer_;
52 ScopedChromeFrameRegistrar::RegisterAndExitProcessIfDirected();
53 base::EnableTerminationOnHeapCorruption();
54 base::PlatformThread::SetName("ChromeFrame tests");
56 _set_purecall_handler(PureCall);
58 // Set up a FieldTrialList to keep any field trials we have going in
59 // Chrome Frame happy.
60 base::FieldTrialList field_trial_list(new metrics::SHA1EntropyProvider("42"));
62 base::TestSuite test_suite(argc, argv);
64 SetConfigBool(kChromeFrameHeadlessMode, true);
65 SetConfigBool(kChromeFrameAccessibleMode, true);
67 base::ProcessHandle crash_service = NULL;
68 google_breakpad::scoped_ptr<google_breakpad::ExceptionHandler> breakpad;
70 if (!CommandLine::ForCurrentProcess()->HasSwitch(kNoCrashService)) {
71 crash_service = chrome_frame_test::StartCrashService();
73 breakpad.reset(InitializeCrashReporting(HEADLESS));
76 // Install the log collector before anything else that adds a Google Test
77 // event listener so that it's the last one to run after each test (the
78 // listeners are invoked in reverse order at the end of a test). This allows
79 // the collector to emit logs if other listeners ADD_FAILURE or EXPECT_*.
80 if (!CommandLine::ForCurrentProcess()->HasSwitch(kNoLogCollector))
81 logging_win::InstallTestLogCollector(testing::UnitTest::GetInstance());
83 chrome_frame_test::InstallIEConfigurator();
85 chrome_frame_test::InstallTestScrubber(testing::UnitTest::GetInstance());
87 int ret = -1;
88 // If mini_installer is used to register CF, we use the switch
89 // --no-registration to avoid repetitive registration.
90 if (CommandLine::ForCurrentProcess()->HasSwitch(kNoRegistrationSwitch)) {
91 ret = test_suite.Run();
92 } else {
93 // This will register the chrome frame in the build directory. It currently
94 // leaves that chrome frame registered once the tests are done. It must be
95 // constructed AFTER the TestSuite is created since TestSuites create THE
96 // AtExitManager.
97 // TODO(robertshield): Make these tests restore the original registration
98 // once done.
99 ScopedChromeFrameRegistrar registrar(chrome_frame_test::GetTestBedType());
101 // Register IAccessible2 proxy stub DLL, needed for some tests.
102 ScopedChromeFrameRegistrar ia2_registrar(
103 chrome_frame_test::GetIAccessible2ProxyStubPath().value(),
104 ScopedChromeFrameRegistrar::SYSTEM_LEVEL);
105 ret = test_suite.Run();
108 DeleteConfigValue(kChromeFrameHeadlessMode);
109 DeleteConfigValue(kChromeFrameAccessibleMode);
111 if (crash_service)
112 base::KillProcess(crash_service, 0, false);
113 return ret;