1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
// Copyright (c) 2006-2008 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 <atlbase.h>
#include <iostream>
#include "base/at_exit.h"
#include "base/path_service.h"
#include "base/platform_thread.h"
#include "base/process_util.h"
#include "base/sys_info.h"
#include "chrome/common/env_vars.h"
#include "base/test/test_suite.h"
#include "base/command_line.h"
#include "chrome/common/chrome_paths.h"
#include "chrome_frame/test/http_server.h"
#include "chrome_frame/test_utils.h"
#include "chrome_frame/utils.h"
// To enable ATL-based code to run in this module
class ChromeFrameUnittestsModule
: public CAtlExeModuleT<ChromeFrameUnittestsModule> {
public:
static HRESULT InitializeCom() {
return CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
}
};
ChromeFrameUnittestsModule _AtlModule;
const wchar_t kNoRegistrationSwitch[] = L"no-registration";
// Causes the test executable to just run the web server and quit when the
// server is killed. Useful for debugging tests.
const wchar_t kRunAsServer[] = L"server";
base::ProcessHandle LoadCrashService() {
FilePath exe_dir;
if (!PathService::Get(base::DIR_EXE, &exe_dir)) {
DCHECK(false);
return NULL;
}
base::ProcessHandle crash_service = NULL;
FilePath crash_service_path = exe_dir.Append(L"crash_service.exe");
if (!base::LaunchApp(crash_service_path.ToWStringHack(), false, false,
&crash_service)) {
printf("Couldn't start crash_service.exe, so this test run won't tell " \
"you if any test crashes!\n");
return NULL;
}
printf("Started crash_service.exe so you know if a test crashes!\n");
// This sleep is to ensure that the crash service is done initializing, i.e
// the pipe creation, etc.
Sleep(500);
return crash_service;
}
void PureCall() {
__debugbreak();
}
int main(int argc, char **argv) {
base::EnableTerminationOnHeapCorruption();
PlatformThread::SetName("ChromeFrame tests");
_set_purecall_handler(PureCall);
TestSuite test_suite(argc, argv);
if (CommandLine::ForCurrentProcess()->HasSwitch(kRunAsServer)) {
ChromeFrameHTTPServer server;
server.SetUp();
GURL server_url(server.server()->TestServerPage(""));
std::cout << std::endl
<< "Server waiting on " << server_url.spec().c_str()
<< std::endl << std::endl
<< "Test output will be written to "
<< server.server()->GetDataDirectory().value().c_str() << "\\dump"
<< std::endl << std::endl
<< "Hit Ctrl-C or navigate to "
<< server_url.spec().c_str() << "kill to shut down the server."
<< std::endl;
server.WaitToFinish(INFINITE);
server.TearDown();
std::cout << "Server stopped.";
return 0;
}
SetConfigBool(kChromeFrameHeadlessMode, true);
base::ProcessHandle crash_service = LoadCrashService();
int ret = -1;
// If mini_installer is used to register CF, we use the switch
// --no-registration to avoid repetitive registration.
if (CommandLine::ForCurrentProcess()->HasSwitch(kNoRegistrationSwitch)) {
ret = test_suite.Run();
} else {
// Register paths needed by the ScopedChromeFrameRegistrar.
chrome::RegisterPathProvider();
// This will register the chrome frame in the build directory. It currently
// leaves that chrome frame registered once the tests are done. It must be
// constructed AFTER the TestSuite is created since TestSuites create THE
// AtExitManager.
// TODO(robertshield): Make these tests restore the original registration
// once done.
ScopedChromeFrameRegistrar registrar;
ret = test_suite.Run();
}
DeleteConfigValue(kChromeFrameHeadlessMode);
if (crash_service)
base::KillProcess(crash_service, 0, false);
}
|