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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 bool BlinkTestController::OnMessageReceived(const IPC::Message& message) { | 485 bool BlinkTestController::OnMessageReceived(const IPC::Message& message) { |
486 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 486 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
487 bool handled = true; | 487 bool handled = true; |
488 IPC_BEGIN_MESSAGE_MAP(BlinkTestController, message) | 488 IPC_BEGIN_MESSAGE_MAP(BlinkTestController, message) |
489 IPC_MESSAGE_HANDLER(ShellViewHostMsg_PrintMessage, OnPrintMessage) | 489 IPC_MESSAGE_HANDLER(ShellViewHostMsg_PrintMessage, OnPrintMessage) |
490 IPC_MESSAGE_HANDLER(ShellViewHostMsg_PrintMessageToStderr, | 490 IPC_MESSAGE_HANDLER(ShellViewHostMsg_PrintMessageToStderr, |
491 OnPrintMessageToStderr) | 491 OnPrintMessageToStderr) |
492 IPC_MESSAGE_HANDLER(ShellViewHostMsg_TextDump, OnTextDump) | 492 IPC_MESSAGE_HANDLER(ShellViewHostMsg_TextDump, OnTextDump) |
493 IPC_MESSAGE_HANDLER(ShellViewHostMsg_InitiateLayoutDump, | 493 IPC_MESSAGE_HANDLER(ShellViewHostMsg_InitiateLayoutDump, |
494 OnInitiateLayoutDump) | 494 OnInitiateLayoutDump) |
| 495 IPC_MESSAGE_HANDLER(ShellViewHostMsg_InitiatePixelsDump, |
| 496 OnInitiatePixelsDump) |
495 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ImageDump, OnImageDump) | 497 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ImageDump, OnImageDump) |
496 IPC_MESSAGE_HANDLER(ShellViewHostMsg_AudioDump, OnAudioDump) | 498 IPC_MESSAGE_HANDLER(ShellViewHostMsg_AudioDump, OnAudioDump) |
497 IPC_MESSAGE_HANDLER(ShellViewHostMsg_OverridePreferences, | 499 IPC_MESSAGE_HANDLER(ShellViewHostMsg_OverridePreferences, |
498 OnOverridePreferences) | 500 OnOverridePreferences) |
499 IPC_MESSAGE_HANDLER(ShellViewHostMsg_SetPopupBlockingEnabled, | 501 IPC_MESSAGE_HANDLER(ShellViewHostMsg_SetPopupBlockingEnabled, |
500 OnSetPopupBlockingEnabled) | 502 OnSetPopupBlockingEnabled) |
501 IPC_MESSAGE_HANDLER(ShellViewHostMsg_TestFinished, OnTestFinished) | 503 IPC_MESSAGE_HANDLER(ShellViewHostMsg_TestFinished, OnTestFinished) |
502 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ClearDevToolsLocalStorage, | 504 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ClearDevToolsLocalStorage, |
503 OnClearDevToolsLocalStorage) | 505 OnClearDevToolsLocalStorage) |
504 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ShowDevTools, OnShowDevTools) | 506 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ShowDevTools, OnShowDevTools) |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 | 781 |
780 ++number_of_messages; | 782 ++number_of_messages; |
781 GetLayoutTestControlPtr(rfh)->DumpFrameLayout( | 783 GetLayoutTestControlPtr(rfh)->DumpFrameLayout( |
782 base::Bind(&BlinkTestController::OnDumpFrameLayoutResponse, | 784 base::Bind(&BlinkTestController::OnDumpFrameLayoutResponse, |
783 base::Unretained(this), rfh->GetFrameTreeNodeId())); | 785 base::Unretained(this), rfh->GetFrameTreeNodeId())); |
784 } | 786 } |
785 | 787 |
786 pending_layout_dumps_ = number_of_messages; | 788 pending_layout_dumps_ = number_of_messages; |
787 } | 789 } |
788 | 790 |
| 791 void BlinkTestController::OnInitiatePixelsDump() { |
| 792 // DO NOT SUBMIT - remove ad-hoc logs. |
| 793 LOG(ERROR) << "OnInitiatePixelsDump"; |
| 794 composited_frames_.clear(); |
| 795 TriggerCompositingIfAllChildrenHaveBeenComposited(); |
| 796 } |
| 797 |
| 798 void BlinkTestController::TriggerCompositingIfAllChildrenHaveBeenComposited() { |
| 799 for (RenderFrameHost* rfh : main_window_->web_contents()->GetAllFrames()) { |
| 800 // Skip the frame if it already was composited. |
| 801 if (0 != composited_frames_.count(rfh->GetFrameTreeNodeId())) |
| 802 continue; |
| 803 |
| 804 // Ignore non-live frames / pretend that they are ready for a pixel dump. |
| 805 if (!rfh->IsRenderFrameLive()) { |
| 806 composited_frames_.insert(rfh->GetFrameTreeNodeId()); |
| 807 continue; |
| 808 } |
| 809 |
| 810 // Check if all child frames of |rfh| have been composited. |
| 811 bool are_all_children_composited = true; |
| 812 for (RenderFrameHost* child : |
| 813 main_window_->web_contents()->GetAllFrames()) { |
| 814 if (child->GetParent() != rfh) |
| 815 continue; |
| 816 if (0 == composited_frames_.count(child->GetFrameTreeNodeId())) { |
| 817 are_all_children_composited = false; |
| 818 break; |
| 819 } |
| 820 } |
| 821 if (!are_all_children_composited) |
| 822 continue; |
| 823 |
| 824 // At this point we know that |rfh| is ready for compositing. |
| 825 TriggerCompositing(rfh); |
| 826 } |
| 827 } |
| 828 |
| 829 void BlinkTestController::TriggerCompositing(RenderFrameHost* frame) { |
| 830 LOG(ERROR) << "TriggerCompositing" |
| 831 << "; frame->GetLastCommittedURL() = " |
| 832 << frame->GetLastCommittedURL(); |
| 833 |
| 834 GetLayoutTestControlPtr(frame)->TriggerCompositing( |
| 835 base::Bind(&BlinkTestController::OnTriggerCompositingResponse, |
| 836 base::Unretained(this), frame->GetFrameTreeNodeId(), |
| 837 frame->GetProcess()->GetID())); |
| 838 } |
| 839 |
| 840 void BlinkTestController::OnTriggerCompositingResponse( |
| 841 int frame_tree_node_id, |
| 842 // DO NOT SUBMIT - use |process_id|? |
| 843 int process_id) { |
| 844 LOG(ERROR) << "OnTriggerCompositingResponse"; |
| 845 composited_frames_.insert(frame_tree_node_id); |
| 846 |
| 847 if (0 == |
| 848 composited_frames_.count( |
| 849 main_window_->web_contents()->GetMainFrame()->GetFrameTreeNodeId())) { |
| 850 TriggerCompositingIfAllChildrenHaveBeenComposited(); |
| 851 return; |
| 852 } |
| 853 |
| 854 LOG(ERROR) << "OnTriggerCompositingResponse - all frames were composited"; |
| 855 main_window_->web_contents()->GetRenderWidgetHostView()->CopyFromSurface( |
| 856 gfx::Rect(), gfx::Size(), |
| 857 base::Bind(&BlinkTestController::OnPixelsDumpCaptured, |
| 858 base::Unretained(this)), |
| 859 kN32_SkColorType); |
| 860 } |
| 861 |
789 void BlinkTestController::OnLayoutTestRuntimeFlagsChanged( | 862 void BlinkTestController::OnLayoutTestRuntimeFlagsChanged( |
790 int sender_process_host_id, | 863 int sender_process_host_id, |
791 const base::DictionaryValue& changed_layout_test_runtime_flags) { | 864 const base::DictionaryValue& changed_layout_test_runtime_flags) { |
792 // Stash the accumulated changes for future, not-yet-created renderers. | 865 // Stash the accumulated changes for future, not-yet-created renderers. |
793 accumulated_layout_test_runtime_flags_changes_.MergeDictionary( | 866 accumulated_layout_test_runtime_flags_changes_.MergeDictionary( |
794 &changed_layout_test_runtime_flags); | 867 &changed_layout_test_runtime_flags); |
795 | 868 |
796 // Propagate the changes to all the tracked renderer processes. | 869 // Propagate the changes to all the tracked renderer processes. |
797 for (RenderProcessHost* process : all_observed_render_process_hosts_) { | 870 for (RenderProcessHost* process : all_observed_render_process_hosts_) { |
798 // Do not propagate the changes back to the process that originated them. | 871 // Do not propagate the changes back to the process that originated them. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 } | 904 } |
832 } | 905 } |
833 | 906 |
834 // Continue finishing the test. | 907 // Continue finishing the test. |
835 RenderViewHost* render_view_host = | 908 RenderViewHost* render_view_host = |
836 main_window_->web_contents()->GetRenderViewHost(); | 909 main_window_->web_contents()->GetRenderViewHost(); |
837 render_view_host->Send(new ShellViewMsg_LayoutDumpCompleted( | 910 render_view_host->Send(new ShellViewMsg_LayoutDumpCompleted( |
838 render_view_host->GetRoutingID(), stitched_layout_dump)); | 911 render_view_host->GetRoutingID(), stitched_layout_dump)); |
839 } | 912 } |
840 | 913 |
| 914 void BlinkTestController::OnPixelsDumpCaptured(const SkBitmap& dump, |
| 915 ReadbackResponse response) { |
| 916 DCHECK_EQ(READBACK_SUCCESS, response); |
| 917 RenderViewHost* render_view_host = |
| 918 main_window_->web_contents()->GetRenderViewHost(); |
| 919 render_view_host->Send(new ShellViewMsg_PixelsDumpResult( |
| 920 render_view_host->GetRoutingID(), dump)); |
| 921 } |
| 922 |
841 void BlinkTestController::OnPrintMessage(const std::string& message) { | 923 void BlinkTestController::OnPrintMessage(const std::string& message) { |
842 printer_->AddMessageRaw(message); | 924 printer_->AddMessageRaw(message); |
843 } | 925 } |
844 | 926 |
845 void BlinkTestController::OnPrintMessageToStderr(const std::string& message) { | 927 void BlinkTestController::OnPrintMessageToStderr(const std::string& message) { |
846 printer_->AddMessageToStderr(message); | 928 printer_->AddMessageToStderr(message); |
847 } | 929 } |
848 | 930 |
849 void BlinkTestController::OnOverridePreferences(const WebPreferences& prefs) { | 931 void BlinkTestController::OnOverridePreferences(const WebPreferences& prefs) { |
850 should_override_prefs_ = true; | 932 should_override_prefs_ = true; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 } | 1127 } |
1046 DCHECK(layout_test_control_map_[frame].get()); | 1128 DCHECK(layout_test_control_map_[frame].get()); |
1047 return layout_test_control_map_[frame].get(); | 1129 return layout_test_control_map_[frame].get(); |
1048 } | 1130 } |
1049 | 1131 |
1050 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { | 1132 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { |
1051 layout_test_control_map_.erase(frame); | 1133 layout_test_control_map_.erase(frame); |
1052 } | 1134 } |
1053 | 1135 |
1054 } // namespace content | 1136 } // namespace content |
OLD | NEW |