OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include <atlbase.h> | |
6 | |
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/test/logging/win/test_log_collector.h" | |
15 #include "chrome_frame/crash_server_init.h" | |
16 #include "chrome_frame/test/chrome_frame_test_utils.h" | |
17 #include "chrome_frame/test/chrome_frame_ui_test_utils.h" | |
18 #include "chrome_frame/test/ie_configurator.h" | |
19 #include "chrome_frame/test/test_scrubber.h" | |
20 #include "chrome_frame/test_utils.h" | |
21 #include "chrome_frame/utils.h" | |
22 #include "components/variations/entropy_provider.h" | |
23 | |
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() {} | |
35 }; | |
36 | |
37 ChromeFrameUnittestsModule _AtlModule; | |
38 | |
39 const char kNoCrashService[] = "no-crash-service"; | |
40 const char kNoLogCollector[] = "no-log-collector"; | |
41 const char kNoRegistrationSwitch[] = "no-registration"; | |
42 | |
43 void PureCall() { | |
44 __debugbreak(); | |
45 } | |
46 | |
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_; | |
51 | |
52 ScopedChromeFrameRegistrar::RegisterAndExitProcessIfDirected(); | |
53 base::EnableTerminationOnHeapCorruption(); | |
54 base::PlatformThread::SetName("ChromeFrame tests"); | |
55 | |
56 _set_purecall_handler(PureCall); | |
57 | |
58 base::TestSuite test_suite(argc, argv); | |
59 | |
60 SetConfigBool(kChromeFrameHeadlessMode, true); | |
61 SetConfigBool(kChromeFrameAccessibleMode, true); | |
62 | |
63 base::ProcessHandle crash_service = NULL; | |
64 google_breakpad::scoped_ptr<google_breakpad::ExceptionHandler> breakpad; | |
65 | |
66 if (!CommandLine::ForCurrentProcess()->HasSwitch(kNoCrashService)) { | |
67 crash_service = chrome_frame_test::StartCrashService(); | |
68 | |
69 breakpad.reset(InitializeCrashReporting(HEADLESS)); | |
70 } | |
71 | |
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()); | |
78 | |
79 chrome_frame_test::InstallIEConfigurator(); | |
80 | |
81 chrome_frame_test::InstallTestScrubber(testing::UnitTest::GetInstance()); | |
82 | |
83 int ret = -1; | |
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(); | |
88 } else { | |
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 | |
92 // AtExitManager. | |
93 // TODO(robertshield): Make these tests restore the original registration | |
94 // once done. | |
95 ScopedChromeFrameRegistrar registrar(chrome_frame_test::GetTestBedType()); | |
96 | |
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(); | |
102 } | |
103 | |
104 DeleteConfigValue(kChromeFrameHeadlessMode); | |
105 DeleteConfigValue(kChromeFrameAccessibleMode); | |
106 | |
107 if (crash_service) | |
108 base::KillProcess(crash_service, 0, false); | |
109 return ret; | |
110 } | |
OLD | NEW |