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

Side by Side Diff: content/shell/renderer/layout_test/blink_test_runner.cc

Issue 1736353002: ABANDONED CL: Shared-memory-based approach to layout tests runtime flags replication. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer/layout_test/blink_test_runner.h" 5 #include "content/shell/renderer/layout_test/blink_test_runner.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <clocale> 9 #include <clocale>
10 #include <cmath> 10 #include <cmath>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/base64.h" 13 #include "base/base64.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/debug/debugger.h" 16 #include "base/debug/debugger.h"
17 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
18 #include "base/location.h" 18 #include "base/location.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/md5.h" 20 #include "base/md5.h"
21 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
22 #include "base/memory/shared_memory.h"
22 #include "base/single_thread_task_runner.h" 23 #include "base/single_thread_task_runner.h"
23 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
25 #include "base/strings/sys_string_conversions.h" 26 #include "base/strings/sys_string_conversions.h"
26 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
27 #include "base/thread_task_runner_handle.h" 28 #include "base/thread_task_runner_handle.h"
28 #include "base/time/time.h" 29 #include "base/time/time.h"
29 #include "build/build_config.h" 30 #include "build/build_config.h"
30 #include "components/plugins/renderer/plugin_placeholder.h" 31 #include "components/plugins/renderer/plugin_placeholder.h"
31 #include "components/test_runner/app_banner_client.h" 32 #include "components/test_runner/app_banner_client.h"
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 } 606 }
606 return RewriteLayoutTestsURL(result).string().utf8(); 607 return RewriteLayoutTestsURL(result).string().utf8();
607 } 608 }
608 609
609 void BlinkTestRunner::SetLocale(const std::string& locale) { 610 void BlinkTestRunner::SetLocale(const std::string& locale) {
610 setlocale(LC_ALL, locale.c_str()); 611 setlocale(LC_ALL, locale.c_str());
611 } 612 }
612 613
613 void BlinkTestRunner::TestFinished() { 614 void BlinkTestRunner::TestFinished() {
614 if (!is_main_window_ || !render_view()->GetMainRenderFrame()) { 615 if (!is_main_window_ || !render_view()->GetMainRenderFrame()) {
616 VLOG(1) << "Test finished in secondary window.";
615 Send(new ShellViewHostMsg_TestFinishedInSecondaryRenderer(routing_id())); 617 Send(new ShellViewHostMsg_TestFinishedInSecondaryRenderer(routing_id()));
616 return; 618 return;
617 } 619 }
620 VLOG(1) << "Test finished.";
621
618 test_runner::WebTestInterfaces* interfaces = 622 test_runner::WebTestInterfaces* interfaces =
619 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces(); 623 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
620 interfaces->SetTestIsRunning(false); 624 interfaces->SetTestIsRunning(false);
621 if (interfaces->TestRunner()->ShouldDumpBackForwardList()) { 625 if (interfaces->TestRunner()->ShouldDumpBackForwardList()) {
622 SyncNavigationStateVisitor visitor; 626 SyncNavigationStateVisitor visitor;
623 RenderView::ForEach(&visitor); 627 RenderView::ForEach(&visitor);
628 VLOG(2) << "Capturing session history dump.";
624 Send(new ShellViewHostMsg_CaptureSessionHistory(routing_id())); 629 Send(new ShellViewHostMsg_CaptureSessionHistory(routing_id()));
625 } else { 630 } else {
626 CaptureDump(); 631 CaptureDump();
627 } 632 }
628 } 633 }
629 634
630 void BlinkTestRunner::CloseRemainingWindows() { 635 void BlinkTestRunner::CloseRemainingWindows() {
631 Send(new ShellViewHostMsg_CloseRemainingWindows(routing_id())); 636 Send(new ShellViewHostMsg_CloseRemainingWindows(routing_id()));
632 } 637 }
633 638
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 else { 706 else {
702 NOTREACHED(); 707 NOTREACHED();
703 status = PermissionStatus::DENIED; 708 status = PermissionStatus::DENIED;
704 } 709 }
705 710
706 Send(new LayoutTestHostMsg_SetPermission( 711 Send(new LayoutTestHostMsg_SetPermission(
707 routing_id(), name, status, origin, embedding_origin)); 712 routing_id(), name, status, origin, embedding_origin));
708 } 713 }
709 714
710 void BlinkTestRunner::ResetPermissions() { 715 void BlinkTestRunner::ResetPermissions() {
711 Send(new LayoutTestHostMsg_ResetPermissions(routing_id())); 716 if (is_main_window_)
717 Send(new LayoutTestHostMsg_ResetPermissions(routing_id()));
712 } 718 }
713 719
714 cc::SharedBitmapManager* BlinkTestRunner::GetSharedBitmapManager() { 720 cc::SharedBitmapManager* BlinkTestRunner::GetSharedBitmapManager() {
715 return RenderThread::Get()->GetSharedBitmapManager(); 721 return RenderThread::Get()->GetSharedBitmapManager();
716 } 722 }
717 723
718 void BlinkTestRunner::DispatchBeforeInstallPromptEvent( 724 void BlinkTestRunner::DispatchBeforeInstallPromptEvent(
719 int request_id, 725 int request_id,
720 const std::vector<std::string>& event_platforms, 726 const std::vector<std::string>& event_platforms,
721 const base::Callback<void(bool)>& callback) { 727 const base::Callback<void(bool)>& callback) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 } 819 }
814 820
815 void BlinkTestRunner::Navigate(const GURL& url) { 821 void BlinkTestRunner::Navigate(const GURL& url) {
816 focus_on_next_commit_ = true; 822 focus_on_next_commit_ = true;
817 if (!is_main_window_ && 823 if (!is_main_window_ &&
818 LayoutTestRenderProcessObserver::GetInstance()->main_test_runner() == 824 LayoutTestRenderProcessObserver::GetInstance()->main_test_runner() ==
819 this) { 825 this) {
820 test_runner::WebTestInterfaces* interfaces = 826 test_runner::WebTestInterfaces* interfaces =
821 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces(); 827 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
822 interfaces->SetTestIsRunning(true); 828 interfaces->SetTestIsRunning(true);
829
830 // Use static / non-shared layout dump flags in secondary windows.
831 static test_runner::LayoutDumpFlags static_layout_dump_flags;
832 interfaces->TestRunner()->SetSharedLayoutDumpFlags(
833 &static_layout_dump_flags);
834
835 interfaces->TestRunner()->Reset();
823 interfaces->ConfigureForTestWithURL(GURL(), false); 836 interfaces->ConfigureForTestWithURL(GURL(), false);
824 ForceResizeRenderView(render_view(), WebSize(800, 600)); 837 ForceResizeRenderView(render_view(), WebSize(800, 600));
825 } 838 }
826 } 839 }
827 840
828 void BlinkTestRunner::DidCommitProvisionalLoad(WebLocalFrame* frame, 841 void BlinkTestRunner::DidCommitProvisionalLoad(WebLocalFrame* frame,
829 bool is_new_navigation) { 842 bool is_new_navigation) {
830 if (!focus_on_next_commit_) 843 if (!focus_on_next_commit_)
831 return; 844 return;
832 focus_on_next_commit_ = false; 845 focus_on_next_commit_ = false;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 // Private methods ----------------------------------------------------------- 881 // Private methods -----------------------------------------------------------
869 882
870 void BlinkTestRunner::CaptureDump() { 883 void BlinkTestRunner::CaptureDump() {
871 test_runner::WebTestInterfaces* interfaces = 884 test_runner::WebTestInterfaces* interfaces =
872 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces(); 885 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
873 TRACE_EVENT0("shell", "BlinkTestRunner::CaptureDump"); 886 TRACE_EVENT0("shell", "BlinkTestRunner::CaptureDump");
874 887
875 if (interfaces->TestRunner()->ShouldDumpAsAudio()) { 888 if (interfaces->TestRunner()->ShouldDumpAsAudio()) {
876 std::vector<unsigned char> vector_data; 889 std::vector<unsigned char> vector_data;
877 interfaces->TestRunner()->GetAudioData(&vector_data); 890 interfaces->TestRunner()->GetAudioData(&vector_data);
891 VLOG(2) << "Sending audio dump.";
878 Send(new ShellViewHostMsg_AudioDump(routing_id(), vector_data)); 892 Send(new ShellViewHostMsg_AudioDump(routing_id(), vector_data));
879 CaptureDumpContinued(); 893 CaptureDumpContinued();
880 return; 894 return;
881 } 895 }
882 896
883 std::string custom_text_dump; 897 std::string custom_text_dump;
884 if (interfaces->TestRunner()->HasCustomTextDump(&custom_text_dump)) { 898 if (interfaces->TestRunner()->HasCustomTextDump(&custom_text_dump)) {
899 VLOG(2) << "Sending custom text dump.";
885 Send(new ShellViewHostMsg_TextDump(routing_id(), custom_text_dump + "\n")); 900 Send(new ShellViewHostMsg_TextDump(routing_id(), custom_text_dump + "\n"));
886 CaptureDumpContinued(); 901 CaptureDumpContinued();
887 return; 902 return;
888 } 903 }
889 904
890 const test_runner::LayoutDumpFlags& layout_dump_flags = 905 const test_runner::LayoutDumpFlags& layout_dump_flags =
891 interfaces->TestRunner()->GetLayoutDumpFlags(); 906 interfaces->TestRunner()->GetLayoutDumpFlags();
892 if (!layout_dump_flags.dump_child_frames()) { 907 if (!layout_dump_flags.dump_child_frames()) {
893 std::string layout_dump = DumpLayout( 908 std::string layout_dump = DumpLayout(
894 render_view()->GetMainRenderFrame()->GetWebFrame(), layout_dump_flags); 909 render_view()->GetMainRenderFrame()->GetWebFrame(), layout_dump_flags);
895 OnLayoutDumpCompleted(layout_dump); 910 OnLayoutDumpCompleted(layout_dump);
896 return; 911 return;
897 } 912 }
898 913
899 Send( 914 Send(new ShellViewHostMsg_InitiateLayoutDump(
900 new ShellViewHostMsg_InitiateLayoutDump(routing_id(), layout_dump_flags)); 915 routing_id(), layout_dump_flags.dump_child_frames()));
901 // OnLayoutDumpCompleted will be eventually called by an IPC from the browser. 916 // OnLayoutDumpCompleted will be eventually called by an IPC from the browser.
902 } 917 }
903 918
904 void BlinkTestRunner::OnLayoutDumpCompleted(std::string completed_layout_dump) { 919 void BlinkTestRunner::OnLayoutDumpCompleted(std::string completed_layout_dump) {
905 test_runner::WebTestInterfaces* interfaces = 920 test_runner::WebTestInterfaces* interfaces =
906 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces(); 921 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
907 if (interfaces->TestRunner()->ShouldDumpBackForwardList()) { 922 if (interfaces->TestRunner()->ShouldDumpBackForwardList()) {
908 completed_layout_dump.append(proxy()->DumpBackForwardLists()); 923 completed_layout_dump.append(proxy()->DumpBackForwardLists());
909 } 924 }
910 925
926 VLOG(2) << "Sending layout dump.";
911 Send(new ShellViewHostMsg_TextDump(routing_id(), completed_layout_dump)); 927 Send(new ShellViewHostMsg_TextDump(routing_id(), completed_layout_dump));
912 928
913 CaptureDumpContinued(); 929 CaptureDumpContinued();
914 } 930 }
915 931
916 void BlinkTestRunner::CaptureDumpContinued() { 932 void BlinkTestRunner::CaptureDumpContinued() {
917 test_runner::WebTestInterfaces* interfaces = 933 test_runner::WebTestInterfaces* interfaces =
918 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces(); 934 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
919 if (test_config_.enable_pixel_dumping && 935 if (test_config_.enable_pixel_dumping &&
920 interfaces->TestRunner()->ShouldGeneratePixelResults() && 936 interfaces->TestRunner()->ShouldGeneratePixelResults() &&
(...skipping 20 matching lines...) Expand all
941 957
942 SkAutoLockPixels snapshot_lock(snapshot); 958 SkAutoLockPixels snapshot_lock(snapshot);
943 // The snapshot arrives from the GPU process via shared memory. Because MSan 959 // The snapshot arrives from the GPU process via shared memory. Because MSan
944 // can't track initializedness across processes, we must assure it that the 960 // can't track initializedness across processes, we must assure it that the
945 // pixels are in fact initialized. 961 // pixels are in fact initialized.
946 MSAN_UNPOISON(snapshot.getPixels(), snapshot.getSize()); 962 MSAN_UNPOISON(snapshot.getPixels(), snapshot.getSize());
947 base::MD5Digest digest; 963 base::MD5Digest digest;
948 base::MD5Sum(snapshot.getPixels(), snapshot.getSize(), &digest); 964 base::MD5Sum(snapshot.getPixels(), snapshot.getSize(), &digest);
949 std::string actual_pixel_hash = base::MD5DigestToBase16(digest); 965 std::string actual_pixel_hash = base::MD5DigestToBase16(digest);
950 966
967 VLOG(2) << "Sending pixel dump.";
951 if (actual_pixel_hash == test_config_.expected_pixel_hash) { 968 if (actual_pixel_hash == test_config_.expected_pixel_hash) {
952 SkBitmap empty_image; 969 SkBitmap empty_image;
953 Send(new ShellViewHostMsg_ImageDump( 970 Send(new ShellViewHostMsg_ImageDump(
954 routing_id(), actual_pixel_hash, empty_image)); 971 routing_id(), actual_pixel_hash, empty_image));
955 } else { 972 } else {
956 Send(new ShellViewHostMsg_ImageDump( 973 Send(new ShellViewHostMsg_ImageDump(
957 routing_id(), actual_pixel_hash, snapshot)); 974 routing_id(), actual_pixel_hash, snapshot));
958 } 975 }
959 976
960 CaptureDumpComplete(); 977 CaptureDumpComplete();
961 } 978 }
962 979
963 void BlinkTestRunner::CaptureDumpComplete() { 980 void BlinkTestRunner::CaptureDumpComplete() {
964 render_view()->GetWebView()->mainFrame()->stopLoading(); 981 render_view()->GetWebView()->mainFrame()->stopLoading();
965 982
983 VLOG(1) << "Dump completed.";
984
966 base::ThreadTaskRunnerHandle::Get()->PostTask( 985 base::ThreadTaskRunnerHandle::Get()->PostTask(
967 FROM_HERE, base::Bind(base::IgnoreResult(&BlinkTestRunner::Send), 986 FROM_HERE, base::Bind(base::IgnoreResult(&BlinkTestRunner::Send),
968 base::Unretained(this), 987 base::Unretained(this),
969 new ShellViewHostMsg_TestFinished(routing_id()))); 988 new ShellViewHostMsg_TestFinished(routing_id())));
970 } 989 }
971 990
972 void BlinkTestRunner::OnReplicateTestConfiguration( 991 void BlinkTestRunner::OnReplicateTestConfiguration(
973 const ShellTestConfiguration& params) { 992 const ShellTestConfiguration& params) {
993 VLOG(2) << "Replicating test configuration.";
994
974 test_config_ = params; 995 test_config_ = params;
975 is_main_window_ = true; 996 is_main_window_ = true;
976 997
998 layout_dump_flags_memory_.reset(
999 new base::SharedMemory(test_config_.layout_dump_flags_memory_handle,
1000 false /* expecting read-write memory */));
1001 if (!layout_dump_flags_memory_->Map(sizeof(test_runner::LayoutDumpFlags))) {
1002 // TODO(lukasza): DO NOT SUBMIT: Report the error somehow?
1003 CHECK(false);
1004 }
1005 DCHECK(layout_dump_flags_memory_->memory());
1006
977 test_runner::WebTestInterfaces* interfaces = 1007 test_runner::WebTestInterfaces* interfaces =
978 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces(); 1008 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
1009 interfaces->TestRunner()->SetSharedLayoutDumpFlags(
1010 static_cast<test_runner::LayoutDumpFlags*>(
1011 layout_dump_flags_memory_->memory()));
979 interfaces->SetTestIsRunning(true); 1012 interfaces->SetTestIsRunning(true);
980 interfaces->ConfigureForTestWithURL(params.test_url,
981 params.enable_pixel_dumping);
982 } 1013 }
983 1014
984 void BlinkTestRunner::OnSetTestConfiguration( 1015 void BlinkTestRunner::OnSetTestConfiguration(
985 const ShellTestConfiguration& params) { 1016 const ShellTestConfiguration& params) {
1017 VLOG(1) << "Setting initial test configuration.";
1018
986 OnReplicateTestConfiguration(params); 1019 OnReplicateTestConfiguration(params);
987 1020
1021 test_runner::WebTestInterfaces* interfaces =
1022 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
1023 interfaces->TestRunner()->Reset();
1024 interfaces->ConfigureForTestWithURL(params.test_url,
1025 params.enable_pixel_dumping);
1026
988 ForceResizeRenderView( 1027 ForceResizeRenderView(
989 render_view(), 1028 render_view(),
990 WebSize(params.initial_size.width(), params.initial_size.height())); 1029 WebSize(params.initial_size.width(), params.initial_size.height()));
991 SetFocus(proxy_, true); 1030 SetFocus(proxy_, true);
992 } 1031 }
993 1032
994 void BlinkTestRunner::OnSessionHistory( 1033 void BlinkTestRunner::OnSessionHistory(
995 const std::vector<int>& routing_ids, 1034 const std::vector<int>& routing_ids,
996 const std::vector<std::vector<PageState>>& session_histories, 1035 const std::vector<std::vector<PageState>>& session_histories,
997 const std::vector<unsigned>& current_entry_indexes) { 1036 const std::vector<unsigned>& current_entry_indexes) {
998 routing_ids_ = routing_ids; 1037 routing_ids_ = routing_ids;
999 session_histories_ = session_histories; 1038 session_histories_ = session_histories;
1000 current_entry_indexes_ = current_entry_indexes; 1039 current_entry_indexes_ = current_entry_indexes;
1001 CaptureDump(); 1040 CaptureDump();
1002 } 1041 }
1003 1042
1004 void BlinkTestRunner::OnReset() { 1043 void BlinkTestRunner::OnReset() {
1005 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces()->ResetAll(); 1044 test_runner::WebTestInterfaces* interfaces =
1045 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
1046 interfaces->ResetAll();
1047 interfaces->TestRunner()->Reset();
1048
1006 Reset(true /* for_new_test */); 1049 Reset(true /* for_new_test */);
1007 // Navigating to about:blank will make sure that no new loads are initiated 1050 // Navigating to about:blank will make sure that no new loads are initiated
1008 // by the renderer. 1051 // by the renderer.
1009 render_view()->GetWebView()->mainFrame()->loadRequest( 1052 render_view()->GetWebView()->mainFrame()->loadRequest(
1010 WebURLRequest(GURL(url::kAboutBlankURL))); 1053 WebURLRequest(GURL(url::kAboutBlankURL)));
1011 Send(new ShellViewHostMsg_ResetDone(routing_id())); 1054 Send(new ShellViewHostMsg_ResetDone(routing_id()));
1012 } 1055 }
1013 1056
1014 void BlinkTestRunner::OnNotifyDone() { 1057 void BlinkTestRunner::OnNotifyDone() {
1015 render_view()->GetWebView()->mainFrame()->executeScript( 1058 render_view()->GetWebView()->mainFrame()->executeScript(
(...skipping 17 matching lines...) Expand all
1033 get_bluetooth_events_callbacks_.pop_front(); 1076 get_bluetooth_events_callbacks_.pop_front();
1034 callback.Run(events); 1077 callback.Run(events);
1035 } 1078 }
1036 1079
1037 void BlinkTestRunner::ReportLeakDetectionResult( 1080 void BlinkTestRunner::ReportLeakDetectionResult(
1038 const LeakDetectionResult& report) { 1081 const LeakDetectionResult& report) {
1039 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report)); 1082 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report));
1040 } 1083 }
1041 1084
1042 } // namespace content 1085 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698