Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: content/shell/browser/layout_test/blink_test_controller.cc

Issue 2756623002: DevTools: extract bindings from ShellDevToolsFrontend (Closed)
Patch Set: fixup Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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_window_.reset();
498 devtools_frontend_->Close(); 497 devtools_bindings_.reset();
dgozman 2017/03/20 22:40:22 First reset bindings, as they use WebContents from
chenwilliam 2017/03/21 18:17:29 Done.
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 if (test_phase_ != BETWEEN_TESTS) { 579 if (test_phase_ != BETWEEN_TESTS) {
582 Shell::CloseAllWindows(); 580 Shell::CloseAllWindows();
583 base::ThreadTaskRunnerHandle::Get()->PostTask( 581 base::ThreadTaskRunnerHandle::Get()->PostTask(
584 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 582 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
585 test_phase_ = CLEAN_UP; 583 test_phase_ = CLEAN_UP;
586 } else if (main_window_) { 584 } else if (main_window_) {
587 main_window_->Close(); 585 main_window_->Close();
588 } 586 }
589 main_window_ = NULL; 587 main_window_ = NULL;
590 current_pid_ = base::kNullProcessId; 588 current_pid_ = base::kNullProcessId;
589 devtools_bindings_.reset();
dgozman 2017/03/20 22:40:22 Same here - reset bindings before destroying main
chenwilliam 2017/03/21 18:17:29 Done.
591 } 590 }
592 591
593 void BlinkTestController::HandleNewRenderFrameHost(RenderFrameHost* frame) { 592 void BlinkTestController::HandleNewRenderFrameHost(RenderFrameHost* frame) {
594 // All RenderFrameHosts in layout tests should get Mojo bindings. 593 // All RenderFrameHosts in layout tests should get Mojo bindings.
595 if (!(frame->GetEnabledBindings() & BINDINGS_POLICY_MOJO)) 594 if (!(frame->GetEnabledBindings() & BINDINGS_POLICY_MOJO))
596 frame->AllowBindings(BINDINGS_POLICY_MOJO); 595 frame->AllowBindings(BINDINGS_POLICY_MOJO);
597 596
598 RenderProcessHost* process = frame->GetProcess(); 597 RenderProcessHost* process = frame->GetProcess();
599 bool main_window = 598 bool main_window =
600 WebContents::FromRenderFrameHost(frame) == main_window_->web_contents(); 599 WebContents::FromRenderFrameHost(frame) == main_window_->web_contents();
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if (devtools_bindings_)
dgozman 2017/03/20 22:40:22 We can just destroy bindings here.
chenwilliam 2017/03/21 18:17:29 Done.
832 devtools_frontend_->DisconnectFromTarget(); 834 devtools_bindings_->DisconnectFromTarget();
833 } 835 }
834 836
835 void BlinkTestController::OnGoToOffset(int offset) { 837 void BlinkTestController::OnGoToOffset(int offset) {
836 main_window_->GoBackOrForward(offset); 838 main_window_->GoBackOrForward(offset);
837 } 839 }
838 840
839 void BlinkTestController::OnReload() { 841 void BlinkTestController::OnReload() {
840 main_window_->Reload(); 842 main_window_->Reload();
841 } 843 }
842 844
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 main_window_->web_contents()->GetRenderViewHost(); 885 main_window_->web_contents()->GetRenderViewHost();
884 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), 886 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(),
885 routing_ids, 887 routing_ids,
886 session_histories, 888 session_histories,
887 current_entry_indexes)); 889 current_entry_indexes));
888 } 890 }
889 891
890 void BlinkTestController::OnCloseRemainingWindows() { 892 void BlinkTestController::OnCloseRemainingWindows() {
891 DevToolsAgentHost::DetachAllClients(); 893 DevToolsAgentHost::DetachAllClients();
892 std::vector<Shell*> open_windows(Shell::windows()); 894 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) { 895 for (size_t i = 0; i < open_windows.size(); ++i) {
896 if (open_windows[i] != main_window_ && open_windows[i] != devtools_shell) 896 if (open_windows[i] != main_window_ &&
897 open_windows[i] != devtools_window_.get())
897 open_windows[i]->Close(); 898 open_windows[i]->Close();
898 } 899 }
899 base::RunLoop().RunUntilIdle(); 900 base::RunLoop().RunUntilIdle();
900 } 901 }
901 902
902 void BlinkTestController::OnResetDone() { 903 void BlinkTestController::OnResetDone() {
903 if (is_leak_detection_enabled_) { 904 if (is_leak_detection_enabled_) {
904 if (main_window_ && main_window_->web_contents()) { 905 if (main_window_ && main_window_->web_contents()) {
905 RenderViewHost* render_view_host = 906 RenderViewHost* render_view_host =
906 main_window_->web_contents()->GetRenderViewHost(); 907 main_window_->web_contents()->GetRenderViewHost();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 } 986 }
986 DCHECK(layout_test_control_map_[frame].get()); 987 DCHECK(layout_test_control_map_[frame].get());
987 return layout_test_control_map_[frame].get(); 988 return layout_test_control_map_[frame].get();
988 } 989 }
989 990
990 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { 991 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) {
991 layout_test_control_map_.erase(frame); 992 layout_test_control_map_.erase(frame);
992 } 993 }
993 994
994 } // namespace content 995 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698