| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 GURL devtools_protocol_test_url = |
| 301 DevToolsProtocolTestBindings::GetProtocolTestURL(test_url); |
| 302 if (!devtools_protocol_test_url.is_empty()) |
| 303 test_url_ = devtools_protocol_test_url; |
| 304 else if (test_url.spec().find("/inspector-unit/") != std::string::npos) |
| 305 test_url_ = LayoutTestDevToolsBindings::MapJSTestURL(test_url); |
| 306 else |
| 300 test_url_ = test_url; | 307 test_url_ = test_url; |
| 301 else | |
| 302 test_url_ = LayoutTestDevToolsBindings::MapJSTestURL(test_url); | |
| 303 did_send_initial_test_configuration_ = false; | 308 did_send_initial_test_configuration_ = false; |
| 304 printer_->reset(); | 309 printer_->reset(); |
| 305 frame_to_layout_dump_map_.clear(); | 310 frame_to_layout_dump_map_.clear(); |
| 306 render_process_host_observer_.RemoveAll(); | 311 render_process_host_observer_.RemoveAll(); |
| 307 all_observed_render_process_hosts_.clear(); | 312 all_observed_render_process_hosts_.clear(); |
| 308 main_window_render_process_hosts_.clear(); | 313 main_window_render_process_hosts_.clear(); |
| 309 accumulated_layout_test_runtime_flags_changes_.Clear(); | 314 accumulated_layout_test_runtime_flags_changes_.Clear(); |
| 310 layout_test_control_map_.clear(); | 315 layout_test_control_map_.clear(); |
| 311 ShellBrowserContext* browser_context = | 316 ShellBrowserContext* browser_context = |
| 312 ShellContentBrowserClient::Get()->browser_context(); | 317 ShellContentBrowserClient::Get()->browser_context(); |
| 313 is_compositing_test_ = | 318 is_compositing_test_ = |
| 314 test_url_.spec().find("compositing/") != std::string::npos; | 319 test_url_.spec().find("compositing/") != std::string::npos; |
| 315 initial_size_ = Shell::GetShellDefaultSize(); | 320 initial_size_ = Shell::GetShellDefaultSize(); |
| 316 // The W3C SVG layout tests use a different size than the other layout tests. | 321 // 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) | 322 if (test_url_.spec().find("W3C-SVG-1.1") != std::string::npos) |
| 318 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip); | 323 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip); |
| 319 if (!main_window_) { | 324 if (!main_window_) { |
| 320 main_window_ = content::Shell::CreateNewWindow( | 325 main_window_ = content::Shell::CreateNewWindow( |
| 321 browser_context, | 326 browser_context, |
| 322 GURL(), | 327 GURL(), |
| 323 NULL, | 328 NULL, |
| 324 initial_size_); | 329 initial_size_); |
| 325 WebContentsObserver::Observe(main_window_->web_contents()); | 330 WebContentsObserver::Observe(main_window_->web_contents()); |
| 331 if (!devtools_protocol_test_url.is_empty()) { |
| 332 devtools_protocol_test_bindings_.reset( |
| 333 new DevToolsProtocolTestBindings(main_window_->web_contents())); |
| 334 } |
| 326 current_pid_ = base::kNullProcessId; | 335 current_pid_ = base::kNullProcessId; |
| 327 default_prefs_ = | 336 default_prefs_ = |
| 328 main_window_->web_contents()->GetRenderViewHost()->GetWebkitPreferences(); | 337 main_window_->web_contents()->GetRenderViewHost()->GetWebkitPreferences(); |
| 329 main_window_->LoadURL(test_url_); | 338 main_window_->LoadURL(test_url_); |
| 330 } else { | 339 } else { |
| 331 #if defined(OS_MACOSX) | 340 #if defined(OS_MACOSX) |
| 332 // Shell::SizeTo is not implemented on all platforms. | 341 // Shell::SizeTo is not implemented on all platforms. |
| 333 main_window_->SizeTo(initial_size_); | 342 main_window_->SizeTo(initial_size_); |
| 334 #endif | 343 #endif |
| 335 main_window_->web_contents() | 344 main_window_->web_contents() |
| 336 ->GetRenderViewHost() | 345 ->GetRenderViewHost() |
| 337 ->GetWidget() | 346 ->GetWidget() |
| 338 ->GetView() | 347 ->GetView() |
| 339 ->SetSize(initial_size_); | 348 ->SetSize(initial_size_); |
| 340 main_window_->web_contents() | 349 main_window_->web_contents() |
| 341 ->GetRenderViewHost() | 350 ->GetRenderViewHost() |
| 342 ->GetWidget() | 351 ->GetWidget() |
| 343 ->WasResized(); | 352 ->WasResized(); |
| 344 RenderViewHost* render_view_host = | 353 RenderViewHost* render_view_host = |
| 345 main_window_->web_contents()->GetRenderViewHost(); | 354 main_window_->web_contents()->GetRenderViewHost(); |
| 346 | 355 |
| 356 if (!devtools_protocol_test_url.is_empty()) { |
| 357 devtools_protocol_test_bindings_.reset( |
| 358 new DevToolsProtocolTestBindings(main_window_->web_contents())); |
| 359 } |
| 360 |
| 347 // Compositing tests override the default preferences (see | 361 // Compositing tests override the default preferences (see |
| 348 // BlinkTestController::OverrideWebkitPrefs) so we force them to be | 362 // BlinkTestController::OverrideWebkitPrefs) so we force them to be |
| 349 // calculated again to ensure is_compositing_test_ changes are picked up. | 363 // calculated again to ensure is_compositing_test_ changes are picked up. |
| 350 OverrideWebkitPrefs(&default_prefs_); | 364 OverrideWebkitPrefs(&default_prefs_); |
| 351 | 365 |
| 352 render_view_host->UpdateWebkitPreferences(default_prefs_); | 366 render_view_host->UpdateWebkitPreferences(default_prefs_); |
| 353 HandleNewRenderFrameHost(render_view_host->GetMainFrame()); | 367 HandleNewRenderFrameHost(render_view_host->GetMainFrame()); |
| 354 | 368 |
| 355 NavigationController::LoadURLParams params(test_url_); | 369 NavigationController::LoadURLParams params(test_url_); |
| 356 params.transition_type = ui::PageTransitionFromInt( | 370 params.transition_type = ui::PageTransitionFromInt( |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 611 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 598 printer_->AddErrorMessage("#CRASHED - gpu"); | 612 printer_->AddErrorMessage("#CRASHED - gpu"); |
| 599 DiscardMainWindow(); | 613 DiscardMainWindow(); |
| 600 } | 614 } |
| 601 | 615 |
| 602 void BlinkTestController::DiscardMainWindow() { | 616 void BlinkTestController::DiscardMainWindow() { |
| 603 // If we're running a test, we need to close all windows and exit the message | 617 // If we're running a test, we need to close all windows and exit the message |
| 604 // loop. Otherwise, we're already outside of the message loop, and we just | 618 // loop. Otherwise, we're already outside of the message loop, and we just |
| 605 // discard the main window. | 619 // discard the main window. |
| 606 devtools_bindings_.reset(); | 620 devtools_bindings_.reset(); |
| 621 devtools_protocol_test_bindings_.reset(); |
| 607 WebContentsObserver::Observe(NULL); | 622 WebContentsObserver::Observe(NULL); |
| 608 if (test_phase_ != BETWEEN_TESTS) { | 623 if (test_phase_ != BETWEEN_TESTS) { |
| 609 Shell::CloseAllWindows(); | 624 Shell::CloseAllWindows(); |
| 610 base::ThreadTaskRunnerHandle::Get()->PostTask( | 625 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 611 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 626 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 612 test_phase_ = CLEAN_UP; | 627 test_phase_ = CLEAN_UP; |
| 613 } else if (main_window_) { | 628 } else if (main_window_) { |
| 614 main_window_->Close(); | 629 main_window_->Close(); |
| 615 } | 630 } |
| 616 main_window_ = NULL; | 631 main_window_ = NULL; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 } | 692 } |
| 678 } | 693 } |
| 679 | 694 |
| 680 void BlinkTestController::OnTestFinished() { | 695 void BlinkTestController::OnTestFinished() { |
| 681 test_phase_ = CLEAN_UP; | 696 test_phase_ = CLEAN_UP; |
| 682 if (!printer_->output_finished()) | 697 if (!printer_->output_finished()) |
| 683 printer_->PrintImageFooter(); | 698 printer_->PrintImageFooter(); |
| 684 RenderViewHost* render_view_host = | 699 RenderViewHost* render_view_host = |
| 685 main_window_->web_contents()->GetRenderViewHost(); | 700 main_window_->web_contents()->GetRenderViewHost(); |
| 686 main_window_->web_contents()->ExitFullscreen(/*will_cause_resize=*/false); | 701 main_window_->web_contents()->ExitFullscreen(/*will_cause_resize=*/false); |
| 702 devtools_protocol_test_bindings_.reset(); |
| 687 | 703 |
| 688 ShellBrowserContext* browser_context = | 704 ShellBrowserContext* browser_context = |
| 689 ShellContentBrowserClient::Get()->browser_context(); | 705 ShellContentBrowserClient::Get()->browser_context(); |
| 690 StoragePartition* storage_partition = | 706 StoragePartition* storage_partition = |
| 691 BrowserContext::GetStoragePartition(browser_context, nullptr); | 707 BrowserContext::GetStoragePartition(browser_context, nullptr); |
| 692 storage_partition->GetServiceWorkerContext()->ClearAllServiceWorkersForTest( | 708 storage_partition->GetServiceWorkerContext()->ClearAllServiceWorkersForTest( |
| 693 base::Bind(base::IgnoreResult(&BlinkTestController::Send), | 709 base::Bind(base::IgnoreResult(&BlinkTestController::Send), |
| 694 base::Unretained(this), | 710 base::Unretained(this), |
| 695 new ShellViewMsg_Reset(render_view_host->GetRoutingID()))); | 711 new ShellViewMsg_Reset(render_view_host->GetRoutingID()))); |
| 696 storage_partition->ClearBluetoothAllowedDevicesMapForTesting(); | 712 storage_partition->ClearBluetoothAllowedDevicesMapForTesting(); |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 } | 1032 } |
| 1017 DCHECK(layout_test_control_map_[frame].get()); | 1033 DCHECK(layout_test_control_map_[frame].get()); |
| 1018 return layout_test_control_map_[frame].get(); | 1034 return layout_test_control_map_[frame].get(); |
| 1019 } | 1035 } |
| 1020 | 1036 |
| 1021 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { | 1037 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { |
| 1022 layout_test_control_map_.erase(frame); | 1038 layout_test_control_map_.erase(frame); |
| 1023 } | 1039 } |
| 1024 | 1040 |
| 1025 } // namespace content | 1041 } // namespace content |
| OLD | NEW |