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

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

Issue 99266: Deprecate wstring version of PathService::Get() in webkit. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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
« no previous file with comments | « webkit/tools/test_shell/test_shell.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <iostream> 5 #include <iostream>
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/event_recorder.h" 10 #include "base/event_recorder.h"
11 #include "base/file_path.h"
11 #include "base/file_util.h" 12 #include "base/file_util.h"
12 #include "base/icu_util.h" 13 #include "base/icu_util.h"
13 #include "base/memory_debug.h" 14 #include "base/memory_debug.h"
14 #include "base/message_loop.h" 15 #include "base/message_loop.h"
15 #include "base/path_service.h" 16 #include "base/path_service.h"
16 #include "base/process_util.h" 17 #include "base/process_util.h"
17 #include "base/rand_util.h" 18 #include "base/rand_util.h"
18 #include "base/stats_table.h" 19 #include "base/stats_table.h"
19 #include "base/string_util.h" 20 #include "base/string_util.h"
20 #include "base/sys_info.h" 21 #include "base/sys_info.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 116
116 if (playback_mode) 117 if (playback_mode)
117 cache_mode = net::HttpCache::PLAYBACK; 118 cache_mode = net::HttpCache::PLAYBACK;
118 else if (record_mode) 119 else if (record_mode)
119 cache_mode = net::HttpCache::RECORD; 120 cache_mode = net::HttpCache::RECORD;
120 121
121 if (layout_test_mode || 122 if (layout_test_mode ||
122 parsed_command_line.HasSwitch(test_shell::kEnableFileCookies)) 123 parsed_command_line.HasSwitch(test_shell::kEnableFileCookies))
123 net::CookieMonster::EnableFileScheme(); 124 net::CookieMonster::EnableFileScheme();
124 125
125 std::wstring cache_path = 126 FilePath cache_path = FilePath::FromWStringHack(
126 parsed_command_line.GetSwitchValue(test_shell::kCacheDir); 127 parsed_command_line.GetSwitchValue(test_shell::kCacheDir));
127 // If the cache_path is empty and it's layout_test_mode, leave it empty 128 // If the cache_path is empty and it's layout_test_mode, leave it empty
128 // so we use an in-memory cache. This makes running multiple test_shells 129 // so we use an in-memory cache. This makes running multiple test_shells
129 // in parallel less flaky. 130 // in parallel less flaky.
130 if (cache_path.empty() && !layout_test_mode) { 131 if (cache_path.empty() && !layout_test_mode) {
131 PathService::Get(base::DIR_EXE, &cache_path); 132 PathService::Get(base::DIR_EXE, &cache_path);
132 file_util::AppendToPath(&cache_path, L"cache"); 133 cache_path = cache_path.AppendASCII("cache");
133 } 134 }
134 135
135 // Initializing with a default context, which means no on-disk cookie DB, 136 // Initializing with a default context, which means no on-disk cookie DB,
136 // and no support for directory listings. 137 // and no support for directory listings.
137 SimpleResourceLoaderBridge::Init( 138 SimpleResourceLoaderBridge::Init(
138 new TestShellRequestContext(cache_path, cache_mode, layout_test_mode)); 139 new TestShellRequestContext(cache_path.ToWStringHack(),
140 cache_mode, layout_test_mode));
139 141
140 // Load ICU data tables 142 // Load ICU data tables
141 icu_util::Initialize(); 143 icu_util::Initialize();
142 144
143 // Config the network module so it has access to a limited set of resources. 145 // Config the network module so it has access to a limited set of resources.
144 net::NetModule::SetResourceProvider(TestShell::NetResourceProvider); 146 net::NetModule::SetResourceProvider(TestShell::NetResourceProvider);
145 147
146 // On Linux, load the test root certificate. 148 // On Linux, load the test root certificate.
147 net::TestServerLauncher ssl_util; 149 net::TestServerLauncher ssl_util;
148 ssl_util.LoadTestRootCert(); 150 ssl_util.LoadTestRootCert();
(...skipping 13 matching lines...) Expand all
162 if (parsed_command_line.HasSwitch(test_shell::kTestShellTimeOut)) { 164 if (parsed_command_line.HasSwitch(test_shell::kTestShellTimeOut)) {
163 const std::wstring timeout_str = parsed_command_line.GetSwitchValue( 165 const std::wstring timeout_str = parsed_command_line.GetSwitchValue(
164 test_shell::kTestShellTimeOut); 166 test_shell::kTestShellTimeOut);
165 int timeout_ms = 167 int timeout_ms =
166 static_cast<int>(StringToInt64(WideToUTF16Hack(timeout_str.c_str()))); 168 static_cast<int>(StringToInt64(WideToUTF16Hack(timeout_str.c_str())));
167 if (timeout_ms > 0) 169 if (timeout_ms > 0)
168 TestShell::SetFileTestTimeout(timeout_ms); 170 TestShell::SetFileTestTimeout(timeout_ms);
169 } 171 }
170 172
171 // Treat the first loose value as the initial URL to open. 173 // Treat the first loose value as the initial URL to open.
172 std::wstring uri; 174 FilePath uri;
173 175
174 // Default to a homepage if we're interactive. 176 // Default to a homepage if we're interactive.
175 if (!layout_test_mode) { 177 if (!layout_test_mode) {
176 PathService::Get(base::DIR_SOURCE_ROOT, &uri); 178 PathService::Get(base::DIR_SOURCE_ROOT, &uri);
177 file_util::AppendToPath(&uri, L"webkit"); 179 uri = uri.AppendASCII("webkit");
178 file_util::AppendToPath(&uri, L"data"); 180 uri = uri.AppendASCII("data");
179 file_util::AppendToPath(&uri, L"test_shell"); 181 uri = uri.AppendASCII("test_shell");
180 file_util::AppendToPath(&uri, L"index.html"); 182 uri = uri.AppendASCII("index.html");
181 } 183 }
182 184
183 std::vector<std::wstring> loose_values = parsed_command_line.GetLooseValues(); 185 std::vector<std::wstring> loose_values = parsed_command_line.GetLooseValues();
184 if (loose_values.size() > 0) 186 if (loose_values.size() > 0)
185 uri = loose_values[0]; 187 uri = FilePath::FromWStringHack(loose_values[0]);
186 188
187 std::wstring js_flags = 189 std::wstring js_flags =
188 parsed_command_line.GetSwitchValue(test_shell::kJavaScriptFlags); 190 parsed_command_line.GetSwitchValue(test_shell::kJavaScriptFlags);
189 // Test shell always exposes the GC. 191 // Test shell always exposes the GC.
190 js_flags += L" --expose-gc"; 192 js_flags += L" --expose-gc";
191 webkit_glue::SetJavaScriptFlags(js_flags); 193 webkit_glue::SetJavaScriptFlags(js_flags);
192 // Expose GCController to JavaScript. 194 // Expose GCController to JavaScript.
193 WebKit::registerExtension(extensions_v8::GCExtension::Get()); 195 WebKit::registerExtension(extensions_v8::GCExtension::Get());
194 196
195 if (parsed_command_line.HasSwitch(test_shell::kProfiler)) { 197 if (parsed_command_line.HasSwitch(test_shell::kProfiler)) {
196 WebKit::registerExtension(extensions_v8::ProfilerExtension::Get()); 198 WebKit::registerExtension(extensions_v8::ProfilerExtension::Get());
197 } 199 }
198 200
199 // Load and initialize the stats table. Attempt to construct a somewhat 201 // Load and initialize the stats table. Attempt to construct a somewhat
200 // unique name to isolate separate instances from each other. 202 // unique name to isolate separate instances from each other.
201 StatsTable *table = new StatsTable( 203 StatsTable *table = new StatsTable(
202 // truncate the random # to 32 bits for the benefit of Mac OS X, to 204 // truncate the random # to 32 bits for the benefit of Mac OS X, to
203 // avoid tripping over its maximum shared memory segment name length 205 // avoid tripping over its maximum shared memory segment name length
204 kStatsFilePrefix + Uint64ToString(base::RandUint64() & 0xFFFFFFFFL), 206 kStatsFilePrefix + Uint64ToString(base::RandUint64() & 0xFFFFFFFFL),
205 kStatsFileThreads, 207 kStatsFileThreads,
206 kStatsFileCounters); 208 kStatsFileCounters);
207 StatsTable::set_current(table); 209 StatsTable::set_current(table);
208 210
209 TestShell* shell; 211 TestShell* shell;
210 if (TestShell::CreateNewWindow(uri, &shell)) { 212 if (TestShell::CreateNewWindow(uri.ToWStringHack(), &shell)) {
211 if (record_mode || playback_mode) { 213 if (record_mode || playback_mode) {
212 platform.SetWindowPositionForRecording(shell); 214 platform.SetWindowPositionForRecording(shell);
213 WebKit::registerExtension(extensions_v8::PlaybackExtension::Get()); 215 WebKit::registerExtension(extensions_v8::PlaybackExtension::Get());
214 } 216 }
215 217
216 shell->Show(shell->webView(), NEW_WINDOW); 218 shell->Show(shell->webView(), NEW_WINDOW);
217 219
218 if (parsed_command_line.HasSwitch(test_shell::kDumpStatsTable)) 220 if (parsed_command_line.HasSwitch(test_shell::kDumpStatsTable))
219 shell->DumpStatsTableOnExit(); 221 shell->DumpStatsTableOnExit();
220 222
221 bool no_events = parsed_command_line.HasSwitch(test_shell::kNoEvents); 223 bool no_events = parsed_command_line.HasSwitch(test_shell::kNoEvents);
222 if ((record_mode || playback_mode) && !no_events) { 224 if ((record_mode || playback_mode) && !no_events) {
223 std::wstring script_path = cache_path; 225 FilePath script_path = cache_path;
224 // Create the cache directory in case it doesn't exist. 226 // Create the cache directory in case it doesn't exist.
225 file_util::CreateDirectory(cache_path); 227 file_util::CreateDirectory(cache_path);
226 file_util::AppendToPath(&script_path, L"script.log"); 228 script_path = script_path.AppendASCII("script.log");
227 if (record_mode) 229 if (record_mode)
228 base::EventRecorder::current()->StartRecording(script_path); 230 base::EventRecorder::current()->StartRecording(script_path);
229 if (playback_mode) 231 if (playback_mode)
230 base::EventRecorder::current()->StartPlayback(script_path); 232 base::EventRecorder::current()->StartPlayback(script_path);
231 } 233 }
232 234
233 if (parsed_command_line.HasSwitch(test_shell::kDebugMemoryInUse)) { 235 if (parsed_command_line.HasSwitch(test_shell::kDebugMemoryInUse)) {
234 base::MemoryDebug::SetMemoryInUseEnabled(true); 236 base::MemoryDebug::SetMemoryInUseEnabled(true);
235 // Dump all in use memory at startup 237 // Dump all in use memory at startup
236 base::MemoryDebug::DumpAllMemoryInUse(); 238 base::MemoryDebug::DumpAllMemoryInUse();
(...skipping 15 matching lines...) Expand all
252 test_shell::kDumpPixels); 254 test_shell::kDumpPixels);
253 if (params.pixel_file_name.size() == 0) { 255 if (params.pixel_file_name.size() == 0) {
254 fprintf(stderr, "No file specified for pixel tests"); 256 fprintf(stderr, "No file specified for pixel tests");
255 exit(1); 257 exit(1);
256 } 258 }
257 } 259 }
258 if (parsed_command_line.HasSwitch(test_shell::kNoTree)) { 260 if (parsed_command_line.HasSwitch(test_shell::kNoTree)) {
259 params.dump_tree = false; 261 params.dump_tree = false;
260 } 262 }
261 263
262 if (uri.length() == 0) { 264 if (uri.empty()) {
263 // Watch stdin for URLs. 265 // Watch stdin for URLs.
264 char filenameBuffer[kPathBufSize]; 266 char filenameBuffer[kPathBufSize];
265 while (fgets(filenameBuffer, sizeof(filenameBuffer), stdin)) { 267 while (fgets(filenameBuffer, sizeof(filenameBuffer), stdin)) {
266 // When running layout tests we pass new line separated 268 // When running layout tests we pass new line separated
267 // tests to TestShell. Each line is a space separated list 269 // tests to TestShell. Each line is a space separated list
268 // of filename, timeout and expected pixel hash. The timeout 270 // of filename, timeout and expected pixel hash. The timeout
269 // and the pixel hash are optional. 271 // and the pixel hash are optional.
270 char* newLine = strchr(filenameBuffer, '\n'); 272 char* newLine = strchr(filenameBuffer, '\n');
271 if (newLine) 273 if (newLine)
272 *newLine = '\0'; 274 *newLine = '\0';
(...skipping 13 matching lines...) Expand all
286 } 288 }
287 289
288 if (!TestShell::RunFileTest(params)) 290 if (!TestShell::RunFileTest(params))
289 break; 291 break;
290 292
291 TestShell::SetFileTestTimeout(old_timeout_ms); 293 TestShell::SetFileTestTimeout(old_timeout_ms);
292 } 294 }
293 } else { 295 } else {
294 // TODO(ojan): Provide a way for run-singly tests to pass 296 // TODO(ojan): Provide a way for run-singly tests to pass
295 // in a hash and then set params.pixel_hash here. 297 // in a hash and then set params.pixel_hash here.
296 params.test_url = WideToUTF8(uri).c_str(); 298 params.test_url = WideToUTF8(uri.ToWStringHack()).c_str();
297 TestShell::RunFileTest(params); 299 TestShell::RunFileTest(params);
298 } 300 }
299 301
300 shell->CallJSGC(); 302 shell->CallJSGC();
301 shell->CallJSGC(); 303 shell->CallJSGC();
302 if (shell) { 304 if (shell) {
303 // When we finish the last test, cleanup the LayoutTestController. 305 // When we finish the last test, cleanup the LayoutTestController.
304 // It may have references to not-yet-cleaned up windows. By 306 // It may have references to not-yet-cleaned up windows. By
305 // cleaning up here we help purify reports. 307 // cleaning up here we help purify reports.
306 shell->ResetTestController(); 308 shell->ResetTestController();
(...skipping 16 matching lines...) Expand all
323 325
324 TestShell::ShutdownTestShell(); 326 TestShell::ShutdownTestShell();
325 TestShell::CleanupLogging(); 327 TestShell::CleanupLogging();
326 328
327 // Tear down shared StatsTable; prevents unit_tests from leaking it. 329 // Tear down shared StatsTable; prevents unit_tests from leaking it.
328 StatsTable::set_current(NULL); 330 StatsTable::set_current(NULL);
329 delete table; 331 delete table;
330 332
331 return 0; 333 return 0;
332 } 334 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/test_shell.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698