| 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 25 matching lines...) Expand all Loading... |
| 36 #include "content/public/browser/render_widget_host.h" | 36 #include "content/public/browser/render_widget_host.h" |
| 37 #include "content/public/browser/render_widget_host_view.h" | 37 #include "content/public/browser/render_widget_host_view.h" |
| 38 #include "content/public/browser/service_worker_context.h" | 38 #include "content/public/browser/service_worker_context.h" |
| 39 #include "content/public/browser/storage_partition.h" | 39 #include "content/public/browser/storage_partition.h" |
| 40 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 41 #include "content/public/common/associated_interface_provider.h" | 41 #include "content/public/common/associated_interface_provider.h" |
| 42 #include "content/public/common/bindings_policy.h" | 42 #include "content/public/common/bindings_policy.h" |
| 43 #include "content/public/common/content_switches.h" | 43 #include "content/public/common/content_switches.h" |
| 44 #include "content/public/common/url_constants.h" | 44 #include "content/public/common/url_constants.h" |
| 45 #include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factor
y.h" | 45 #include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factor
y.h" |
| 46 #include "content/shell/browser/layout_test/layout_test_devtools_frontend.h" | 46 #include "content/shell/browser/layout_test/layout_test_devtools_bindings.h" |
| 47 #include "content/shell/browser/layout_test/layout_test_first_device_bluetooth_c
hooser.h" | 47 #include "content/shell/browser/layout_test/layout_test_first_device_bluetooth_c
hooser.h" |
| 48 #include "content/shell/browser/shell.h" | 48 #include "content/shell/browser/shell.h" |
| 49 #include "content/shell/browser/shell_browser_context.h" | 49 #include "content/shell/browser/shell_browser_context.h" |
| 50 #include "content/shell/browser/shell_content_browser_client.h" | 50 #include "content/shell/browser/shell_content_browser_client.h" |
| 51 #include "content/shell/browser/shell_devtools_frontend.h" | 51 #include "content/shell/browser/shell_devtools_frontend.h" |
| 52 #include "content/shell/common/layout_test/layout_test_messages.h" | 52 #include "content/shell/common/layout_test/layout_test_messages.h" |
| 53 #include "content/shell/common/layout_test/layout_test_switches.h" | 53 #include "content/shell/common/layout_test/layout_test_switches.h" |
| 54 #include "content/shell/common/shell_messages.h" | 54 #include "content/shell/common/shell_messages.h" |
| 55 #include "content/shell/renderer/layout_test/blink_test_helpers.h" | 55 #include "content/shell/renderer/layout_test/blink_test_helpers.h" |
| 56 #include "ui/gfx/codec/png_codec.h" | 56 #include "ui/gfx/codec/png_codec.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 return instance_; | 225 return instance_; |
| 226 } | 226 } |
| 227 | 227 |
| 228 BlinkTestController::BlinkTestController() | 228 BlinkTestController::BlinkTestController() |
| 229 : main_window_(NULL), | 229 : main_window_(NULL), |
| 230 test_phase_(BETWEEN_TESTS), | 230 test_phase_(BETWEEN_TESTS), |
| 231 is_leak_detection_enabled_( | 231 is_leak_detection_enabled_( |
| 232 base::CommandLine::ForCurrentProcess()->HasSwitch( | 232 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 233 switches::kEnableLeakDetection)), | 233 switches::kEnableLeakDetection)), |
| 234 crash_when_leak_found_(false), | 234 crash_when_leak_found_(false), |
| 235 devtools_frontend_(NULL), | |
| 236 render_process_host_observer_(this) { | 235 render_process_host_observer_(this) { |
| 237 CHECK(!instance_); | 236 CHECK(!instance_); |
| 238 instance_ = this; | 237 instance_ = this; |
| 239 | 238 |
| 240 if (is_leak_detection_enabled_) { | 239 if (is_leak_detection_enabled_) { |
| 241 std::string switchValue = | 240 std::string switchValue = |
| 242 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 241 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 243 switches::kEnableLeakDetection); | 242 switches::kEnableLeakDetection); |
| 244 crash_when_leak_found_ = switchValue == switches::kCrashOnFailure; | 243 crash_when_leak_found_ = switchValue == switches::kCrashOnFailure; |
| 245 } | 244 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 270 bool enable_pixel_dumping, | 269 bool enable_pixel_dumping, |
| 271 const std::string& expected_pixel_hash) { | 270 const std::string& expected_pixel_hash) { |
| 272 DCHECK(CalledOnValidThread()); | 271 DCHECK(CalledOnValidThread()); |
| 273 test_phase_ = DURING_TEST; | 272 test_phase_ = DURING_TEST; |
| 274 current_working_directory_ = current_working_directory; | 273 current_working_directory_ = current_working_directory; |
| 275 enable_pixel_dumping_ = enable_pixel_dumping; | 274 enable_pixel_dumping_ = enable_pixel_dumping; |
| 276 expected_pixel_hash_ = expected_pixel_hash; | 275 expected_pixel_hash_ = expected_pixel_hash; |
| 277 if (test_url.spec().find("/inspector-unit/") == std::string::npos) | 276 if (test_url.spec().find("/inspector-unit/") == std::string::npos) |
| 278 test_url_ = test_url; | 277 test_url_ = test_url; |
| 279 else | 278 else |
| 280 test_url_ = LayoutTestDevToolsFrontend::MapJSTestURL(test_url); | 279 test_url_ = LayoutTestDevToolsBindings::MapJSTestURL(test_url); |
| 281 did_send_initial_test_configuration_ = false; | 280 did_send_initial_test_configuration_ = false; |
| 282 printer_->reset(); | 281 printer_->reset(); |
| 283 frame_to_layout_dump_map_.clear(); | 282 frame_to_layout_dump_map_.clear(); |
| 284 render_process_host_observer_.RemoveAll(); | 283 render_process_host_observer_.RemoveAll(); |
| 285 all_observed_render_process_hosts_.clear(); | 284 all_observed_render_process_hosts_.clear(); |
| 286 main_window_render_process_hosts_.clear(); | 285 main_window_render_process_hosts_.clear(); |
| 287 accumulated_layout_test_runtime_flags_changes_.Clear(); | 286 accumulated_layout_test_runtime_flags_changes_.Clear(); |
| 288 layout_test_control_map_.clear(); | 287 layout_test_control_map_.clear(); |
| 289 ShellBrowserContext* browser_context = | 288 ShellBrowserContext* browser_context = |
| 290 ShellContentBrowserClient::Get()->browser_context(); | 289 ShellContentBrowserClient::Get()->browser_context(); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 | 486 |
| 488 void BlinkTestController::RenderFrameCreated( | 487 void BlinkTestController::RenderFrameCreated( |
| 489 RenderFrameHost* render_frame_host) { | 488 RenderFrameHost* render_frame_host) { |
| 490 DCHECK(CalledOnValidThread()); | 489 DCHECK(CalledOnValidThread()); |
| 491 HandleNewRenderFrameHost(render_frame_host); | 490 HandleNewRenderFrameHost(render_frame_host); |
| 492 } | 491 } |
| 493 | 492 |
| 494 void BlinkTestController::DevToolsProcessCrashed() { | 493 void BlinkTestController::DevToolsProcessCrashed() { |
| 495 DCHECK(CalledOnValidThread()); | 494 DCHECK(CalledOnValidThread()); |
| 496 printer_->AddErrorMessage("#CRASHED - devtools"); | 495 printer_->AddErrorMessage("#CRASHED - devtools"); |
| 497 if (devtools_frontend_) | 496 devtools_bindings_.reset(); |
| 498 devtools_frontend_->Close(); | 497 devtools_window_.reset(); |
| 499 devtools_frontend_ = NULL; | |
| 500 } | 498 } |
| 501 | 499 |
| 502 void BlinkTestController::WebContentsDestroyed() { | 500 void BlinkTestController::WebContentsDestroyed() { |
| 503 DCHECK(CalledOnValidThread()); | 501 DCHECK(CalledOnValidThread()); |
| 504 printer_->AddErrorMessage("FAIL: main window was destroyed"); | 502 printer_->AddErrorMessage("FAIL: main window was destroyed"); |
| 505 DiscardMainWindow(); | 503 DiscardMainWindow(); |
| 506 } | 504 } |
| 507 | 505 |
| 508 void BlinkTestController::RenderProcessHostDestroyed( | 506 void BlinkTestController::RenderProcessHostDestroyed( |
| 509 RenderProcessHost* render_process_host) { | 507 RenderProcessHost* render_process_host) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 base::TerminationStatus exit_code) { | 568 base::TerminationStatus exit_code) { |
| 571 DCHECK(CalledOnValidThread()); | 569 DCHECK(CalledOnValidThread()); |
| 572 printer_->AddErrorMessage("#CRASHED - gpu"); | 570 printer_->AddErrorMessage("#CRASHED - gpu"); |
| 573 DiscardMainWindow(); | 571 DiscardMainWindow(); |
| 574 } | 572 } |
| 575 | 573 |
| 576 void BlinkTestController::DiscardMainWindow() { | 574 void BlinkTestController::DiscardMainWindow() { |
| 577 // If we're running a test, we need to close all windows and exit the message | 575 // If we're running a test, we need to close all windows and exit the message |
| 578 // loop. Otherwise, we're already outside of the message loop, and we just | 576 // loop. Otherwise, we're already outside of the message loop, and we just |
| 579 // discard the main window. | 577 // discard the main window. |
| 578 devtools_bindings_.reset(); |
| 580 WebContentsObserver::Observe(NULL); | 579 WebContentsObserver::Observe(NULL); |
| 581 if (test_phase_ != BETWEEN_TESTS) { | 580 if (test_phase_ != BETWEEN_TESTS) { |
| 582 Shell::CloseAllWindows(); | 581 Shell::CloseAllWindows(); |
| 583 base::ThreadTaskRunnerHandle::Get()->PostTask( | 582 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 584 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 583 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 585 test_phase_ = CLEAN_UP; | 584 test_phase_ = CLEAN_UP; |
| 586 } else if (main_window_) { | 585 } else if (main_window_) { |
| 587 main_window_->Close(); | 586 main_window_->Close(); |
| 588 } | 587 } |
| 589 main_window_ = NULL; | 588 main_window_ = NULL; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 main_window_->web_contents()->GetRenderViewHost(); | 797 main_window_->web_contents()->GetRenderViewHost(); |
| 799 main_render_view_host->OnWebkitPreferencesChanged(); | 798 main_render_view_host->OnWebkitPreferencesChanged(); |
| 800 } | 799 } |
| 801 | 800 |
| 802 void BlinkTestController::OnClearDevToolsLocalStorage() { | 801 void BlinkTestController::OnClearDevToolsLocalStorage() { |
| 803 ShellBrowserContext* browser_context = | 802 ShellBrowserContext* browser_context = |
| 804 ShellContentBrowserClient::Get()->browser_context(); | 803 ShellContentBrowserClient::Get()->browser_context(); |
| 805 StoragePartition* storage_partition = | 804 StoragePartition* storage_partition = |
| 806 BrowserContext::GetStoragePartition(browser_context, NULL); | 805 BrowserContext::GetStoragePartition(browser_context, NULL); |
| 807 storage_partition->GetDOMStorageContext()->DeleteLocalStorage( | 806 storage_partition->GetDOMStorageContext()->DeleteLocalStorage( |
| 808 content::LayoutTestDevToolsFrontend::GetDevToolsPathAsURL("") | 807 content::LayoutTestDevToolsBindings::GetDevToolsPathAsURL("") |
| 809 .GetOrigin()); | 808 .GetOrigin()); |
| 810 } | 809 } |
| 811 | 810 |
| 812 void BlinkTestController::OnShowDevTools(const std::string& settings, | 811 void BlinkTestController::OnShowDevTools(const std::string& settings, |
| 813 const std::string& frontend_url) { | 812 const std::string& frontend_url) { |
| 814 if (!devtools_frontend_) { | 813 if (!devtools_window_) { |
| 815 devtools_frontend_ = LayoutTestDevToolsFrontend::Show( | 814 ShellBrowserContext* browser_context = |
| 816 main_window_->web_contents(), settings, frontend_url); | 815 ShellContentBrowserClient::Get()->browser_context(); |
| 817 } else { | 816 devtools_window_.reset(content::Shell::CreateNewWindow( |
| 818 devtools_frontend_->ReuseFrontend(settings, frontend_url); | 817 browser_context, GURL(), nullptr, initial_size_)); |
| 819 } | 818 } |
| 820 devtools_frontend_->Activate(); | 819 devtools_bindings_.reset(new LayoutTestDevToolsBindings( |
| 821 devtools_frontend_->Focus(); | 820 devtools_window_->web_contents(), main_window_->web_contents())); |
| 821 devtools_bindings_->LoadDevTools(settings, frontend_url); |
| 822 devtools_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); |
| 823 devtools_window_->web_contents()->Focus(); |
| 822 } | 824 } |
| 823 | 825 |
| 824 void BlinkTestController::OnEvaluateInDevTools( | 826 void BlinkTestController::OnEvaluateInDevTools( |
| 825 int call_id, const std::string& script) { | 827 int call_id, const std::string& script) { |
| 826 if (devtools_frontend_) | 828 if (devtools_bindings_) |
| 827 devtools_frontend_->EvaluateInFrontend(call_id, script); | 829 devtools_bindings_->EvaluateInFrontend(call_id, script); |
| 828 } | 830 } |
| 829 | 831 |
| 830 void BlinkTestController::OnCloseDevTools() { | 832 void BlinkTestController::OnCloseDevTools() { |
| 831 if (devtools_frontend_) | 833 devtools_bindings_.reset(); |
| 832 devtools_frontend_->DisconnectFromTarget(); | |
| 833 } | 834 } |
| 834 | 835 |
| 835 void BlinkTestController::OnGoToOffset(int offset) { | 836 void BlinkTestController::OnGoToOffset(int offset) { |
| 836 main_window_->GoBackOrForward(offset); | 837 main_window_->GoBackOrForward(offset); |
| 837 } | 838 } |
| 838 | 839 |
| 839 void BlinkTestController::OnReload() { | 840 void BlinkTestController::OnReload() { |
| 840 main_window_->Reload(); | 841 main_window_->Reload(); |
| 841 } | 842 } |
| 842 | 843 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 main_window_->web_contents()->GetRenderViewHost(); | 884 main_window_->web_contents()->GetRenderViewHost(); |
| 884 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), | 885 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), |
| 885 routing_ids, | 886 routing_ids, |
| 886 session_histories, | 887 session_histories, |
| 887 current_entry_indexes)); | 888 current_entry_indexes)); |
| 888 } | 889 } |
| 889 | 890 |
| 890 void BlinkTestController::OnCloseRemainingWindows() { | 891 void BlinkTestController::OnCloseRemainingWindows() { |
| 891 DevToolsAgentHost::DetachAllClients(); | 892 DevToolsAgentHost::DetachAllClients(); |
| 892 std::vector<Shell*> open_windows(Shell::windows()); | 893 std::vector<Shell*> open_windows(Shell::windows()); |
| 893 Shell* devtools_shell = devtools_frontend_ ? | |
| 894 devtools_frontend_->frontend_shell() : NULL; | |
| 895 for (size_t i = 0; i < open_windows.size(); ++i) { | 894 for (size_t i = 0; i < open_windows.size(); ++i) { |
| 896 if (open_windows[i] != main_window_ && open_windows[i] != devtools_shell) | 895 if (open_windows[i] != main_window_ && |
| 896 open_windows[i] != devtools_window_.get()) |
| 897 open_windows[i]->Close(); | 897 open_windows[i]->Close(); |
| 898 } | 898 } |
| 899 base::RunLoop().RunUntilIdle(); | 899 base::RunLoop().RunUntilIdle(); |
| 900 } | 900 } |
| 901 | 901 |
| 902 void BlinkTestController::OnResetDone() { | 902 void BlinkTestController::OnResetDone() { |
| 903 if (is_leak_detection_enabled_) { | 903 if (is_leak_detection_enabled_) { |
| 904 if (main_window_ && main_window_->web_contents()) { | 904 if (main_window_ && main_window_->web_contents()) { |
| 905 RenderViewHost* render_view_host = | 905 RenderViewHost* render_view_host = |
| 906 main_window_->web_contents()->GetRenderViewHost(); | 906 main_window_->web_contents()->GetRenderViewHost(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 } | 985 } |
| 986 DCHECK(layout_test_control_map_[frame].get()); | 986 DCHECK(layout_test_control_map_[frame].get()); |
| 987 return layout_test_control_map_[frame].get(); | 987 return layout_test_control_map_[frame].get(); |
| 988 } | 988 } |
| 989 | 989 |
| 990 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { | 990 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { |
| 991 layout_test_control_map_.erase(frame); | 991 layout_test_control_map_.erase(frame); |
| 992 } | 992 } |
| 993 | 993 |
| 994 } // namespace content | 994 } // namespace content |
| OLD | NEW |