| 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 26 matching lines...) Expand all Loading... |
| 37 #include "content/public/browser/render_view_host.h" | 37 #include "content/public/browser/render_view_host.h" |
| 38 #include "content/public/browser/render_widget_host.h" | 38 #include "content/public/browser/render_widget_host.h" |
| 39 #include "content/public/browser/render_widget_host_view.h" | 39 #include "content/public/browser/render_widget_host_view.h" |
| 40 #include "content/public/browser/service_worker_context.h" | 40 #include "content/public/browser/service_worker_context.h" |
| 41 #include "content/public/browser/storage_partition.h" | 41 #include "content/public/browser/storage_partition.h" |
| 42 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
| 43 #include "content/public/common/associated_interface_provider.h" | 43 #include "content/public/common/associated_interface_provider.h" |
| 44 #include "content/public/common/bindings_policy.h" | 44 #include "content/public/common/bindings_policy.h" |
| 45 #include "content/public/common/content_switches.h" | 45 #include "content/public/common/content_switches.h" |
| 46 #include "content/public/common/url_constants.h" | 46 #include "content/public/common/url_constants.h" |
| 47 #include "content/shell/browser/layout_test/devtools_protocol_test_bindings.h" |
| 47 #include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factor
y.h" | 48 #include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factor
y.h" |
| 48 #include "content/shell/browser/layout_test/layout_test_content_browser_client.h
" | 49 #include "content/shell/browser/layout_test/layout_test_content_browser_client.h
" |
| 49 #include "content/shell/browser/layout_test/layout_test_devtools_bindings.h" | 50 #include "content/shell/browser/layout_test/layout_test_devtools_bindings.h" |
| 50 #include "content/shell/browser/layout_test/layout_test_first_device_bluetooth_c
hooser.h" | 51 #include "content/shell/browser/layout_test/layout_test_first_device_bluetooth_c
hooser.h" |
| 51 #include "content/shell/browser/shell.h" | 52 #include "content/shell/browser/shell.h" |
| 52 #include "content/shell/browser/shell_browser_context.h" | 53 #include "content/shell/browser/shell_browser_context.h" |
| 53 #include "content/shell/browser/shell_content_browser_client.h" | 54 #include "content/shell/browser/shell_content_browser_client.h" |
| 54 #include "content/shell/browser/shell_devtools_frontend.h" | 55 #include "content/shell/browser/shell_devtools_frontend.h" |
| 55 #include "content/shell/common/layout_test/layout_test_messages.h" | 56 #include "content/shell/common/layout_test/layout_test_messages.h" |
| 56 #include "content/shell/common/layout_test/layout_test_switches.h" | 57 #include "content/shell/common/layout_test/layout_test_switches.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 bool enable_pixel_dumping, | 294 bool enable_pixel_dumping, |
| 294 const std::string& expected_pixel_hash) { | 295 const std::string& expected_pixel_hash) { |
| 295 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 296 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 296 test_phase_ = DURING_TEST; | 297 test_phase_ = DURING_TEST; |
| 297 current_working_directory_ = current_working_directory; | 298 current_working_directory_ = current_working_directory; |
| 298 enable_pixel_dumping_ = enable_pixel_dumping; | 299 enable_pixel_dumping_ = enable_pixel_dumping; |
| 299 expected_pixel_hash_ = expected_pixel_hash; | 300 expected_pixel_hash_ = expected_pixel_hash; |
| 300 bool is_devtools_js_test = false; | 301 bool is_devtools_js_test = false; |
| 301 test_url_ = LayoutTestDevToolsBindings::MapTestURLIfNeeded( | 302 test_url_ = LayoutTestDevToolsBindings::MapTestURLIfNeeded( |
| 302 test_url, &is_devtools_js_test); | 303 test_url, &is_devtools_js_test); |
| 304 bool is_devtools_protocol_test = false; |
| 305 test_url_ = DevToolsProtocolTestBindings::MapTestURLIfNeeded( |
| 306 test_url_, &is_devtools_protocol_test); |
| 303 did_send_initial_test_configuration_ = false; | 307 did_send_initial_test_configuration_ = false; |
| 304 printer_->reset(); | 308 printer_->reset(); |
| 305 frame_to_layout_dump_map_.clear(); | 309 frame_to_layout_dump_map_.clear(); |
| 306 render_process_host_observer_.RemoveAll(); | 310 render_process_host_observer_.RemoveAll(); |
| 307 all_observed_render_process_hosts_.clear(); | 311 all_observed_render_process_hosts_.clear(); |
| 308 main_window_render_process_hosts_.clear(); | 312 main_window_render_process_hosts_.clear(); |
| 309 accumulated_layout_test_runtime_flags_changes_.Clear(); | 313 accumulated_layout_test_runtime_flags_changes_.Clear(); |
| 310 layout_test_control_map_.clear(); | 314 layout_test_control_map_.clear(); |
| 311 ShellBrowserContext* browser_context = | 315 ShellBrowserContext* browser_context = |
| 312 ShellContentBrowserClient::Get()->browser_context(); | 316 ShellContentBrowserClient::Get()->browser_context(); |
| 313 is_compositing_test_ = | 317 is_compositing_test_ = |
| 314 test_url_.spec().find("compositing/") != std::string::npos; | 318 test_url_.spec().find("compositing/") != std::string::npos; |
| 315 initial_size_ = Shell::GetShellDefaultSize(); | 319 initial_size_ = Shell::GetShellDefaultSize(); |
| 316 // The W3C SVG layout tests use a different size than the other layout tests. | 320 // 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) | 321 if (test_url_.spec().find("W3C-SVG-1.1") != std::string::npos) |
| 318 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip); | 322 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip); |
| 319 if (!main_window_) { | 323 if (!main_window_) { |
| 320 main_window_ = content::Shell::CreateNewWindow( | 324 main_window_ = content::Shell::CreateNewWindow( |
| 321 browser_context, | 325 browser_context, |
| 322 GURL(), | 326 GURL(), |
| 323 NULL, | 327 NULL, |
| 324 initial_size_); | 328 initial_size_); |
| 325 WebContentsObserver::Observe(main_window_->web_contents()); | 329 WebContentsObserver::Observe(main_window_->web_contents()); |
| 330 if (is_devtools_protocol_test) { |
| 331 devtools_protocol_test_bindings_.reset( |
| 332 new DevToolsProtocolTestBindings(main_window_->web_contents())); |
| 333 } |
| 326 current_pid_ = base::kNullProcessId; | 334 current_pid_ = base::kNullProcessId; |
| 327 default_prefs_ = | 335 default_prefs_ = |
| 328 main_window_->web_contents()->GetRenderViewHost()->GetWebkitPreferences(); | 336 main_window_->web_contents()->GetRenderViewHost()->GetWebkitPreferences(); |
| 329 if (is_devtools_js_test) | 337 if (is_devtools_js_test) |
| 330 LoadDevToolsJSTest(); | 338 LoadDevToolsJSTest(); |
| 331 else | 339 else |
| 332 main_window_->LoadURL(test_url_); | 340 main_window_->LoadURL(test_url_); |
| 333 } else { | 341 } else { |
| 334 #if defined(OS_MACOSX) | 342 #if defined(OS_MACOSX) |
| 335 // Shell::SizeTo is not implemented on all platforms. | 343 // Shell::SizeTo is not implemented on all platforms. |
| 336 main_window_->SizeTo(initial_size_); | 344 main_window_->SizeTo(initial_size_); |
| 337 #endif | 345 #endif |
| 338 main_window_->web_contents() | 346 main_window_->web_contents() |
| 339 ->GetRenderViewHost() | 347 ->GetRenderViewHost() |
| 340 ->GetWidget() | 348 ->GetWidget() |
| 341 ->GetView() | 349 ->GetView() |
| 342 ->SetSize(initial_size_); | 350 ->SetSize(initial_size_); |
| 343 main_window_->web_contents() | 351 main_window_->web_contents() |
| 344 ->GetRenderViewHost() | 352 ->GetRenderViewHost() |
| 345 ->GetWidget() | 353 ->GetWidget() |
| 346 ->WasResized(); | 354 ->WasResized(); |
| 347 RenderViewHost* render_view_host = | 355 RenderViewHost* render_view_host = |
| 348 main_window_->web_contents()->GetRenderViewHost(); | 356 main_window_->web_contents()->GetRenderViewHost(); |
| 349 | 357 |
| 358 if (is_devtools_protocol_test) { |
| 359 devtools_protocol_test_bindings_.reset( |
| 360 new DevToolsProtocolTestBindings(main_window_->web_contents())); |
| 361 } |
| 362 |
| 350 // Compositing tests override the default preferences (see | 363 // Compositing tests override the default preferences (see |
| 351 // BlinkTestController::OverrideWebkitPrefs) so we force them to be | 364 // BlinkTestController::OverrideWebkitPrefs) so we force them to be |
| 352 // calculated again to ensure is_compositing_test_ changes are picked up. | 365 // calculated again to ensure is_compositing_test_ changes are picked up. |
| 353 OverrideWebkitPrefs(&default_prefs_); | 366 OverrideWebkitPrefs(&default_prefs_); |
| 354 | 367 |
| 355 render_view_host->UpdateWebkitPreferences(default_prefs_); | 368 render_view_host->UpdateWebkitPreferences(default_prefs_); |
| 356 HandleNewRenderFrameHost(render_view_host->GetMainFrame()); | 369 HandleNewRenderFrameHost(render_view_host->GetMainFrame()); |
| 357 | 370 |
| 358 if (is_devtools_js_test) { | 371 if (is_devtools_js_test) { |
| 359 LoadDevToolsJSTest(); | 372 LoadDevToolsJSTest(); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 637 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 625 printer_->AddErrorMessage("#CRASHED - gpu"); | 638 printer_->AddErrorMessage("#CRASHED - gpu"); |
| 626 DiscardMainWindow(); | 639 DiscardMainWindow(); |
| 627 } | 640 } |
| 628 | 641 |
| 629 void BlinkTestController::DiscardMainWindow() { | 642 void BlinkTestController::DiscardMainWindow() { |
| 630 // If we're running a test, we need to close all windows and exit the message | 643 // If we're running a test, we need to close all windows and exit the message |
| 631 // loop. Otherwise, we're already outside of the message loop, and we just | 644 // loop. Otherwise, we're already outside of the message loop, and we just |
| 632 // discard the main window. | 645 // discard the main window. |
| 633 devtools_bindings_.reset(); | 646 devtools_bindings_.reset(); |
| 647 devtools_protocol_test_bindings_.reset(); |
| 634 WebContentsObserver::Observe(NULL); | 648 WebContentsObserver::Observe(NULL); |
| 635 if (test_phase_ != BETWEEN_TESTS) { | 649 if (test_phase_ != BETWEEN_TESTS) { |
| 636 Shell::CloseAllWindows(); | 650 Shell::CloseAllWindows(); |
| 637 base::ThreadTaskRunnerHandle::Get()->PostTask( | 651 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 638 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 652 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 639 test_phase_ = CLEAN_UP; | 653 test_phase_ = CLEAN_UP; |
| 640 } else if (main_window_) { | 654 } else if (main_window_) { |
| 641 main_window_->Close(); | 655 main_window_->Close(); |
| 642 } | 656 } |
| 643 main_window_ = NULL; | 657 main_window_ = NULL; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 process->Send(new LayoutTestMsg_ReplicateLayoutTestRuntimeFlagsChanges( | 716 process->Send(new LayoutTestMsg_ReplicateLayoutTestRuntimeFlagsChanges( |
| 703 accumulated_layout_test_runtime_flags_changes_)); | 717 accumulated_layout_test_runtime_flags_changes_)); |
| 704 } | 718 } |
| 705 } | 719 } |
| 706 | 720 |
| 707 void BlinkTestController::OnTestFinished() { | 721 void BlinkTestController::OnTestFinished() { |
| 708 test_phase_ = CLEAN_UP; | 722 test_phase_ = CLEAN_UP; |
| 709 if (!printer_->output_finished()) | 723 if (!printer_->output_finished()) |
| 710 printer_->PrintImageFooter(); | 724 printer_->PrintImageFooter(); |
| 711 main_window_->web_contents()->ExitFullscreen(/*will_cause_resize=*/false); | 725 main_window_->web_contents()->ExitFullscreen(/*will_cause_resize=*/false); |
| 726 devtools_protocol_test_bindings_.reset(); |
| 712 | 727 |
| 713 ShellBrowserContext* browser_context = | 728 ShellBrowserContext* browser_context = |
| 714 ShellContentBrowserClient::Get()->browser_context(); | 729 ShellContentBrowserClient::Get()->browser_context(); |
| 715 StoragePartition* storage_partition = | 730 StoragePartition* storage_partition = |
| 716 BrowserContext::GetStoragePartition(browser_context, nullptr); | 731 BrowserContext::GetStoragePartition(browser_context, nullptr); |
| 717 storage_partition->GetServiceWorkerContext()->ClearAllServiceWorkersForTest( | 732 storage_partition->GetServiceWorkerContext()->ClearAllServiceWorkersForTest( |
| 718 base::Bind(&BlinkTestController::OnAllServiceWorkersCleared, | 733 base::Bind(&BlinkTestController::OnAllServiceWorkersCleared, |
| 719 base::Unretained(this))); | 734 base::Unretained(this))); |
| 720 storage_partition->ClearBluetoothAllowedDevicesMapForTesting(); | 735 storage_partition->ClearBluetoothAllowedDevicesMapForTesting(); |
| 721 } | 736 } |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 } | 1054 } |
| 1040 DCHECK(layout_test_control_map_[frame].get()); | 1055 DCHECK(layout_test_control_map_[frame].get()); |
| 1041 return layout_test_control_map_[frame].get(); | 1056 return layout_test_control_map_[frame].get(); |
| 1042 } | 1057 } |
| 1043 | 1058 |
| 1044 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { | 1059 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { |
| 1045 layout_test_control_map_.erase(frame); | 1060 layout_test_control_map_.erase(frame); |
| 1046 } | 1061 } |
| 1047 | 1062 |
| 1048 } // namespace content | 1063 } // namespace content |
| OLD | NEW |