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 27 matching lines...) Expand all Loading... | |
| 38 #include "content/public/browser/storage_partition.h" | 38 #include "content/public/browser/storage_partition.h" |
| 39 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 40 #include "content/public/common/content_switches.h" | 40 #include "content/public/common/content_switches.h" |
| 41 #include "content/public/common/url_constants.h" | 41 #include "content/public/common/url_constants.h" |
| 42 #include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factor y.h" | 42 #include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factor y.h" |
| 43 #include "content/shell/browser/layout_test/layout_test_devtools_frontend.h" | 43 #include "content/shell/browser/layout_test/layout_test_devtools_frontend.h" |
| 44 #include "content/shell/browser/shell.h" | 44 #include "content/shell/browser/shell.h" |
| 45 #include "content/shell/browser/shell_browser_context.h" | 45 #include "content/shell/browser/shell_browser_context.h" |
| 46 #include "content/shell/browser/shell_content_browser_client.h" | 46 #include "content/shell/browser/shell_content_browser_client.h" |
| 47 #include "content/shell/browser/shell_devtools_frontend.h" | 47 #include "content/shell/browser/shell_devtools_frontend.h" |
| 48 #include "content/shell/common/layout_test/layout_test_messages.h" | |
| 48 #include "content/shell/common/layout_test/layout_test_switches.h" | 49 #include "content/shell/common/layout_test/layout_test_switches.h" |
| 49 #include "content/shell/common/shell_messages.h" | 50 #include "content/shell/common/shell_messages.h" |
| 50 #include "content/shell/renderer/layout_test/blink_test_helpers.h" | 51 #include "content/shell/renderer/layout_test/blink_test_helpers.h" |
| 51 #include "ui/gfx/codec/png_codec.h" | 52 #include "ui/gfx/codec/png_codec.h" |
| 52 | 53 |
| 53 namespace content { | 54 namespace content { |
| 54 | 55 |
| 55 namespace { | 56 namespace { |
| 56 | 57 |
| 57 const int kTestSVGWindowWidthDip = 480; | 58 const int kTestSVGWindowWidthDip = 480; |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 void BlinkTestController::OpenURL(const GURL& url) { | 373 void BlinkTestController::OpenURL(const GURL& url) { |
| 373 if (test_phase_ != DURING_TEST) | 374 if (test_phase_ != DURING_TEST) |
| 374 return; | 375 return; |
| 375 | 376 |
| 376 Shell::CreateNewWindow(main_window_->web_contents()->GetBrowserContext(), | 377 Shell::CreateNewWindow(main_window_->web_contents()->GetBrowserContext(), |
| 377 url, | 378 url, |
| 378 main_window_->web_contents()->GetSiteInstance(), | 379 main_window_->web_contents()->GetSiteInstance(), |
| 379 gfx::Size()); | 380 gfx::Size()); |
| 380 } | 381 } |
| 381 | 382 |
| 382 void BlinkTestController::TestFinishedInSecondaryRenderer() { | 383 void BlinkTestController::OnTestFinishedInSecondaryRenderer() { |
| 383 RenderViewHost* render_view_host = | 384 RenderViewHost* render_view_host = |
| 384 main_window_->web_contents()->GetRenderViewHost(); | 385 main_window_->web_contents()->GetRenderViewHost(); |
| 385 render_view_host->Send( | 386 render_view_host->Send( |
| 386 new ShellViewMsg_NotifyDone(render_view_host->GetRoutingID())); | 387 new ShellViewMsg_NotifyDone(render_view_host->GetRoutingID())); |
| 387 } | 388 } |
| 388 | 389 |
| 389 bool BlinkTestController::IsMainWindow(WebContents* web_contents) const { | 390 bool BlinkTestController::IsMainWindow(WebContents* web_contents) const { |
| 390 return main_window_ && web_contents == main_window_->web_contents(); | 391 return main_window_ && web_contents == main_window_->web_contents(); |
| 391 } | 392 } |
| 392 | 393 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 | 440 |
| 440 return handled; | 441 return handled; |
| 441 } | 442 } |
| 442 | 443 |
| 443 bool BlinkTestController::OnMessageReceived( | 444 bool BlinkTestController::OnMessageReceived( |
| 444 const IPC::Message& message, | 445 const IPC::Message& message, |
| 445 RenderFrameHost* render_frame_host) { | 446 RenderFrameHost* render_frame_host) { |
| 446 bool handled = true; | 447 bool handled = true; |
| 447 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(BlinkTestController, message, | 448 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(BlinkTestController, message, |
| 448 render_frame_host) | 449 render_frame_host) |
| 449 IPC_MESSAGE_HANDLER(ShellViewHostMsg_LayoutTestRuntimeFlagsChanged, | |
| 450 OnLayoutTestRuntimeFlagsChanged) | |
| 451 IPC_MESSAGE_HANDLER(ShellViewHostMsg_LayoutDumpResponse, | 450 IPC_MESSAGE_HANDLER(ShellViewHostMsg_LayoutDumpResponse, |
| 452 OnLayoutDumpResponse) | 451 OnLayoutDumpResponse) |
| 453 IPC_MESSAGE_UNHANDLED(handled = false) | 452 IPC_MESSAGE_UNHANDLED(handled = false) |
| 454 IPC_END_MESSAGE_MAP() | 453 IPC_END_MESSAGE_MAP() |
| 455 return handled; | 454 return handled; |
| 456 } | 455 } |
| 457 | 456 |
| 458 void BlinkTestController::PluginCrashed(const base::FilePath& plugin_path, | 457 void BlinkTestController::PluginCrashed(const base::FilePath& plugin_path, |
| 459 base::ProcessId plugin_pid) { | 458 base::ProcessId plugin_pid) { |
| 460 DCHECK(CalledOnValidThread()); | 459 DCHECK(CalledOnValidThread()); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 params.test_url = test_url_; | 600 params.test_url = test_url_; |
| 602 params.enable_pixel_dumping = enable_pixel_dumping_; | 601 params.enable_pixel_dumping = enable_pixel_dumping_; |
| 603 params.allow_external_pages = | 602 params.allow_external_pages = |
| 604 base::CommandLine::ForCurrentProcess()->HasSwitch( | 603 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 605 switches::kAllowExternalPages); | 604 switches::kAllowExternalPages); |
| 606 params.expected_pixel_hash = expected_pixel_hash_; | 605 params.expected_pixel_hash = expected_pixel_hash_; |
| 607 params.initial_size = initial_size_; | 606 params.initial_size = initial_size_; |
| 608 | 607 |
| 609 if (did_send_initial_test_configuration_) { | 608 if (did_send_initial_test_configuration_) { |
| 610 frame->Send(new ShellViewMsg_ReplicateTestConfiguration( | 609 frame->Send(new ShellViewMsg_ReplicateTestConfiguration( |
| 611 frame->GetRoutingID(), params, | 610 frame->GetRoutingID(), params)); |
| 612 accumulated_layout_test_runtime_flags_changes_)); | |
| 613 } else { | 611 } else { |
| 614 did_send_initial_test_configuration_ = true; | 612 did_send_initial_test_configuration_ = true; |
| 615 frame->Send( | 613 frame->Send( |
| 616 new ShellViewMsg_SetTestConfiguration(frame->GetRoutingID(), params)); | 614 new ShellViewMsg_SetTestConfiguration(frame->GetRoutingID(), params)); |
| 617 } | 615 } |
| 618 } | 616 } |
| 619 | 617 |
| 620 // Is this a previously unknown renderer process? | 618 // Is this a previously unknown renderer process? |
| 621 if (!render_process_host_observer_.IsObserving(process)) { | 619 if (!render_process_host_observer_.IsObserving(process)) { |
| 622 render_process_host_observer_.Add(process); | 620 render_process_host_observer_.Add(process); |
| 623 all_observed_render_process_hosts_.insert(process); | 621 all_observed_render_process_hosts_.insert(process); |
| 624 | 622 |
| 625 if (!main_window) { | 623 if (!main_window) { |
| 626 frame->Send( | 624 frame->Send( |
| 627 new ShellViewMsg_SetupSecondaryRenderer(frame->GetRoutingID())); | 625 new ShellViewMsg_SetupSecondaryRenderer(frame->GetRoutingID())); |
| 628 } | 626 } |
| 627 | |
| 628 process->Send(new LayoutTestMsg_ReplicateLayoutTestRuntimeFlagsChanges( | |
| 629 accumulated_layout_test_runtime_flags_changes_)); | |
| 629 } | 630 } |
| 630 } | 631 } |
| 631 | 632 |
| 632 void BlinkTestController::OnTestFinished() { | 633 void BlinkTestController::OnTestFinished() { |
| 633 test_phase_ = CLEAN_UP; | 634 test_phase_ = CLEAN_UP; |
| 634 if (!printer_->output_finished()) | 635 if (!printer_->output_finished()) |
| 635 printer_->PrintImageFooter(); | 636 printer_->PrintImageFooter(); |
| 636 RenderViewHost* render_view_host = | 637 RenderViewHost* render_view_host = |
| 637 main_window_->web_contents()->GetRenderViewHost(); | 638 main_window_->web_contents()->GetRenderViewHost(); |
| 638 main_window_->web_contents()->ExitFullscreen(/*will_cause_resize=*/false); | 639 main_window_->web_contents()->ExitFullscreen(/*will_cause_resize=*/false); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 printer_->PrintTextBlock(dump); | 691 printer_->PrintTextBlock(dump); |
| 691 printer_->PrintTextFooter(); | 692 printer_->PrintTextFooter(); |
| 692 } | 693 } |
| 693 | 694 |
| 694 void BlinkTestController::OnInitiateLayoutDump() { | 695 void BlinkTestController::OnInitiateLayoutDump() { |
| 695 pending_layout_dumps_ = main_window_->web_contents()->SendToAllFrames( | 696 pending_layout_dumps_ = main_window_->web_contents()->SendToAllFrames( |
| 696 new ShellViewMsg_LayoutDumpRequest(MSG_ROUTING_NONE)); | 697 new ShellViewMsg_LayoutDumpRequest(MSG_ROUTING_NONE)); |
| 697 } | 698 } |
| 698 | 699 |
| 699 void BlinkTestController::OnLayoutTestRuntimeFlagsChanged( | 700 void BlinkTestController::OnLayoutTestRuntimeFlagsChanged( |
| 700 RenderFrameHost* sender, | 701 int sender_process_host_id, |
| 701 const base::DictionaryValue& changed_layout_test_runtime_flags) { | 702 const base::DictionaryValue& changed_layout_test_runtime_flags) { |
| 702 // Stash the changes for future renderers. | 703 // Stash the accumulated changes for future, not-yet-created renderers. |
| 703 accumulated_layout_test_runtime_flags_changes_.MergeDictionary( | 704 accumulated_layout_test_runtime_flags_changes_.MergeDictionary( |
| 704 &changed_layout_test_runtime_flags); | 705 &changed_layout_test_runtime_flags); |
| 705 | 706 |
| 706 // Only need to send the propagation message once per renderer process. | 707 // Propagate the changes to all the tracked renderer processes. |
| 707 std::set<int> already_covered_process_ids; | 708 for (RenderProcessHost* process : all_observed_render_process_hosts_) { |
| 709 // Do not propagate the changes back to the process that originated them. | |
| 710 // (propagating them back could also clobber subsequent changes in the | |
| 711 // originator). | |
| 712 if (process->GetID() == sender_process_host_id) | |
| 713 continue; | |
| 708 | 714 |
| 709 // No need to propagate the changes back to the process that originated them. | 715 process->Send(new LayoutTestMsg_ReplicateLayoutTestRuntimeFlagsChanges( |
| 710 // (propagating them back could also clobber subsequent changes in the | 716 changed_layout_test_runtime_flags)); |
|
Łukasz Anforowicz
2016/04/15 20:17:51
dcheng@ was (rightfully) unhappy about the shape o
| |
| 711 // originator). | |
| 712 already_covered_process_ids.insert(sender->GetProcess()->GetID()); | |
| 713 | |
| 714 // Propagate the changes to all the renderer processes associated with the | |
| 715 // main window. | |
| 716 for (RenderFrameHost* frame : main_window_->web_contents()->GetAllFrames()) { | |
| 717 bool inserted_new_item = | |
| 718 already_covered_process_ids.insert(frame->GetProcess()->GetID()).second; | |
| 719 if (inserted_new_item) { | |
| 720 frame->Send(new ShellViewMsg_ReplicateLayoutTestRuntimeFlagsChanges( | |
| 721 frame->GetRoutingID(), changed_layout_test_runtime_flags)); | |
| 722 } | |
| 723 } | 717 } |
| 724 } | 718 } |
| 725 | 719 |
| 726 void BlinkTestController::OnLayoutDumpResponse(RenderFrameHost* sender, | 720 void BlinkTestController::OnLayoutDumpResponse(RenderFrameHost* sender, |
| 727 const std::string& dump) { | 721 const std::string& dump) { |
| 728 // Store the result. | 722 // Store the result. |
| 729 auto pair = frame_to_layout_dump_map_.insert( | 723 auto pair = frame_to_layout_dump_map_.insert( |
| 730 std::make_pair(sender->GetFrameTreeNodeId(), dump)); | 724 std::make_pair(sender->GetFrameTreeNodeId(), dump)); |
| 731 bool insertion_took_place = pair.second; | 725 bool insertion_took_place = pair.second; |
| 732 DCHECK(insertion_took_place); | 726 DCHECK(insertion_took_place); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 933 } else { | 927 } else { |
| 934 printer_->AddErrorMessage(base::StringPrintf( | 928 printer_->AddErrorMessage(base::StringPrintf( |
| 935 "FAIL: Unexpected sendBluetoothManualChooserEvent() event name '%s'.", | 929 "FAIL: Unexpected sendBluetoothManualChooserEvent() event name '%s'.", |
| 936 event_name.c_str())); | 930 event_name.c_str())); |
| 937 return; | 931 return; |
| 938 } | 932 } |
| 939 bluetooth_chooser_factory_->SendEvent(event, argument); | 933 bluetooth_chooser_factory_->SendEvent(event, argument); |
| 940 } | 934 } |
| 941 | 935 |
| 942 } // namespace content | 936 } // namespace content |
| OLD | NEW |