1 // Copyright (c) 2010 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.
8 #include "base/path_service.h"
9 #include "base/platform_thread.h"
10 #include "base/process_util.h"
11 #include "base/sys_info.h"
12 #include "chrome/common/env_vars.h"
13 #include "base/test/test_suite.h"
14 #include "base/command_line.h"
15 #include "chrome/common/chrome_paths.h"
17 #include "chrome_frame/test/chrome_frame_test_utils.h"
18 #include "chrome_frame/test/http_server.h"
19 #include "chrome_frame/test_utils.h"
20 #include "chrome_frame/utils.h"
22 // To enable ATL-based code to run in this module
23 class ChromeFrameUnittestsModule
24 : public CAtlExeModuleT
<ChromeFrameUnittestsModule
> {
26 static HRESULT
InitializeCom() {
27 return CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
31 ChromeFrameUnittestsModule _AtlModule
;
33 const wchar_t kNoRegistrationSwitch
[] = L
"no-registration";
35 // Causes the test executable to just run the web server and quit when the
36 // server is killed. Useful for debugging tests.
37 const wchar_t kRunAsServer
[] = L
"server";
43 int main(int argc
, char **argv
) {
44 base::EnableTerminationOnHeapCorruption();
45 PlatformThread::SetName("ChromeFrame tests");
47 _set_purecall_handler(PureCall
);
49 TestSuite
test_suite(argc
, argv
);
51 if (CommandLine::ForCurrentProcess()->HasSwitch(kRunAsServer
)) {
52 ChromeFrameHTTPServer server
;
54 GURL
server_url(server
.server()->TestServerPage(""));
55 std::cout
<< std::endl
56 << "Server waiting on " << server_url
.spec().c_str()
57 << std::endl
<< std::endl
58 << "Test output will be written to "
59 << server
.server()->GetDataDirectory().value().c_str() << "\\dump"
60 << std::endl
<< std::endl
61 << "Hit Ctrl-C or navigate to "
62 << server_url
.spec().c_str() << "kill to shut down the server."
64 server
.WaitToFinish(INFINITE
);
66 std::cout
<< "Server stopped.";
70 SetConfigBool(kChromeFrameHeadlessMode
, true);
72 base::ProcessHandle crash_service
= chrome_frame_test::StartCrashService();
74 // If mini_installer is used to register CF, we use the switch
75 // --no-registration to avoid repetitive registration.
76 if (CommandLine::ForCurrentProcess()->HasSwitch(kNoRegistrationSwitch
)) {
77 ret
= test_suite
.Run();
79 // Register paths needed by the ScopedChromeFrameRegistrar.
80 chrome::RegisterPathProvider();
82 // This will register the chrome frame in the build directory. It currently
83 // leaves that chrome frame registered once the tests are done. It must be
84 // constructed AFTER the TestSuite is created since TestSuites create THE
86 // TODO(robertshield): Make these tests restore the original registration
88 ScopedChromeFrameRegistrar registrar
;
89 ret
= test_suite
.Run();
92 DeleteConfigValue(kChromeFrameHeadlessMode
);
95 base::KillProcess(crash_service
, 0, false);