OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/shell/browser/layout_test/blink_test_controller.h" | 5 #include "content/shell/browser/layout_test/blink_test_controller.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <iostream> | 9 #include <iostream> |
10 #include <set> | 10 #include <set> |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 BlinkTestController* BlinkTestController::instance_ = NULL; | 242 BlinkTestController* BlinkTestController::instance_ = NULL; |
243 | 243 |
244 // static | 244 // static |
245 BlinkTestController* BlinkTestController::Get() { | 245 BlinkTestController* BlinkTestController::Get() { |
246 DCHECK(instance_); | 246 DCHECK(instance_); |
247 return instance_; | 247 return instance_; |
248 } | 248 } |
249 | 249 |
250 BlinkTestController::BlinkTestController() | 250 BlinkTestController::BlinkTestController() |
251 : main_window_(NULL), | 251 : main_window_(NULL), |
| 252 secondary_window_(nullptr), |
252 devtools_window_(nullptr), | 253 devtools_window_(nullptr), |
253 test_phase_(BETWEEN_TESTS), | 254 test_phase_(BETWEEN_TESTS), |
254 is_leak_detection_enabled_( | 255 is_leak_detection_enabled_( |
255 base::CommandLine::ForCurrentProcess()->HasSwitch( | 256 base::CommandLine::ForCurrentProcess()->HasSwitch( |
256 switches::kEnableLeakDetection)), | 257 switches::kEnableLeakDetection)), |
257 crash_when_leak_found_(false), | 258 crash_when_leak_found_(false), |
258 render_process_host_observer_(this) { | 259 render_process_host_observer_(this) { |
259 CHECK(!instance_); | 260 CHECK(!instance_); |
260 instance_ = this; | 261 instance_ = this; |
261 | 262 |
(...skipping 27 matching lines...) Expand all Loading... |
289 bool BlinkTestController::PrepareForLayoutTest( | 290 bool BlinkTestController::PrepareForLayoutTest( |
290 const GURL& test_url, | 291 const GURL& test_url, |
291 const base::FilePath& current_working_directory, | 292 const base::FilePath& current_working_directory, |
292 bool enable_pixel_dumping, | 293 bool enable_pixel_dumping, |
293 const std::string& expected_pixel_hash) { | 294 const std::string& expected_pixel_hash) { |
294 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 295 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
295 test_phase_ = DURING_TEST; | 296 test_phase_ = DURING_TEST; |
296 current_working_directory_ = current_working_directory; | 297 current_working_directory_ = current_working_directory; |
297 enable_pixel_dumping_ = enable_pixel_dumping; | 298 enable_pixel_dumping_ = enable_pixel_dumping; |
298 expected_pixel_hash_ = expected_pixel_hash; | 299 expected_pixel_hash_ = expected_pixel_hash; |
299 if (test_url.spec().find("/inspector-unit/") == std::string::npos) | 300 bool is_devtools_js_test = false; |
300 test_url_ = test_url; | 301 test_url_ = LayoutTestDevToolsBindings::MapTestURLIfNeeded( |
301 else | 302 test_url, &is_devtools_js_test); |
302 test_url_ = LayoutTestDevToolsBindings::MapJSTestURL(test_url); | |
303 did_send_initial_test_configuration_ = false; | 303 did_send_initial_test_configuration_ = false; |
304 printer_->reset(); | 304 printer_->reset(); |
305 frame_to_layout_dump_map_.clear(); | 305 frame_to_layout_dump_map_.clear(); |
306 render_process_host_observer_.RemoveAll(); | 306 render_process_host_observer_.RemoveAll(); |
307 all_observed_render_process_hosts_.clear(); | 307 all_observed_render_process_hosts_.clear(); |
308 main_window_render_process_hosts_.clear(); | 308 main_window_render_process_hosts_.clear(); |
309 accumulated_layout_test_runtime_flags_changes_.Clear(); | 309 accumulated_layout_test_runtime_flags_changes_.Clear(); |
310 layout_test_control_map_.clear(); | 310 layout_test_control_map_.clear(); |
311 ShellBrowserContext* browser_context = | 311 ShellBrowserContext* browser_context = |
312 ShellContentBrowserClient::Get()->browser_context(); | 312 ShellContentBrowserClient::Get()->browser_context(); |
313 is_compositing_test_ = | 313 is_compositing_test_ = |
314 test_url_.spec().find("compositing/") != std::string::npos; | 314 test_url_.spec().find("compositing/") != std::string::npos; |
315 initial_size_ = Shell::GetShellDefaultSize(); | 315 initial_size_ = Shell::GetShellDefaultSize(); |
316 // The W3C SVG layout tests use a different size than the other layout tests. | 316 // The W3C SVG layout tests use a different size than the other layout tests. |
317 if (test_url_.spec().find("W3C-SVG-1.1") != std::string::npos) | 317 if (test_url_.spec().find("W3C-SVG-1.1") != std::string::npos) |
318 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip); | 318 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip); |
319 if (!main_window_) { | 319 if (!main_window_) { |
320 main_window_ = content::Shell::CreateNewWindow( | 320 main_window_ = content::Shell::CreateNewWindow( |
321 browser_context, | 321 browser_context, |
322 GURL(), | 322 GURL(), |
323 NULL, | 323 NULL, |
324 initial_size_); | 324 initial_size_); |
325 WebContentsObserver::Observe(main_window_->web_contents()); | 325 WebContentsObserver::Observe(main_window_->web_contents()); |
326 current_pid_ = base::kNullProcessId; | 326 current_pid_ = base::kNullProcessId; |
327 default_prefs_ = | 327 default_prefs_ = |
328 main_window_->web_contents()->GetRenderViewHost()->GetWebkitPreferences(); | 328 main_window_->web_contents()->GetRenderViewHost()->GetWebkitPreferences(); |
329 main_window_->LoadURL(test_url_); | 329 if (is_devtools_js_test) |
| 330 LoadDevToolsJSTest(); |
| 331 else |
| 332 main_window_->LoadURL(test_url_); |
330 } else { | 333 } else { |
331 #if defined(OS_MACOSX) | 334 #if defined(OS_MACOSX) |
332 // Shell::SizeTo is not implemented on all platforms. | 335 // Shell::SizeTo is not implemented on all platforms. |
333 main_window_->SizeTo(initial_size_); | 336 main_window_->SizeTo(initial_size_); |
334 #endif | 337 #endif |
335 main_window_->web_contents() | 338 main_window_->web_contents() |
336 ->GetRenderViewHost() | 339 ->GetRenderViewHost() |
337 ->GetWidget() | 340 ->GetWidget() |
338 ->GetView() | 341 ->GetView() |
339 ->SetSize(initial_size_); | 342 ->SetSize(initial_size_); |
340 main_window_->web_contents() | 343 main_window_->web_contents() |
341 ->GetRenderViewHost() | 344 ->GetRenderViewHost() |
342 ->GetWidget() | 345 ->GetWidget() |
343 ->WasResized(); | 346 ->WasResized(); |
344 RenderViewHost* render_view_host = | 347 RenderViewHost* render_view_host = |
345 main_window_->web_contents()->GetRenderViewHost(); | 348 main_window_->web_contents()->GetRenderViewHost(); |
346 | 349 |
347 // Compositing tests override the default preferences (see | 350 // Compositing tests override the default preferences (see |
348 // BlinkTestController::OverrideWebkitPrefs) so we force them to be | 351 // BlinkTestController::OverrideWebkitPrefs) so we force them to be |
349 // calculated again to ensure is_compositing_test_ changes are picked up. | 352 // calculated again to ensure is_compositing_test_ changes are picked up. |
350 OverrideWebkitPrefs(&default_prefs_); | 353 OverrideWebkitPrefs(&default_prefs_); |
351 | 354 |
352 render_view_host->UpdateWebkitPreferences(default_prefs_); | 355 render_view_host->UpdateWebkitPreferences(default_prefs_); |
353 HandleNewRenderFrameHost(render_view_host->GetMainFrame()); | 356 HandleNewRenderFrameHost(render_view_host->GetMainFrame()); |
354 | 357 |
355 NavigationController::LoadURLParams params(test_url_); | 358 if (is_devtools_js_test) { |
356 params.transition_type = ui::PageTransitionFromInt( | 359 LoadDevToolsJSTest(); |
357 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); | 360 } else { |
358 params.should_clear_history_list = true; | 361 NavigationController::LoadURLParams params(test_url_); |
359 main_window_->web_contents()->GetController().LoadURLWithParams(params); | 362 params.transition_type = ui::PageTransitionFromInt( |
360 main_window_->web_contents()->Focus(); | 363 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); |
| 364 params.should_clear_history_list = true; |
| 365 main_window_->web_contents()->GetController().LoadURLWithParams(params); |
| 366 main_window_->web_contents()->Focus(); |
| 367 } |
361 } | 368 } |
362 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->SetActive( | 369 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->SetActive( |
363 true); | 370 true); |
364 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); | 371 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); |
365 return true; | 372 return true; |
366 } | 373 } |
367 | 374 |
| 375 Shell* BlinkTestController::SecondaryWindow() { |
| 376 if (!secondary_window_) { |
| 377 ShellBrowserContext* browser_context = |
| 378 ShellContentBrowserClient::Get()->browser_context(); |
| 379 secondary_window_ = content::Shell::CreateNewWindow(browser_context, GURL(), |
| 380 nullptr, initial_size_); |
| 381 } |
| 382 return secondary_window_; |
| 383 } |
| 384 |
| 385 void BlinkTestController::LoadDevToolsJSTest() { |
| 386 devtools_window_ = main_window_; |
| 387 Shell* secondary = SecondaryWindow(); |
| 388 devtools_bindings_.reset(LayoutTestDevToolsBindings::LoadDevTools( |
| 389 devtools_window_->web_contents(), secondary->web_contents(), "", |
| 390 test_url_.spec())); |
| 391 secondary->LoadURL(GURL(url::kAboutBlankURL)); |
| 392 } |
| 393 |
368 bool BlinkTestController::ResetAfterLayoutTest() { | 394 bool BlinkTestController::ResetAfterLayoutTest() { |
369 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 395 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
370 printer_->PrintTextFooter(); | 396 printer_->PrintTextFooter(); |
371 printer_->PrintImageFooter(); | 397 printer_->PrintImageFooter(); |
372 printer_->CloseStderr(); | 398 printer_->CloseStderr(); |
373 did_send_initial_test_configuration_ = false; | 399 did_send_initial_test_configuration_ = false; |
374 test_phase_ = BETWEEN_TESTS; | 400 test_phase_ = BETWEEN_TESTS; |
375 is_compositing_test_ = false; | 401 is_compositing_test_ = false; |
376 enable_pixel_dumping_ = false; | 402 enable_pixel_dumping_ = false; |
377 expected_pixel_hash_.clear(); | 403 expected_pixel_hash_.clear(); |
378 test_url_ = GURL(); | 404 test_url_ = GURL(); |
379 prefs_ = WebPreferences(); | 405 prefs_ = WebPreferences(); |
380 should_override_prefs_ = false; | 406 should_override_prefs_ = false; |
381 LayoutTestContentBrowserClient::Get()->SetPopupBlockingEnabled(false); | 407 LayoutTestContentBrowserClient::Get()->SetPopupBlockingEnabled(false); |
| 408 devtools_bindings_.reset(); |
382 | 409 |
383 #if defined(OS_ANDROID) | 410 #if defined(OS_ANDROID) |
384 // Re-using the shell's main window on Android causes issues with networking | 411 // Re-using the shell's main window on Android causes issues with networking |
385 // requests never succeeding. See http://crbug.com/277652. | 412 // requests never succeeding. See http://crbug.com/277652. |
386 DiscardMainWindow(); | 413 DiscardMainWindow(); |
387 #endif | 414 #endif |
388 return true; | 415 return true; |
389 } | 416 } |
390 | 417 |
391 void BlinkTestController::SetTempPath(const base::FilePath& temp_path) { | 418 void BlinkTestController::SetTempPath(const base::FilePath& temp_path) { |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 ShellContentBrowserClient::Get()->browser_context(); | 863 ShellContentBrowserClient::Get()->browser_context(); |
837 StoragePartition* storage_partition = | 864 StoragePartition* storage_partition = |
838 BrowserContext::GetStoragePartition(browser_context, NULL); | 865 BrowserContext::GetStoragePartition(browser_context, NULL); |
839 storage_partition->GetDOMStorageContext()->DeleteLocalStorage( | 866 storage_partition->GetDOMStorageContext()->DeleteLocalStorage( |
840 content::LayoutTestDevToolsBindings::GetDevToolsPathAsURL("") | 867 content::LayoutTestDevToolsBindings::GetDevToolsPathAsURL("") |
841 .GetOrigin()); | 868 .GetOrigin()); |
842 } | 869 } |
843 | 870 |
844 void BlinkTestController::OnShowDevTools(const std::string& settings, | 871 void BlinkTestController::OnShowDevTools(const std::string& settings, |
845 const std::string& frontend_url) { | 872 const std::string& frontend_url) { |
846 if (!devtools_window_) { | 873 devtools_window_ = SecondaryWindow(); |
847 ShellBrowserContext* browser_context = | |
848 ShellContentBrowserClient::Get()->browser_context(); | |
849 devtools_window_ = content::Shell::CreateNewWindow(browser_context, GURL(), | |
850 nullptr, initial_size_); | |
851 } | |
852 | |
853 devtools_bindings_.reset(LayoutTestDevToolsBindings::LoadDevTools( | 874 devtools_bindings_.reset(LayoutTestDevToolsBindings::LoadDevTools( |
854 devtools_window_->web_contents(), main_window_->web_contents(), settings, | 875 devtools_window_->web_contents(), main_window_->web_contents(), settings, |
855 frontend_url)); | 876 frontend_url)); |
856 devtools_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); | 877 devtools_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); |
857 devtools_window_->web_contents()->Focus(); | 878 devtools_window_->web_contents()->Focus(); |
858 } | 879 } |
859 | 880 |
860 void BlinkTestController::OnEvaluateInDevTools( | 881 void BlinkTestController::OnEvaluateInDevTools( |
861 int call_id, const std::string& script) { | 882 int call_id, const std::string& script) { |
862 if (devtools_bindings_) | 883 if (devtools_bindings_) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), | 940 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), |
920 routing_ids, | 941 routing_ids, |
921 session_histories, | 942 session_histories, |
922 current_entry_indexes)); | 943 current_entry_indexes)); |
923 } | 944 } |
924 | 945 |
925 void BlinkTestController::OnCloseRemainingWindows() { | 946 void BlinkTestController::OnCloseRemainingWindows() { |
926 DevToolsAgentHost::DetachAllClients(); | 947 DevToolsAgentHost::DetachAllClients(); |
927 std::vector<Shell*> open_windows(Shell::windows()); | 948 std::vector<Shell*> open_windows(Shell::windows()); |
928 for (size_t i = 0; i < open_windows.size(); ++i) { | 949 for (size_t i = 0; i < open_windows.size(); ++i) { |
929 if (open_windows[i] != main_window_ && open_windows[i] != devtools_window_) | 950 if (open_windows[i] != main_window_ && open_windows[i] != secondary_window_) |
930 open_windows[i]->Close(); | 951 open_windows[i]->Close(); |
931 } | 952 } |
932 base::RunLoop().RunUntilIdle(); | 953 base::RunLoop().RunUntilIdle(); |
933 } | 954 } |
934 | 955 |
935 void BlinkTestController::OnResetDone() { | 956 void BlinkTestController::OnResetDone() { |
936 if (is_leak_detection_enabled_) { | 957 if (is_leak_detection_enabled_) { |
937 if (main_window_ && main_window_->web_contents()) { | 958 if (main_window_ && main_window_->web_contents()) { |
938 RenderViewHost* render_view_host = | 959 RenderViewHost* render_view_host = |
939 main_window_->web_contents()->GetRenderViewHost(); | 960 main_window_->web_contents()->GetRenderViewHost(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 } | 1039 } |
1019 DCHECK(layout_test_control_map_[frame].get()); | 1040 DCHECK(layout_test_control_map_[frame].get()); |
1020 return layout_test_control_map_[frame].get(); | 1041 return layout_test_control_map_[frame].get(); |
1021 } | 1042 } |
1022 | 1043 |
1023 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { | 1044 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { |
1024 layout_test_control_map_.erase(frame); | 1045 layout_test_control_map_.erase(frame); |
1025 } | 1046 } |
1026 | 1047 |
1027 } // namespace content | 1048 } // namespace content |
OLD | NEW |