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 (secondary_window_) |
| 498 devtools_frontend_->Close(); | 498 secondary_window_.reset(); |
| 499 devtools_frontend_ = NULL; | 499 devtools_window_ = nullptr; |
|
dgozman
2017/03/17 22:44:14
Reset devtools_bindings_.
chenwilliam
2017/03/20 21:32:18
Done.
| |
| 500 } | 500 } |
| 501 | 501 |
| 502 void BlinkTestController::WebContentsDestroyed() { | 502 void BlinkTestController::WebContentsDestroyed() { |
| 503 DCHECK(CalledOnValidThread()); | 503 DCHECK(CalledOnValidThread()); |
| 504 printer_->AddErrorMessage("FAIL: main window was destroyed"); | 504 printer_->AddErrorMessage("FAIL: main window was destroyed"); |
| 505 DiscardMainWindow(); | 505 DiscardMainWindow(); |
| 506 } | 506 } |
| 507 | 507 |
| 508 void BlinkTestController::RenderProcessHostDestroyed( | 508 void BlinkTestController::RenderProcessHostDestroyed( |
| 509 RenderProcessHost* render_process_host) { | 509 RenderProcessHost* render_process_host) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 | 659 |
| 660 ShellBrowserContext* browser_context = | 660 ShellBrowserContext* browser_context = |
| 661 ShellContentBrowserClient::Get()->browser_context(); | 661 ShellContentBrowserClient::Get()->browser_context(); |
| 662 StoragePartition* storage_partition = | 662 StoragePartition* storage_partition = |
| 663 BrowserContext::GetStoragePartition(browser_context, nullptr); | 663 BrowserContext::GetStoragePartition(browser_context, nullptr); |
| 664 storage_partition->GetServiceWorkerContext()->ClearAllServiceWorkersForTest( | 664 storage_partition->GetServiceWorkerContext()->ClearAllServiceWorkersForTest( |
| 665 base::Bind(base::IgnoreResult(&BlinkTestController::Send), | 665 base::Bind(base::IgnoreResult(&BlinkTestController::Send), |
| 666 base::Unretained(this), | 666 base::Unretained(this), |
| 667 new ShellViewMsg_Reset(render_view_host->GetRoutingID()))); | 667 new ShellViewMsg_Reset(render_view_host->GetRoutingID()))); |
| 668 storage_partition->ClearBluetoothAllowedDevicesMapForTesting(); | 668 storage_partition->ClearBluetoothAllowedDevicesMapForTesting(); |
| 669 devtools_bindings_.reset(); | |
|
dgozman
2017/03/17 22:44:14
Let's instead do this in DiscardMainWindow.
chenwilliam
2017/03/20 21:32:20
Done.
| |
| 669 } | 670 } |
| 670 | 671 |
| 671 void BlinkTestController::OnImageDump(const std::string& actual_pixel_hash, | 672 void BlinkTestController::OnImageDump(const std::string& actual_pixel_hash, |
| 672 const SkBitmap& image) { | 673 const SkBitmap& image) { |
| 673 SkAutoLockPixels image_lock(image); | 674 SkAutoLockPixels image_lock(image); |
| 674 | 675 |
| 675 printer_->PrintImageHeader(actual_pixel_hash, expected_pixel_hash_); | 676 printer_->PrintImageHeader(actual_pixel_hash, expected_pixel_hash_); |
| 676 | 677 |
| 677 // Only encode and dump the png if the hashes don't match. Encoding the | 678 // Only encode and dump the png if the hashes don't match. Encoding the |
| 678 // image is really expensive. | 679 // image is really expensive. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 main_window_->web_contents()->GetRenderViewHost(); | 799 main_window_->web_contents()->GetRenderViewHost(); |
| 799 main_render_view_host->OnWebkitPreferencesChanged(); | 800 main_render_view_host->OnWebkitPreferencesChanged(); |
| 800 } | 801 } |
| 801 | 802 |
| 802 void BlinkTestController::OnClearDevToolsLocalStorage() { | 803 void BlinkTestController::OnClearDevToolsLocalStorage() { |
| 803 ShellBrowserContext* browser_context = | 804 ShellBrowserContext* browser_context = |
| 804 ShellContentBrowserClient::Get()->browser_context(); | 805 ShellContentBrowserClient::Get()->browser_context(); |
| 805 StoragePartition* storage_partition = | 806 StoragePartition* storage_partition = |
| 806 BrowserContext::GetStoragePartition(browser_context, NULL); | 807 BrowserContext::GetStoragePartition(browser_context, NULL); |
| 807 storage_partition->GetDOMStorageContext()->DeleteLocalStorage( | 808 storage_partition->GetDOMStorageContext()->DeleteLocalStorage( |
| 808 content::LayoutTestDevToolsFrontend::GetDevToolsPathAsURL("") | 809 content::LayoutTestDevToolsBindings::GetDevToolsPathAsURL("") |
| 809 .GetOrigin()); | 810 .GetOrigin()); |
| 810 } | 811 } |
| 811 | 812 |
| 812 void BlinkTestController::OnShowDevTools(const std::string& settings, | 813 void BlinkTestController::OnShowDevTools(const std::string& settings, |
| 813 const std::string& frontend_url) { | 814 const std::string& frontend_url) { |
| 814 if (!devtools_frontend_) { | 815 if (!secondary_window_) { |
| 815 devtools_frontend_ = LayoutTestDevToolsFrontend::Show( | 816 ShellBrowserContext* browser_context = |
| 816 main_window_->web_contents(), settings, frontend_url); | 817 ShellContentBrowserClient::Get()->browser_context(); |
| 817 } else { | 818 secondary_window_.reset(content::Shell::CreateNewWindow( |
| 818 devtools_frontend_->ReuseFrontend(settings, frontend_url); | 819 browser_context, GURL(), NULL, initial_size_)); |
|
dgozman
2017/03/17 22:44:14
nullptr
chenwilliam
2017/03/20 21:32:20
Done.
| |
| 819 } | 820 } |
| 820 devtools_frontend_->Activate(); | 821 devtools_window_ = secondary_window_.get(); |
| 821 devtools_frontend_->Focus(); | 822 devtools_bindings_.reset(new LayoutTestDevToolsBindings( |
| 823 devtools_window_->web_contents(), main_window_->web_contents())); | |
| 824 devtools_bindings_->SetPreferences(settings); | |
| 825 devtools_window_->LoadURL( | |
| 826 devtools_bindings_->GetDevToolsPathAsURL(frontend_url)); | |
| 827 | |
| 828 // Need to ensure frontend host is created when re-using a shell | |
| 829 devtools_bindings_->CreateFrontendHost(); | |
|
dgozman
2017/03/17 22:44:14
Let's combine this and two previous calls into dev
chenwilliam
2017/03/20 21:32:20
Done.
| |
| 830 | |
| 831 devtools_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); | |
| 832 devtools_window_->web_contents()->Focus(); | |
| 822 } | 833 } |
| 823 | 834 |
| 824 void BlinkTestController::OnEvaluateInDevTools( | 835 void BlinkTestController::OnEvaluateInDevTools( |
| 825 int call_id, const std::string& script) { | 836 int call_id, const std::string& script) { |
| 826 if (devtools_frontend_) | 837 if (devtools_bindings_) |
| 827 devtools_frontend_->EvaluateInFrontend(call_id, script); | 838 devtools_bindings_->EvaluateInFrontend(call_id, script); |
| 828 } | 839 } |
| 829 | 840 |
| 830 void BlinkTestController::OnCloseDevTools() { | 841 void BlinkTestController::OnCloseDevTools() { |
| 831 if (devtools_frontend_) | 842 if (devtools_bindings_) |
| 832 devtools_frontend_->DisconnectFromTarget(); | 843 devtools_bindings_->DisconnectFromTarget(); |
| 833 } | 844 } |
| 834 | 845 |
| 835 void BlinkTestController::OnGoToOffset(int offset) { | 846 void BlinkTestController::OnGoToOffset(int offset) { |
| 836 main_window_->GoBackOrForward(offset); | 847 main_window_->GoBackOrForward(offset); |
| 837 } | 848 } |
| 838 | 849 |
| 839 void BlinkTestController::OnReload() { | 850 void BlinkTestController::OnReload() { |
| 840 main_window_->Reload(); | 851 main_window_->Reload(); |
| 841 } | 852 } |
| 842 | 853 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 883 main_window_->web_contents()->GetRenderViewHost(); | 894 main_window_->web_contents()->GetRenderViewHost(); |
| 884 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), | 895 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), |
| 885 routing_ids, | 896 routing_ids, |
| 886 session_histories, | 897 session_histories, |
| 887 current_entry_indexes)); | 898 current_entry_indexes)); |
| 888 } | 899 } |
| 889 | 900 |
| 890 void BlinkTestController::OnCloseRemainingWindows() { | 901 void BlinkTestController::OnCloseRemainingWindows() { |
| 891 DevToolsAgentHost::DetachAllClients(); | 902 DevToolsAgentHost::DetachAllClients(); |
| 892 std::vector<Shell*> open_windows(Shell::windows()); | 903 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) { | 904 for (size_t i = 0; i < open_windows.size(); ++i) { |
| 896 if (open_windows[i] != main_window_ && open_windows[i] != devtools_shell) | 905 if (open_windows[i] != main_window_ && |
| 906 open_windows[i] != secondary_window_.get()) | |
| 897 open_windows[i]->Close(); | 907 open_windows[i]->Close(); |
| 898 } | 908 } |
| 899 base::RunLoop().RunUntilIdle(); | 909 base::RunLoop().RunUntilIdle(); |
| 900 } | 910 } |
| 901 | 911 |
| 902 void BlinkTestController::OnResetDone() { | 912 void BlinkTestController::OnResetDone() { |
| 903 if (is_leak_detection_enabled_) { | 913 if (is_leak_detection_enabled_) { |
| 904 if (main_window_ && main_window_->web_contents()) { | 914 if (main_window_ && main_window_->web_contents()) { |
| 905 RenderViewHost* render_view_host = | 915 RenderViewHost* render_view_host = |
| 906 main_window_->web_contents()->GetRenderViewHost(); | 916 main_window_->web_contents()->GetRenderViewHost(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 985 } | 995 } |
| 986 DCHECK(layout_test_control_map_[frame].get()); | 996 DCHECK(layout_test_control_map_[frame].get()); |
| 987 return layout_test_control_map_[frame].get(); | 997 return layout_test_control_map_[frame].get(); |
| 988 } | 998 } |
| 989 | 999 |
| 990 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { | 1000 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { |
| 991 layout_test_control_map_.erase(frame); | 1001 layout_test_control_map_.erase(frame); |
| 992 } | 1002 } |
| 993 | 1003 |
| 994 } // namespace content | 1004 } // namespace content |
| OLD | NEW |