Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: webkit/tools/test_shell/test_shell_main.cc

Issue 15028002: Delete test_shell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add dummy test_shell build target. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "base/at_exit.h"
6 #include "base/basictypes.h"
7 #include "base/command_line.h"
8 #include "base/debug/stack_trace.h"
9 #include "base/debug/trace_event.h"
10 #include "base/environment.h"
11 #include "base/event_recorder.h"
12 #include "base/file_util.h"
13 #include "base/files/file_path.h"
14 #include "base/i18n/icu_util.h"
15 #include "base/message_loop.h"
16 #include "base/metrics/stats_table.h"
17 #include "base/path_service.h"
18 #include "base/process_util.h"
19 #include "base/rand_util.h"
20 #include "base/strings/string_number_conversions.h"
21 #include "base/sys_info.h"
22 #include "base/utf_string_conversions.h"
23 #include "net/base/net_module.h"
24 #include "net/base/net_util.h"
25 #include "net/cookies/cookie_monster.h"
26 #include "net/http/http_cache.h"
27 #include "net/http/http_util.h"
28 #include "net/test/spawned_test_server.h"
29 #include "net/url_request/url_request_context.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h "
32 #include "ui/base/window_open_disposition.h"
33 #include "ui/gl/gl_implementation.h"
34 #include "ui/gl/gl_switches.h"
35 #include "webkit/glue/webkit_glue.h"
36 #include "webkit/glue/webpreferences.h"
37 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
38 #include "webkit/tools/test_shell/test_shell.h"
39 #include "webkit/tools/test_shell/test_shell_platform_delegate.h"
40 #include "webkit/tools/test_shell/test_shell_request_context.h"
41 #include "webkit/tools/test_shell/test_shell_switches.h"
42 #include "webkit/tools/test_shell/test_shell_webkit_init.h"
43
44 #if defined(OS_WIN)
45 #pragma warning(disable: 4996)
46 #endif
47
48 static const size_t kPathBufSize = 2048;
49
50 using WebKit::WebScriptController;
51
52 namespace {
53
54 // StatsTable initialization parameters.
55 const char* const kStatsFilePrefix = "testshell_";
56 int kStatsFileThreads = 20;
57 int kStatsFileCounters = 200;
58
59 void RemoveSharedMemoryFile(std::string& filename) {
60 // Stats uses SharedMemory under the hood. On posix, this results in a file
61 // on disk.
62 #if defined(OS_POSIX)
63 base::SharedMemory memory;
64 memory.Delete(filename);
65 #endif
66 }
67
68 } // namespace
69
70 int main(int argc, char* argv[]) {
71 base::debug::EnableInProcessStackDumping();
72 base::EnableTerminationOnHeapCorruption();
73
74 // Some tests may use base::Singleton<>, thus we need to instanciate
75 // the AtExitManager or else we will leak objects.
76 base::AtExitManager at_exit_manager;
77
78 TestShellPlatformDelegate::PreflightArgs(&argc, &argv);
79 CommandLine::Init(argc, argv);
80 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
81
82 TestShellPlatformDelegate platform(parsed_command_line);
83
84 if (parsed_command_line.HasSwitch(test_shell::kStartupDialog))
85 TestShell::ShowStartupDebuggingDialog();
86
87 if (parsed_command_line.HasSwitch(test_shell::kCheckLayoutTestSystemDeps)) {
88 exit(platform.CheckLayoutTestSystemDependencies() ? 0 : 1);
89 }
90
91 // Allocate a message loop for this thread. Although it is not used
92 // directly, its constructor sets up some necessary state.
93 MessageLoopForUI main_message_loop;
94
95 scoped_ptr<base::Environment> env(base::Environment::Create());
96 bool suppress_error_dialogs = (
97 env->HasVar("CHROME_HEADLESS") ||
98 parsed_command_line.HasSwitch(test_shell::kNoErrorDialogs));
99 bool ux_theme = parsed_command_line.HasSwitch(test_shell::kUxTheme);
100 #if defined(OS_MACOSX)
101 // The "classic theme" flag is meaningless on OS X. But there is a bunch
102 // of code that sets up the environment for running pixel tests that only
103 // runs if it's set to true.
104 bool classic_theme = true;
105 #else
106 bool classic_theme =
107 parsed_command_line.HasSwitch(test_shell::kClassicTheme);
108 #endif // !OS_MACOSX
109 #if defined(OS_WIN)
110 bool generic_theme = parsed_command_line.HasSwitch(test_shell::kGenericTheme);
111 #else
112 // Stop compiler warnings about unused variables.
113 static_cast<void>(ux_theme);
114 #endif
115
116 bool enable_gp_fault_error_box = false;
117 enable_gp_fault_error_box =
118 parsed_command_line.HasSwitch(test_shell::kGPFaultErrorBox);
119
120 bool allow_external_pages =
121 parsed_command_line.HasSwitch(test_shell::kAllowExternalPages);
122
123 if (parsed_command_line.HasSwitch(test_shell::kEnableAccel2DCanvas))
124 TestShell::SetAccelerated2dCanvasEnabled(true);
125 if (parsed_command_line.HasSwitch(test_shell::kEnableAccelCompositing))
126 TestShell::SetAcceleratedCompositingEnabled(true);
127
128 bool layout_test_mode = false;
129 TestShell::InitLogging(suppress_error_dialogs,
130 layout_test_mode,
131 enable_gp_fault_error_box);
132
133 // Initialize WebKit for this scope.
134 TestShellWebKitInit test_shell_webkit_init(layout_test_mode);
135
136 // Suppress abort message in v8 library in debugging mode (but not
137 // actually under a debugger). V8 calls abort() when it hits
138 // assertion errors.
139 if (suppress_error_dialogs) {
140 platform.SuppressErrorReporting();
141 }
142
143 net::HttpCache::Mode cache_mode = net::HttpCache::NORMAL;
144
145 if (parsed_command_line.HasSwitch(test_shell::kEnableFileCookies))
146 net::CookieMonster::EnableFileScheme();
147
148 base::FilePath cache_path =
149 parsed_command_line.GetSwitchValuePath(test_shell::kCacheDir);
150 if (cache_path.empty()) {
151 PathService::Get(base::DIR_EXE, &cache_path);
152 cache_path = cache_path.AppendASCII("cache");
153 }
154
155 // Initializing with a default context, which means no on-disk cookie DB,
156 // and no support for directory listings.
157 SimpleResourceLoaderBridge::Init(cache_path, cache_mode, layout_test_mode);
158
159 // Load ICU data tables
160 icu_util::Initialize();
161
162 // Config the modules that need access to a limited set of resources.
163 net::NetModule::SetResourceProvider(TestShell::ResourceProvider);
164
165 platform.InitializeGUI();
166
167 TestShell::InitializeTestShell(layout_test_mode, allow_external_pages);
168
169 if (parsed_command_line.HasSwitch(test_shell::kAllowScriptsToCloseWindows))
170 TestShell::SetAllowScriptsToCloseWindows();
171
172 if (parsed_command_line.HasSwitch(test_shell::kEnableSmoothScrolling))
173 TestShell::GetWebPreferences()->enable_scroll_animator = true;
174
175 // Disable user themes for layout tests so pixel tests are consistent.
176 #if defined(OS_WIN)
177 TestShellWebTheme::Engine engine;
178 #endif
179 if (classic_theme)
180 platform.SelectUnifiedTheme();
181 #if defined(OS_WIN)
182 if (generic_theme)
183 test_shell_webkit_init.SetThemeEngine(&engine);
184 #endif
185
186 // Unless specifically requested otherwise, default to OSMesa for GL.
187 if (!parsed_command_line.HasSwitch(switches::kUseGL))
188 gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL);
189
190 // Treat the first argument as the initial URL to open.
191 GURL starting_url;
192
193 base::FilePath path;
194 PathService::Get(base::DIR_SOURCE_ROOT, &path);
195 path = path.AppendASCII("webkit").AppendASCII("data")
196 .AppendASCII("test_shell").AppendASCII("index.html");
197 starting_url = net::FilePathToFileURL(path);
198
199 const CommandLine::StringVector& args = parsed_command_line.GetArgs();
200 if (!args.empty()) {
201 GURL url(args[0]);
202 if (url.is_valid()) {
203 starting_url = url;
204 } else {
205 // Treat as a relative file path.
206 base::FilePath path = base::MakeAbsoluteFilePath(base::FilePath(args[0]));
207 starting_url = net::FilePathToFileURL(path);
208 }
209 }
210
211 // Get the JavaScript flags. The test runner might send a quoted string which
212 // needs to be unquoted before further processing.
213 std::string js_flags =
214 parsed_command_line.GetSwitchValueASCII(test_shell::kJavaScriptFlags);
215 js_flags = net::HttpUtil::Unquote(js_flags);
216 // Split the JavaScript flags into a list.
217 std::vector<std::string> js_flags_list;
218 size_t start = 0;
219 while (true) {
220 size_t comma_pos = js_flags.find_first_of(',', start);
221 std::string flags;
222 if (comma_pos == std::string::npos) {
223 flags = js_flags.substr(start, js_flags.length() - start);
224 } else {
225 flags = js_flags.substr(start, comma_pos - start);
226 start = comma_pos + 1;
227 }
228 js_flags_list.push_back(flags);
229 if (comma_pos == std::string::npos)
230 break;
231 }
232 TestShell::SetJavaScriptFlags(js_flags_list);
233
234 // Test shell always exposes the GC.
235 webkit_glue::SetJavaScriptFlags("--expose-gc");
236
237 // Load and initialize the stats table. Attempt to construct a somewhat
238 // unique name to isolate separate instances from each other.
239
240 // truncate the random # to 32 bits for the benefit of Mac OS X, to
241 // avoid tripping over its maximum shared memory segment name length
242 std::string stats_filename = kStatsFilePrefix +
243 base::Uint64ToString(base::RandUint64() & 0xFFFFFFFFL);
244 RemoveSharedMemoryFile(stats_filename);
245 base::StatsTable *table = new base::StatsTable(stats_filename,
246 kStatsFileThreads,
247 kStatsFileCounters);
248 base::StatsTable::set_current(table);
249
250 TestShell* shell;
251 if (TestShell::CreateNewWindow(starting_url, &shell)) {
252 shell->Show(WebKit::WebNavigationPolicyNewWindow);
253
254 if (parsed_command_line.HasSwitch(test_shell::kDumpStatsTable))
255 shell->DumpStatsTableOnExit();
256
257 webkit_glue::SetJavaScriptFlags(TestShell::GetJSFlagsForLoad(0));
258 MessageLoop::current()->Run();
259 }
260
261 TestShell::ShutdownTestShell();
262 TestShell::CleanupLogging();
263
264 // Tear down shared StatsTable; prevents unit_tests from leaking it.
265 base::StatsTable::set_current(NULL);
266 delete table;
267 RemoveSharedMemoryFile(stats_filename);
268
269 return 0;
270 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698