| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
| 6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/event_recorder.h" | 10 #include "base/event_recorder.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 24 #include "net/cookies/cookie_monster.h" | 24 #include "net/cookies/cookie_monster.h" |
| 25 #include "net/http/http_cache.h" | 25 #include "net/http/http_cache.h" |
| 26 #include "net/http/http_util.h" | 26 #include "net/http/http_util.h" |
| 27 #include "net/test/test_server.h" | 27 #include "net/test/test_server.h" |
| 28 #include "net/url_request/url_request_context.h" | 28 #include "net/url_request/url_request_context.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h
" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h
" |
| 31 #include "ui/gfx/gl/gl_implementation.h" | 31 #include "ui/gfx/gl/gl_implementation.h" |
| 32 #include "ui/gfx/gl/gl_switches.h" | 32 #include "ui/gfx/gl/gl_switches.h" |
| 33 #include "webkit/extensions/v8/gc_extension.h" | |
| 34 #include "webkit/extensions/v8/heap_profiler_extension.h" | |
| 35 #include "webkit/extensions/v8/playback_extension.h" | |
| 36 #include "webkit/extensions/v8/profiler_extension.h" | |
| 37 #include "webkit/glue/webkit_glue.h" | 33 #include "webkit/glue/webkit_glue.h" |
| 38 #include "webkit/glue/webpreferences.h" | 34 #include "webkit/glue/webpreferences.h" |
| 39 #include "webkit/glue/window_open_disposition.h" | 35 #include "webkit/glue/window_open_disposition.h" |
| 40 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" | 36 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" |
| 41 #include "webkit/tools/test_shell/test_shell.h" | 37 #include "webkit/tools/test_shell/test_shell.h" |
| 42 #include "webkit/tools/test_shell/test_shell_platform_delegate.h" | 38 #include "webkit/tools/test_shell/test_shell_platform_delegate.h" |
| 43 #include "webkit/tools/test_shell/test_shell_request_context.h" | 39 #include "webkit/tools/test_shell/test_shell_request_context.h" |
| 44 #include "webkit/tools/test_shell/test_shell_switches.h" | 40 #include "webkit/tools/test_shell/test_shell_switches.h" |
| 45 #include "webkit/tools/test_shell/test_shell_webkit_init.h" | 41 #include "webkit/tools/test_shell/test_shell_webkit_init.h" |
| 46 | 42 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 149 |
| 154 // Suppress abort message in v8 library in debugging mode (but not | 150 // Suppress abort message in v8 library in debugging mode (but not |
| 155 // actually under a debugger). V8 calls abort() when it hits | 151 // actually under a debugger). V8 calls abort() when it hits |
| 156 // assertion errors. | 152 // assertion errors. |
| 157 if (suppress_error_dialogs) { | 153 if (suppress_error_dialogs) { |
| 158 platform.SuppressErrorReporting(); | 154 platform.SuppressErrorReporting(); |
| 159 } | 155 } |
| 160 | 156 |
| 161 net::HttpCache::Mode cache_mode = net::HttpCache::NORMAL; | 157 net::HttpCache::Mode cache_mode = net::HttpCache::NORMAL; |
| 162 | 158 |
| 163 // This is a special mode where JS helps the browser implement | |
| 164 // playback/record mode. Generally, in this mode, some functions | |
| 165 // of client-side randomness are removed. For example, in | |
| 166 // this mode Math.random() and Date.getTime() may not return | |
| 167 // values which vary. | |
| 168 bool playback_mode = | |
| 169 parsed_command_line.HasSwitch(test_shell::kPlaybackMode); | |
| 170 bool record_mode = | |
| 171 parsed_command_line.HasSwitch(test_shell::kRecordMode); | |
| 172 | |
| 173 if (playback_mode) | |
| 174 cache_mode = net::HttpCache::PLAYBACK; | |
| 175 else if (record_mode) | |
| 176 cache_mode = net::HttpCache::RECORD; | |
| 177 | |
| 178 if (parsed_command_line.HasSwitch(test_shell::kEnableFileCookies)) | 159 if (parsed_command_line.HasSwitch(test_shell::kEnableFileCookies)) |
| 179 net::CookieMonster::EnableFileScheme(); | 160 net::CookieMonster::EnableFileScheme(); |
| 180 | 161 |
| 181 FilePath cache_path = | 162 FilePath cache_path = |
| 182 parsed_command_line.GetSwitchValuePath(test_shell::kCacheDir); | 163 parsed_command_line.GetSwitchValuePath(test_shell::kCacheDir); |
| 183 if (cache_path.empty()) { | 164 if (cache_path.empty()) { |
| 184 PathService::Get(base::DIR_EXE, &cache_path); | 165 PathService::Get(base::DIR_EXE, &cache_path); |
| 185 cache_path = cache_path.AppendASCII("cache"); | 166 cache_path = cache_path.AppendASCII("cache"); |
| 186 } | 167 } |
| 187 | 168 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 251 } |
| 271 js_flags_list.push_back(flags); | 252 js_flags_list.push_back(flags); |
| 272 if (comma_pos == std::string::npos) | 253 if (comma_pos == std::string::npos) |
| 273 break; | 254 break; |
| 274 } | 255 } |
| 275 TestShell::SetJavaScriptFlags(js_flags_list); | 256 TestShell::SetJavaScriptFlags(js_flags_list); |
| 276 | 257 |
| 277 // Test shell always exposes the GC. | 258 // Test shell always exposes the GC. |
| 278 webkit_glue::SetJavaScriptFlags("--expose-gc"); | 259 webkit_glue::SetJavaScriptFlags("--expose-gc"); |
| 279 | 260 |
| 280 // Expose GCController to JavaScript. | |
| 281 WebScriptController::registerExtension(extensions_v8::GCExtension::Get()); | |
| 282 | |
| 283 if (parsed_command_line.HasSwitch(test_shell::kProfiler)) { | |
| 284 WebScriptController::registerExtension( | |
| 285 extensions_v8::ProfilerExtension::Get()); | |
| 286 } | |
| 287 | |
| 288 if (parsed_command_line.HasSwitch(test_shell::kHeapProfiler)) { | |
| 289 WebScriptController::registerExtension( | |
| 290 extensions_v8::HeapProfilerExtension::Get()); | |
| 291 } | |
| 292 | |
| 293 // Load and initialize the stats table. Attempt to construct a somewhat | 261 // Load and initialize the stats table. Attempt to construct a somewhat |
| 294 // unique name to isolate separate instances from each other. | 262 // unique name to isolate separate instances from each other. |
| 295 | 263 |
| 296 // truncate the random # to 32 bits for the benefit of Mac OS X, to | 264 // truncate the random # to 32 bits for the benefit of Mac OS X, to |
| 297 // avoid tripping over its maximum shared memory segment name length | 265 // avoid tripping over its maximum shared memory segment name length |
| 298 std::string stats_filename = kStatsFilePrefix + | 266 std::string stats_filename = kStatsFilePrefix + |
| 299 base::Uint64ToString(base::RandUint64() & 0xFFFFFFFFL); | 267 base::Uint64ToString(base::RandUint64() & 0xFFFFFFFFL); |
| 300 RemoveSharedMemoryFile(stats_filename); | 268 RemoveSharedMemoryFile(stats_filename); |
| 301 base::StatsTable *table = new base::StatsTable(stats_filename, | 269 base::StatsTable *table = new base::StatsTable(stats_filename, |
| 302 kStatsFileThreads, | 270 kStatsFileThreads, |
| 303 kStatsFileCounters); | 271 kStatsFileCounters); |
| 304 base::StatsTable::set_current(table); | 272 base::StatsTable::set_current(table); |
| 305 | 273 |
| 306 TestShell* shell; | 274 TestShell* shell; |
| 307 if (TestShell::CreateNewWindow(starting_url, &shell)) { | 275 if (TestShell::CreateNewWindow(starting_url, &shell)) { |
| 308 if (record_mode || playback_mode) { | |
| 309 platform.SetWindowPositionForRecording(shell); | |
| 310 WebScriptController::registerExtension( | |
| 311 extensions_v8::PlaybackExtension::Get()); | |
| 312 } | |
| 313 | |
| 314 shell->Show(WebKit::WebNavigationPolicyNewWindow); | 276 shell->Show(WebKit::WebNavigationPolicyNewWindow); |
| 315 | 277 |
| 316 if (parsed_command_line.HasSwitch(test_shell::kDumpStatsTable)) | 278 if (parsed_command_line.HasSwitch(test_shell::kDumpStatsTable)) |
| 317 shell->DumpStatsTableOnExit(); | 279 shell->DumpStatsTableOnExit(); |
| 318 | 280 |
| 319 bool no_events = parsed_command_line.HasSwitch(test_shell::kNoEvents); | |
| 320 if ((record_mode || playback_mode) && !no_events) { | |
| 321 FilePath script_path = cache_path; | |
| 322 // Create the cache directory in case it doesn't exist. | |
| 323 file_util::CreateDirectory(cache_path); | |
| 324 script_path = script_path.AppendASCII("script.log"); | |
| 325 if (record_mode) | |
| 326 base::EventRecorder::current()->StartRecording(script_path); | |
| 327 if (playback_mode) | |
| 328 base::EventRecorder::current()->StartPlayback(script_path); | |
| 329 } | |
| 330 | |
| 331 webkit_glue::SetJavaScriptFlags(TestShell::GetJSFlagsForLoad(0)); | 281 webkit_glue::SetJavaScriptFlags(TestShell::GetJSFlagsForLoad(0)); |
| 332 MessageLoop::current()->Run(); | 282 MessageLoop::current()->Run(); |
| 333 | |
| 334 if (record_mode) | |
| 335 base::EventRecorder::current()->StopRecording(); | |
| 336 if (playback_mode) | |
| 337 base::EventRecorder::current()->StopPlayback(); | |
| 338 } | 283 } |
| 339 | 284 |
| 340 TestShell::ShutdownTestShell(); | 285 TestShell::ShutdownTestShell(); |
| 341 TestShell::CleanupLogging(); | 286 TestShell::CleanupLogging(); |
| 342 | 287 |
| 343 // Tear down shared StatsTable; prevents unit_tests from leaking it. | 288 // Tear down shared StatsTable; prevents unit_tests from leaking it. |
| 344 base::StatsTable::set_current(NULL); | 289 base::StatsTable::set_current(NULL); |
| 345 delete table; | 290 delete table; |
| 346 RemoveSharedMemoryFile(stats_filename); | 291 RemoveSharedMemoryFile(stats_filename); |
| 347 | 292 |
| 348 return 0; | 293 return 0; |
| 349 } | 294 } |
| OLD | NEW |