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.
7 #include "base/command_line.h"
8 #include "base/process/kill.h"
9 #include "base/process/memory.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
> {
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";
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 base::TestSuite
test_suite(argc
, argv
);
60 SetConfigBool(kChromeFrameHeadlessMode
, true);
61 SetConfigBool(kChromeFrameAccessibleMode
, true);
63 base::ProcessHandle crash_service
= NULL
;
64 google_breakpad::scoped_ptr
<google_breakpad::ExceptionHandler
> breakpad
;
66 if (!CommandLine::ForCurrentProcess()->HasSwitch(kNoCrashService
)) {
67 crash_service
= chrome_frame_test::StartCrashService();
69 breakpad
.reset(InitializeCrashReporting(HEADLESS
));
72 // Install the log collector before anything else that adds a Google Test
73 // event listener so that it's the last one to run after each test (the
74 // listeners are invoked in reverse order at the end of a test). This allows
75 // the collector to emit logs if other listeners ADD_FAILURE or EXPECT_*.
76 if (!CommandLine::ForCurrentProcess()->HasSwitch(kNoLogCollector
))
77 logging_win::InstallTestLogCollector(testing::UnitTest::GetInstance());
79 chrome_frame_test::InstallIEConfigurator();
81 chrome_frame_test::InstallTestScrubber(testing::UnitTest::GetInstance());
84 // If mini_installer is used to register CF, we use the switch
85 // --no-registration to avoid repetitive registration.
86 if (CommandLine::ForCurrentProcess()->HasSwitch(kNoRegistrationSwitch
)) {
87 ret
= test_suite
.Run();
89 // This will register the chrome frame in the build directory. It currently
90 // leaves that chrome frame registered once the tests are done. It must be
91 // constructed AFTER the TestSuite is created since TestSuites create THE
93 // TODO(robertshield): Make these tests restore the original registration
95 ScopedChromeFrameRegistrar
registrar(chrome_frame_test::GetTestBedType());
97 // Register IAccessible2 proxy stub DLL, needed for some tests.
98 ScopedChromeFrameRegistrar
ia2_registrar(
99 chrome_frame_test::GetIAccessible2ProxyStubPath().value(),
100 ScopedChromeFrameRegistrar::SYSTEM_LEVEL
);
101 ret
= test_suite
.Run();
104 DeleteConfigValue(kChromeFrameHeadlessMode
);
105 DeleteConfigValue(kChromeFrameAccessibleMode
);
108 base::KillProcess(crash_service
, 0, false);