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 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 BlinkTestController* BlinkTestController::instance_ = NULL; | 220 BlinkTestController* BlinkTestController::instance_ = NULL; |
| 221 | 221 |
| 222 // static | 222 // static |
| 223 BlinkTestController* BlinkTestController::Get() { | 223 BlinkTestController* BlinkTestController::Get() { |
| 224 DCHECK(instance_); | 224 DCHECK(instance_); |
| 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 devtools_window_(nullptr), | |
| 230 test_phase_(BETWEEN_TESTS), | 231 test_phase_(BETWEEN_TESTS), |
| 231 is_leak_detection_enabled_( | 232 is_leak_detection_enabled_( |
| 232 base::CommandLine::ForCurrentProcess()->HasSwitch( | 233 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 233 switches::kEnableLeakDetection)), | 234 switches::kEnableLeakDetection)), |
| 234 crash_when_leak_found_(false), | 235 crash_when_leak_found_(false), |
| 235 devtools_frontend_(NULL), | |
| 236 render_process_host_observer_(this) { | 236 render_process_host_observer_(this) { |
| 237 CHECK(!instance_); | 237 CHECK(!instance_); |
| 238 instance_ = this; | 238 instance_ = this; |
| 239 | 239 |
| 240 if (is_leak_detection_enabled_) { | 240 if (is_leak_detection_enabled_) { |
| 241 std::string switchValue = | 241 std::string switchValue = |
| 242 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 242 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 243 switches::kEnableLeakDetection); | 243 switches::kEnableLeakDetection); |
| 244 crash_when_leak_found_ = switchValue == switches::kCrashOnFailure; | 244 crash_when_leak_found_ = switchValue == switches::kCrashOnFailure; |
| 245 } | 245 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 270 bool enable_pixel_dumping, | 270 bool enable_pixel_dumping, |
| 271 const std::string& expected_pixel_hash) { | 271 const std::string& expected_pixel_hash) { |
| 272 DCHECK(CalledOnValidThread()); | 272 DCHECK(CalledOnValidThread()); |
| 273 test_phase_ = DURING_TEST; | 273 test_phase_ = DURING_TEST; |
| 274 current_working_directory_ = current_working_directory; | 274 current_working_directory_ = current_working_directory; |
| 275 enable_pixel_dumping_ = enable_pixel_dumping; | 275 enable_pixel_dumping_ = enable_pixel_dumping; |
| 276 expected_pixel_hash_ = expected_pixel_hash; | 276 expected_pixel_hash_ = expected_pixel_hash; |
| 277 if (test_url.spec().find("/inspector-unit/") == std::string::npos) | 277 if (test_url.spec().find("/inspector-unit/") == std::string::npos) |
| 278 test_url_ = test_url; | 278 test_url_ = test_url; |
| 279 else | 279 else |
| 280 test_url_ = LayoutTestDevToolsFrontend::MapJSTestURL(test_url); | 280 test_url_ = LayoutTestDevToolsBindings::MapJSTestURL(test_url); |
| 281 did_send_initial_test_configuration_ = false; | 281 did_send_initial_test_configuration_ = false; |
| 282 printer_->reset(); | 282 printer_->reset(); |
| 283 frame_to_layout_dump_map_.clear(); | 283 frame_to_layout_dump_map_.clear(); |
| 284 render_process_host_observer_.RemoveAll(); | 284 render_process_host_observer_.RemoveAll(); |
| 285 all_observed_render_process_hosts_.clear(); | 285 all_observed_render_process_hosts_.clear(); |
| 286 main_window_render_process_hosts_.clear(); | 286 main_window_render_process_hosts_.clear(); |
| 287 accumulated_layout_test_runtime_flags_changes_.Clear(); | 287 accumulated_layout_test_runtime_flags_changes_.Clear(); |
| 288 layout_test_control_map_.clear(); | 288 layout_test_control_map_.clear(); |
| 289 ShellBrowserContext* browser_context = | 289 ShellBrowserContext* browser_context = |
| 290 ShellContentBrowserClient::Get()->browser_context(); | 290 ShellContentBrowserClient::Get()->browser_context(); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 | 487 |
| 488 void BlinkTestController::RenderFrameCreated( | 488 void BlinkTestController::RenderFrameCreated( |
| 489 RenderFrameHost* render_frame_host) { | 489 RenderFrameHost* render_frame_host) { |
| 490 DCHECK(CalledOnValidThread()); | 490 DCHECK(CalledOnValidThread()); |
| 491 HandleNewRenderFrameHost(render_frame_host); | 491 HandleNewRenderFrameHost(render_frame_host); |
| 492 } | 492 } |
| 493 | 493 |
| 494 void BlinkTestController::DevToolsProcessCrashed() { | 494 void BlinkTestController::DevToolsProcessCrashed() { |
| 495 DCHECK(CalledOnValidThread()); | 495 DCHECK(CalledOnValidThread()); |
| 496 printer_->AddErrorMessage("#CRASHED - devtools"); | 496 printer_->AddErrorMessage("#CRASHED - devtools"); |
| 497 if (devtools_frontend_) | 497 if (devtools_window_) |
| 498 devtools_frontend_->Close(); | 498 devtools_window_->Close(); |
| 499 devtools_frontend_ = NULL; | 499 if (secondary_window_.get() == devtools_window_) |
|
dgozman
2017/03/16 21:38:07
This is always true.
chenwilliam
2017/03/17 22:08:26
Removed (will do in f/u patch). I took out the dev
| |
| 500 secondary_window_.reset(); | |
| 501 else | |
| 502 main_window_ = nullptr; | |
| 503 devtools_window_ = nullptr; | |
| 500 } | 504 } |
| 501 | 505 |
| 502 void BlinkTestController::WebContentsDestroyed() { | 506 void BlinkTestController::WebContentsDestroyed() { |
| 503 DCHECK(CalledOnValidThread()); | 507 DCHECK(CalledOnValidThread()); |
| 504 printer_->AddErrorMessage("FAIL: main window was destroyed"); | 508 printer_->AddErrorMessage("FAIL: main window was destroyed"); |
| 505 DiscardMainWindow(); | 509 DiscardMainWindow(); |
| 506 } | 510 } |
| 507 | 511 |
| 508 void BlinkTestController::RenderProcessHostDestroyed( | 512 void BlinkTestController::RenderProcessHostDestroyed( |
| 509 RenderProcessHost* render_process_host) { | 513 RenderProcessHost* render_process_host) { |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 main_window_->web_contents()->GetRenderViewHost(); | 802 main_window_->web_contents()->GetRenderViewHost(); |
| 799 main_render_view_host->OnWebkitPreferencesChanged(); | 803 main_render_view_host->OnWebkitPreferencesChanged(); |
| 800 } | 804 } |
| 801 | 805 |
| 802 void BlinkTestController::OnClearDevToolsLocalStorage() { | 806 void BlinkTestController::OnClearDevToolsLocalStorage() { |
| 803 ShellBrowserContext* browser_context = | 807 ShellBrowserContext* browser_context = |
| 804 ShellContentBrowserClient::Get()->browser_context(); | 808 ShellContentBrowserClient::Get()->browser_context(); |
| 805 StoragePartition* storage_partition = | 809 StoragePartition* storage_partition = |
| 806 BrowserContext::GetStoragePartition(browser_context, NULL); | 810 BrowserContext::GetStoragePartition(browser_context, NULL); |
| 807 storage_partition->GetDOMStorageContext()->DeleteLocalStorage( | 811 storage_partition->GetDOMStorageContext()->DeleteLocalStorage( |
| 808 content::LayoutTestDevToolsFrontend::GetDevToolsPathAsURL("") | 812 content::LayoutTestDevToolsBindings::GetDevToolsPathAsURL("") |
| 809 .GetOrigin()); | 813 .GetOrigin()); |
| 810 } | 814 } |
| 811 | 815 |
| 812 void BlinkTestController::OnShowDevTools(const std::string& settings, | 816 void BlinkTestController::OnShowDevTools(const std::string& settings, |
| 813 const std::string& frontend_url) { | 817 const std::string& frontend_url) { |
| 814 if (!devtools_frontend_) { | 818 if (!devtools_bindings_) { |
| 815 devtools_frontend_ = LayoutTestDevToolsFrontend::Show( | 819 if (!secondary_window_) { |
| 816 main_window_->web_contents(), settings, frontend_url); | 820 ShellBrowserContext* browser_context = |
| 821 ShellContentBrowserClient::Get()->browser_context(); | |
| 822 secondary_window_.reset(content::Shell::CreateNewWindow( | |
| 823 browser_context, GURL(), NULL, initial_size_)); | |
| 824 } | |
| 825 devtools_window_ = secondary_window_.get(); | |
| 826 devtools_bindings_.reset(new LayoutTestDevToolsBindings( | |
| 827 devtools_window_->web_contents(), main_window_->web_contents())); | |
| 817 } else { | 828 } else { |
| 818 devtools_frontend_->ReuseFrontend(settings, frontend_url); | 829 devtools_bindings_->DisconnectFromTarget(); |
|
dgozman
2017/03/16 21:38:07
Can we instead destroy bindings when the test fini
chenwilliam
2017/03/17 22:08:26
Done.
| |
| 830 devtools_bindings_->reset_ready_for_test(); | |
| 831 devtools_bindings_->clear_pending_evaluations(); | |
| 819 } | 832 } |
| 820 devtools_frontend_->Activate(); | 833 devtools_bindings_->SetPreferences(settings); |
| 821 devtools_frontend_->Focus(); | 834 devtools_window_->LoadURL( |
| 835 devtools_bindings_->GetDevToolsPathAsURL(frontend_url)); | |
| 836 devtools_bindings_->Activate(); | |
| 837 devtools_bindings_->Focus(); | |
| 822 } | 838 } |
| 823 | 839 |
| 824 void BlinkTestController::OnEvaluateInDevTools( | 840 void BlinkTestController::OnEvaluateInDevTools( |
| 825 int call_id, const std::string& script) { | 841 int call_id, const std::string& script) { |
| 826 if (devtools_frontend_) | 842 if (devtools_bindings_) |
| 827 devtools_frontend_->EvaluateInFrontend(call_id, script); | 843 devtools_bindings_->EvaluateInFrontend(call_id, script); |
| 828 } | 844 } |
| 829 | 845 |
| 830 void BlinkTestController::OnCloseDevTools() { | 846 void BlinkTestController::OnCloseDevTools() { |
| 831 if (devtools_frontend_) | 847 if (devtools_bindings_) |
| 832 devtools_frontend_->DisconnectFromTarget(); | 848 devtools_bindings_->DisconnectFromTarget(); |
| 833 } | 849 } |
| 834 | 850 |
| 835 void BlinkTestController::OnGoToOffset(int offset) { | 851 void BlinkTestController::OnGoToOffset(int offset) { |
| 836 main_window_->GoBackOrForward(offset); | 852 main_window_->GoBackOrForward(offset); |
| 837 } | 853 } |
| 838 | 854 |
| 839 void BlinkTestController::OnReload() { | 855 void BlinkTestController::OnReload() { |
| 840 main_window_->Reload(); | 856 main_window_->Reload(); |
| 841 } | 857 } |
| 842 | 858 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 883 main_window_->web_contents()->GetRenderViewHost(); | 899 main_window_->web_contents()->GetRenderViewHost(); |
| 884 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), | 900 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), |
| 885 routing_ids, | 901 routing_ids, |
| 886 session_histories, | 902 session_histories, |
| 887 current_entry_indexes)); | 903 current_entry_indexes)); |
| 888 } | 904 } |
| 889 | 905 |
| 890 void BlinkTestController::OnCloseRemainingWindows() { | 906 void BlinkTestController::OnCloseRemainingWindows() { |
| 891 DevToolsAgentHost::DetachAllClients(); | 907 DevToolsAgentHost::DetachAllClients(); |
| 892 std::vector<Shell*> open_windows(Shell::windows()); | 908 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) { | 909 for (size_t i = 0; i < open_windows.size(); ++i) { |
| 896 if (open_windows[i] != main_window_ && open_windows[i] != devtools_shell) | 910 if (open_windows[i] != main_window_ && |
| 911 open_windows[i] != secondary_window_.get()) | |
| 897 open_windows[i]->Close(); | 912 open_windows[i]->Close(); |
| 898 } | 913 } |
| 899 base::RunLoop().RunUntilIdle(); | 914 base::RunLoop().RunUntilIdle(); |
| 900 } | 915 } |
| 901 | 916 |
| 902 void BlinkTestController::OnResetDone() { | 917 void BlinkTestController::OnResetDone() { |
| 903 if (is_leak_detection_enabled_) { | 918 if (is_leak_detection_enabled_) { |
| 904 if (main_window_ && main_window_->web_contents()) { | 919 if (main_window_ && main_window_->web_contents()) { |
| 905 RenderViewHost* render_view_host = | 920 RenderViewHost* render_view_host = |
| 906 main_window_->web_contents()->GetRenderViewHost(); | 921 main_window_->web_contents()->GetRenderViewHost(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 985 } | 1000 } |
| 986 DCHECK(layout_test_control_map_[frame].get()); | 1001 DCHECK(layout_test_control_map_[frame].get()); |
| 987 return layout_test_control_map_[frame].get(); | 1002 return layout_test_control_map_[frame].get(); |
| 988 } | 1003 } |
| 989 | 1004 |
| 990 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { | 1005 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { |
| 991 layout_test_control_map_.erase(frame); | 1006 layout_test_control_map_.erase(frame); |
| 992 } | 1007 } |
| 993 | 1008 |
| 994 } // namespace content | 1009 } // namespace content |
| OLD | NEW |