Chromium Code Reviews| 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_integration_test = |
| 301 test_url.spec().find("/devtools-js/") != std::string::npos; | |
| 302 if (test_url.spec().find("/inspector-unit/") != std::string::npos) | |
| 303 test_url_ = LayoutTestDevToolsBindings::MapUnitTestURL(test_url); | |
|
dgozman
2017/06/15 21:16:48
Let's move this all to a single call
LayoutTestDe
chenwilliam
2017/06/19 18:33:29
Done.
| |
| 304 else if (is_devtools_integration_test) | |
| 305 test_url_ = LayoutTestDevToolsBindings::MapIntegrationTestURL(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()); |
| 326 current_pid_ = base::kNullProcessId; | 331 current_pid_ = base::kNullProcessId; |
| 327 default_prefs_ = | 332 default_prefs_ = |
| 328 main_window_->web_contents()->GetRenderViewHost()->GetWebkitPreferences(); | 333 main_window_->web_contents()->GetRenderViewHost()->GetWebkitPreferences(); |
| 329 main_window_->LoadURL(test_url_); | 334 if (is_devtools_integration_test) |
| 335 LoadDevToolsJSTest(); | |
| 336 else | |
| 337 main_window_->LoadURL(test_url_); | |
| 330 } else { | 338 } else { |
| 331 #if defined(OS_MACOSX) | 339 #if defined(OS_MACOSX) |
| 332 // Shell::SizeTo is not implemented on all platforms. | 340 // Shell::SizeTo is not implemented on all platforms. |
| 333 main_window_->SizeTo(initial_size_); | 341 main_window_->SizeTo(initial_size_); |
| 334 #endif | 342 #endif |
| 335 main_window_->web_contents() | 343 main_window_->web_contents() |
| 336 ->GetRenderViewHost() | 344 ->GetRenderViewHost() |
| 337 ->GetWidget() | 345 ->GetWidget() |
| 338 ->GetView() | 346 ->GetView() |
| 339 ->SetSize(initial_size_); | 347 ->SetSize(initial_size_); |
| 340 main_window_->web_contents() | 348 main_window_->web_contents() |
| 341 ->GetRenderViewHost() | 349 ->GetRenderViewHost() |
| 342 ->GetWidget() | 350 ->GetWidget() |
| 343 ->WasResized(); | 351 ->WasResized(); |
| 344 RenderViewHost* render_view_host = | 352 RenderViewHost* render_view_host = |
| 345 main_window_->web_contents()->GetRenderViewHost(); | 353 main_window_->web_contents()->GetRenderViewHost(); |
| 346 | 354 |
| 347 // Compositing tests override the default preferences (see | 355 // Compositing tests override the default preferences (see |
| 348 // BlinkTestController::OverrideWebkitPrefs) so we force them to be | 356 // BlinkTestController::OverrideWebkitPrefs) so we force them to be |
| 349 // calculated again to ensure is_compositing_test_ changes are picked up. | 357 // calculated again to ensure is_compositing_test_ changes are picked up. |
| 350 OverrideWebkitPrefs(&default_prefs_); | 358 OverrideWebkitPrefs(&default_prefs_); |
| 351 | 359 |
| 352 render_view_host->UpdateWebkitPreferences(default_prefs_); | 360 render_view_host->UpdateWebkitPreferences(default_prefs_); |
| 353 HandleNewRenderFrameHost(render_view_host->GetMainFrame()); | 361 HandleNewRenderFrameHost(render_view_host->GetMainFrame()); |
| 354 | 362 |
| 355 NavigationController::LoadURLParams params(test_url_); | 363 if (is_devtools_integration_test) { |
| 356 params.transition_type = ui::PageTransitionFromInt( | 364 LoadDevToolsJSTest(); |
| 357 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); | 365 } else { |
| 358 params.should_clear_history_list = true; | 366 NavigationController::LoadURLParams params(test_url_); |
| 359 main_window_->web_contents()->GetController().LoadURLWithParams(params); | 367 params.transition_type = ui::PageTransitionFromInt( |
| 360 main_window_->web_contents()->Focus(); | 368 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); |
| 369 params.should_clear_history_list = true; | |
| 370 main_window_->web_contents()->GetController().LoadURLWithParams(params); | |
| 371 main_window_->web_contents()->Focus(); | |
| 372 } | |
| 361 } | 373 } |
| 362 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->SetActive( | 374 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->SetActive( |
| 363 true); | 375 true); |
| 364 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); | 376 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); |
| 365 return true; | 377 return true; |
| 366 } | 378 } |
| 367 | 379 |
| 380 void BlinkTestController::LoadDevToolsJSTest() { | |
| 381 devtools_window_ = main_window_; | |
| 382 if (!secondary_window_) { | |
|
dgozman
2017/06/15 21:16:48
Let's have SecondaryWindow() method which lazily c
chenwilliam
2017/06/19 18:33:29
Done.
| |
| 383 ShellBrowserContext* browser_context = | |
| 384 ShellContentBrowserClient::Get()->browser_context(); | |
| 385 secondary_window_ = content::Shell::CreateNewWindow(browser_context, GURL(), | |
| 386 nullptr, initial_size_); | |
| 387 } | |
| 388 devtools_bindings_.reset(LayoutTestDevToolsBindings::LoadDevTools( | |
| 389 devtools_window_->web_contents(), secondary_window_->web_contents(), "", | |
| 390 test_url_.spec())); | |
| 391 secondary_window_->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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 834 ShellContentBrowserClient::Get()->browser_context(); | 861 ShellContentBrowserClient::Get()->browser_context(); |
| 835 StoragePartition* storage_partition = | 862 StoragePartition* storage_partition = |
| 836 BrowserContext::GetStoragePartition(browser_context, NULL); | 863 BrowserContext::GetStoragePartition(browser_context, NULL); |
| 837 storage_partition->GetDOMStorageContext()->DeleteLocalStorage( | 864 storage_partition->GetDOMStorageContext()->DeleteLocalStorage( |
| 838 content::LayoutTestDevToolsBindings::GetDevToolsPathAsURL("") | 865 content::LayoutTestDevToolsBindings::GetDevToolsPathAsURL("") |
| 839 .GetOrigin()); | 866 .GetOrigin()); |
| 840 } | 867 } |
| 841 | 868 |
| 842 void BlinkTestController::OnShowDevTools(const std::string& settings, | 869 void BlinkTestController::OnShowDevTools(const std::string& settings, |
| 843 const std::string& frontend_url) { | 870 const std::string& frontend_url) { |
| 844 if (!devtools_window_) { | 871 if (!secondary_window_) { |
| 845 ShellBrowserContext* browser_context = | 872 ShellBrowserContext* browser_context = |
| 846 ShellContentBrowserClient::Get()->browser_context(); | 873 ShellContentBrowserClient::Get()->browser_context(); |
| 847 devtools_window_ = content::Shell::CreateNewWindow(browser_context, GURL(), | 874 secondary_window_ = content::Shell::CreateNewWindow(browser_context, GURL(), |
| 848 nullptr, initial_size_); | 875 nullptr, initial_size_); |
| 849 } | 876 } |
| 850 | 877 devtools_window_ = secondary_window_; |
| 851 devtools_bindings_.reset(LayoutTestDevToolsBindings::LoadDevTools( | 878 devtools_bindings_.reset(LayoutTestDevToolsBindings::LoadDevTools( |
| 852 devtools_window_->web_contents(), main_window_->web_contents(), settings, | 879 devtools_window_->web_contents(), main_window_->web_contents(), settings, |
| 853 frontend_url)); | 880 frontend_url)); |
| 854 devtools_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); | 881 devtools_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); |
| 855 devtools_window_->web_contents()->Focus(); | 882 devtools_window_->web_contents()->Focus(); |
| 856 } | 883 } |
| 857 | 884 |
| 858 void BlinkTestController::OnEvaluateInDevTools( | 885 void BlinkTestController::OnEvaluateInDevTools( |
| 859 int call_id, const std::string& script) { | 886 int call_id, const std::string& script) { |
| 860 if (devtools_bindings_) | 887 if (devtools_bindings_) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 917 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), | 944 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), |
| 918 routing_ids, | 945 routing_ids, |
| 919 session_histories, | 946 session_histories, |
| 920 current_entry_indexes)); | 947 current_entry_indexes)); |
| 921 } | 948 } |
| 922 | 949 |
| 923 void BlinkTestController::OnCloseRemainingWindows() { | 950 void BlinkTestController::OnCloseRemainingWindows() { |
| 924 DevToolsAgentHost::DetachAllClients(); | 951 DevToolsAgentHost::DetachAllClients(); |
| 925 std::vector<Shell*> open_windows(Shell::windows()); | 952 std::vector<Shell*> open_windows(Shell::windows()); |
| 926 for (size_t i = 0; i < open_windows.size(); ++i) { | 953 for (size_t i = 0; i < open_windows.size(); ++i) { |
| 927 if (open_windows[i] != main_window_ && open_windows[i] != devtools_window_) | 954 if (open_windows[i] != main_window_ && open_windows[i] != secondary_window_) |
| 928 open_windows[i]->Close(); | 955 open_windows[i]->Close(); |
| 929 } | 956 } |
| 930 base::RunLoop().RunUntilIdle(); | 957 base::RunLoop().RunUntilIdle(); |
| 931 } | 958 } |
| 932 | 959 |
| 933 void BlinkTestController::OnResetDone() { | 960 void BlinkTestController::OnResetDone() { |
| 934 if (is_leak_detection_enabled_) { | 961 if (is_leak_detection_enabled_) { |
| 935 if (main_window_ && main_window_->web_contents()) { | 962 if (main_window_ && main_window_->web_contents()) { |
| 936 RenderViewHost* render_view_host = | 963 RenderViewHost* render_view_host = |
| 937 main_window_->web_contents()->GetRenderViewHost(); | 964 main_window_->web_contents()->GetRenderViewHost(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1016 } | 1043 } |
| 1017 DCHECK(layout_test_control_map_[frame].get()); | 1044 DCHECK(layout_test_control_map_[frame].get()); |
| 1018 return layout_test_control_map_[frame].get(); | 1045 return layout_test_control_map_[frame].get(); |
| 1019 } | 1046 } |
| 1020 | 1047 |
| 1021 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { | 1048 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { |
| 1022 layout_test_control_map_.erase(frame); | 1049 layout_test_control_map_.erase(frame); |
| 1023 } | 1050 } |
| 1024 | 1051 |
| 1025 } // namespace content | 1052 } // namespace content |
| OLD | NEW |