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

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

Issue 2594913002: Replace IPC messages in layout_test_render_frame_observer. (Closed)
Patch Set: Replace const ref by value Created 3 years, 10 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 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <clocale> 10 #include <clocale>
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 return base::TimeDelta(base::Time::Now() - 325 return base::TimeDelta(base::Time::Now() -
326 base::Time::UnixEpoch()).ToInternalValue() / 326 base::Time::UnixEpoch()).ToInternalValue() /
327 base::Time::kMicrosecondsPerMillisecond; 327 base::Time::kMicrosecondsPerMillisecond;
328 } 328 }
329 329
330 WebString BlinkTestRunner::GetAbsoluteWebStringFromUTF8Path( 330 WebString BlinkTestRunner::GetAbsoluteWebStringFromUTF8Path(
331 const std::string& utf8_path) { 331 const std::string& utf8_path) {
332 base::FilePath path = base::FilePath::FromUTF8Unsafe(utf8_path); 332 base::FilePath path = base::FilePath::FromUTF8Unsafe(utf8_path);
333 if (!path.IsAbsolute()) { 333 if (!path.IsAbsolute()) {
334 GURL base_url = 334 GURL base_url =
335 net::FilePathToFileURL(test_config_.current_working_directory.Append( 335 net::FilePathToFileURL(test_config_->current_working_directory.Append(
336 FILE_PATH_LITERAL("foo"))); 336 FILE_PATH_LITERAL("foo")));
337 net::FileURLToFilePath(base_url.Resolve(utf8_path), &path); 337 net::FileURLToFilePath(base_url.Resolve(utf8_path), &path);
338 } 338 }
339 return blink::FilePathToWebString(path); 339 return blink::FilePathToWebString(path);
340 } 340 }
341 341
342 WebURL BlinkTestRunner::LocalFileToDataURL(const WebURL& file_url) { 342 WebURL BlinkTestRunner::LocalFileToDataURL(const WebURL& file_url) {
343 base::FilePath local_path; 343 base::FilePath local_path;
344 if (!net::FileURLToFilePath(file_url, &local_path)) 344 if (!net::FileURLToFilePath(file_url, &local_path))
345 return WebURL(); 345 return WebURL();
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 } 556 }
557 557
558 void BlinkTestRunner::SetBlockThirdPartyCookies(bool block) { 558 void BlinkTestRunner::SetBlockThirdPartyCookies(bool block) {
559 Send(new LayoutTestHostMsg_BlockThirdPartyCookies(routing_id(), block)); 559 Send(new LayoutTestHostMsg_BlockThirdPartyCookies(routing_id(), block));
560 } 560 }
561 561
562 std::string BlinkTestRunner::PathToLocalResource(const std::string& resource) { 562 std::string BlinkTestRunner::PathToLocalResource(const std::string& resource) {
563 #if defined(OS_WIN) 563 #if defined(OS_WIN)
564 if (base::StartsWith(resource, "/tmp/", base::CompareCase::SENSITIVE)) { 564 if (base::StartsWith(resource, "/tmp/", base::CompareCase::SENSITIVE)) {
565 // We want a temp file. 565 // We want a temp file.
566 GURL base_url = net::FilePathToFileURL(test_config_.temp_path); 566 GURL base_url = net::FilePathToFileURL(test_config_->temp_path);
567 return base_url.Resolve(resource.substr(sizeof("/tmp/") - 1)).spec(); 567 return base_url.Resolve(resource.substr(sizeof("/tmp/") - 1)).spec();
568 } 568 }
569 #endif 569 #endif
570 570
571 // Some layout tests use file://// which we resolve as a UNC path. Normalize 571 // Some layout tests use file://// which we resolve as a UNC path. Normalize
572 // them to just file:///. 572 // them to just file:///.
573 std::string result = resource; 573 std::string result = resource;
574 static const size_t kFileLen = sizeof("file:///") - 1; 574 static const size_t kFileLen = sizeof("file:///") - 1;
575 while (base::StartsWith(base::ToLowerASCII(result), "file:////", 575 while (base::StartsWith(base::ToLowerASCII(result), "file:////",
576 base::CompareCase::SENSITIVE)) { 576 base::CompareCase::SENSITIVE)) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 Send(new ShellViewHostMsg_Reload(routing_id())); 636 Send(new ShellViewHostMsg_Reload(routing_id()));
637 } 637 }
638 638
639 void BlinkTestRunner::LoadURLForFrame(const WebURL& url, 639 void BlinkTestRunner::LoadURLForFrame(const WebURL& url,
640 const std::string& frame_name) { 640 const std::string& frame_name) {
641 Send(new ShellViewHostMsg_LoadURLForFrame( 641 Send(new ShellViewHostMsg_LoadURLForFrame(
642 routing_id(), url, frame_name)); 642 routing_id(), url, frame_name));
643 } 643 }
644 644
645 bool BlinkTestRunner::AllowExternalPages() { 645 bool BlinkTestRunner::AllowExternalPages() {
646 return test_config_.allow_external_pages; 646 return test_config_->allow_external_pages;
647 } 647 }
648 648
649 std::string BlinkTestRunner::DumpHistoryForWindow(blink::WebView* web_view) { 649 std::string BlinkTestRunner::DumpHistoryForWindow(blink::WebView* web_view) {
650 size_t pos = 0; 650 size_t pos = 0;
651 std::vector<int>::iterator id; 651 std::vector<int>::iterator id;
652 for (id = routing_ids_.begin(); id != routing_ids_.end(); ++id, ++pos) { 652 for (id = routing_ids_.begin(); id != routing_ids_.end(); ++id, ++pos) {
653 RenderView* render_view = RenderView::FromRoutingID(*id); 653 RenderView* render_view = RenderView::FromRoutingID(*id);
654 if (!render_view) { 654 if (!render_view) {
655 NOTREACHED(); 655 NOTREACHED();
656 continue; 656 continue;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 884
885 Send(new ShellViewHostMsg_TextDump(routing_id(), 885 Send(new ShellViewHostMsg_TextDump(routing_id(),
886 std::move(completed_layout_dump))); 886 std::move(completed_layout_dump)));
887 887
888 CaptureDumpContinued(); 888 CaptureDumpContinued();
889 } 889 }
890 890
891 void BlinkTestRunner::CaptureDumpContinued() { 891 void BlinkTestRunner::CaptureDumpContinued() {
892 test_runner::WebTestInterfaces* interfaces = 892 test_runner::WebTestInterfaces* interfaces =
893 LayoutTestRenderThreadObserver::GetInstance()->test_interfaces(); 893 LayoutTestRenderThreadObserver::GetInstance()->test_interfaces();
894 if (test_config_.enable_pixel_dumping && 894 if (test_config_->enable_pixel_dumping &&
895 interfaces->TestRunner()->ShouldGeneratePixelResults() && 895 interfaces->TestRunner()->ShouldGeneratePixelResults() &&
896 !interfaces->TestRunner()->ShouldDumpAsAudio()) { 896 !interfaces->TestRunner()->ShouldDumpAsAudio()) {
897 CHECK(render_view()->GetWebView()->isAcceleratedCompositingActive()); 897 CHECK(render_view()->GetWebView()->isAcceleratedCompositingActive());
898 interfaces->TestRunner()->DumpPixelsAsync( 898 interfaces->TestRunner()->DumpPixelsAsync(
899 render_view()->GetWebView(), 899 render_view()->GetWebView(),
900 base::Bind(&BlinkTestRunner::OnPixelsDumpCompleted, 900 base::Bind(&BlinkTestRunner::OnPixelsDumpCompleted,
901 base::Unretained(this))); 901 base::Unretained(this)));
902 return; 902 return;
903 } 903 }
904 904
905 CaptureDumpComplete(); 905 CaptureDumpComplete();
906 } 906 }
907 907
908 void BlinkTestRunner::OnPixelsDumpCompleted(const SkBitmap& snapshot) { 908 void BlinkTestRunner::OnPixelsDumpCompleted(const SkBitmap& snapshot) {
909 DCHECK_NE(0, snapshot.info().width()); 909 DCHECK_NE(0, snapshot.info().width());
910 DCHECK_NE(0, snapshot.info().height()); 910 DCHECK_NE(0, snapshot.info().height());
911 911
912 SkAutoLockPixels snapshot_lock(snapshot); 912 SkAutoLockPixels snapshot_lock(snapshot);
913 // The snapshot arrives from the GPU process via shared memory. Because MSan 913 // The snapshot arrives from the GPU process via shared memory. Because MSan
914 // can't track initializedness across processes, we must assure it that the 914 // can't track initializedness across processes, we must assure it that the
915 // pixels are in fact initialized. 915 // pixels are in fact initialized.
916 MSAN_UNPOISON(snapshot.getPixels(), snapshot.getSize()); 916 MSAN_UNPOISON(snapshot.getPixels(), snapshot.getSize());
917 base::MD5Digest digest; 917 base::MD5Digest digest;
918 base::MD5Sum(snapshot.getPixels(), snapshot.getSize(), &digest); 918 base::MD5Sum(snapshot.getPixels(), snapshot.getSize(), &digest);
919 std::string actual_pixel_hash = base::MD5DigestToBase16(digest); 919 std::string actual_pixel_hash = base::MD5DigestToBase16(digest);
920 920
921 if (actual_pixel_hash == test_config_.expected_pixel_hash) { 921 if (actual_pixel_hash == test_config_->expected_pixel_hash) {
922 SkBitmap empty_image; 922 SkBitmap empty_image;
923 Send(new ShellViewHostMsg_ImageDump( 923 Send(new ShellViewHostMsg_ImageDump(
924 routing_id(), actual_pixel_hash, empty_image)); 924 routing_id(), actual_pixel_hash, empty_image));
925 } else { 925 } else {
926 Send(new ShellViewHostMsg_ImageDump( 926 Send(new ShellViewHostMsg_ImageDump(
927 routing_id(), actual_pixel_hash, snapshot)); 927 routing_id(), actual_pixel_hash, snapshot));
928 } 928 }
929 929
930 CaptureDumpComplete(); 930 CaptureDumpComplete();
931 } 931 }
(...skipping 17 matching lines...) Expand all
949 DCHECK(!is_main_window_); 949 DCHECK(!is_main_window_);
950 950
951 test_runner::WebTestInterfaces* interfaces = 951 test_runner::WebTestInterfaces* interfaces =
952 LayoutTestRenderThreadObserver::GetInstance()->test_interfaces(); 952 LayoutTestRenderThreadObserver::GetInstance()->test_interfaces();
953 interfaces->SetTestIsRunning(true); 953 interfaces->SetTestIsRunning(true);
954 interfaces->ConfigureForTestWithURL(GURL(), false); 954 interfaces->ConfigureForTestWithURL(GURL(), false);
955 ForceResizeRenderView(render_view(), WebSize(800, 600)); 955 ForceResizeRenderView(render_view(), WebSize(800, 600));
956 } 956 }
957 957
958 void BlinkTestRunner::OnReplicateTestConfiguration( 958 void BlinkTestRunner::OnReplicateTestConfiguration(
959 const ShellTestConfiguration& params) { 959 mojom::ShellTestConfigurationPtr params) {
960 test_runner::WebTestInterfaces* interfaces = 960 test_runner::WebTestInterfaces* interfaces =
961 LayoutTestRenderThreadObserver::GetInstance()->test_interfaces(); 961 LayoutTestRenderThreadObserver::GetInstance()->test_interfaces();
962 962
963 test_config_ = params; 963 test_config_ = params.Clone();
964 964
965 is_main_window_ = true; 965 is_main_window_ = true;
966 interfaces->SetMainView(render_view()->GetWebView()); 966 interfaces->SetMainView(render_view()->GetWebView());
967 967
968 interfaces->SetTestIsRunning(true); 968 interfaces->SetTestIsRunning(true);
969 interfaces->ConfigureForTestWithURL(params.test_url, 969 interfaces->ConfigureForTestWithURL(params->test_url,
970 params.enable_pixel_dumping); 970 params->enable_pixel_dumping);
971 } 971 }
972 972
973 void BlinkTestRunner::OnSetTestConfiguration( 973 void BlinkTestRunner::OnSetTestConfiguration(
974 const ShellTestConfiguration& params) { 974 mojom::ShellTestConfigurationPtr params) {
975 OnReplicateTestConfiguration(params); 975 mojom::ShellTestConfigurationPtr local_params = params.Clone();
Sam McNally 2017/01/29 23:22:14 You only need to keep a local copy of params->init
Jia 2017/01/29 23:26:39 Thanks Sam. As the clone op isn't expensive, I'd l
976 OnReplicateTestConfiguration(std::move(params));
976 977
977 ForceResizeRenderView( 978 ForceResizeRenderView(render_view(),
978 render_view(), 979 WebSize(local_params->initial_size.width(),
979 WebSize(params.initial_size.width(), params.initial_size.height())); 980 local_params->initial_size.height()));
980 LayoutTestRenderThreadObserver::GetInstance() 981 LayoutTestRenderThreadObserver::GetInstance()
981 ->test_interfaces() 982 ->test_interfaces()
982 ->TestRunner() 983 ->TestRunner()
983 ->SetFocus(render_view()->GetWebView(), true); 984 ->SetFocus(render_view()->GetWebView(), true);
984 } 985 }
985 986
986 void BlinkTestRunner::OnSessionHistory( 987 void BlinkTestRunner::OnSessionHistory(
987 const std::vector<int>& routing_ids, 988 const std::vector<int>& routing_ids,
988 const std::vector<std::vector<PageState>>& session_histories, 989 const std::vector<std::vector<PageState>>& session_histories,
989 const std::vector<unsigned>& current_entry_indexes) { 990 const std::vector<unsigned>& current_entry_indexes) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 void BlinkTestRunner::ReportLeakDetectionResult( 1030 void BlinkTestRunner::ReportLeakDetectionResult(
1030 const LeakDetectionResult& report) { 1031 const LeakDetectionResult& report) {
1031 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report)); 1032 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report));
1032 } 1033 }
1033 1034
1034 void BlinkTestRunner::OnDestruct() { 1035 void BlinkTestRunner::OnDestruct() {
1035 delete this; 1036 delete this;
1036 } 1037 }
1037 1038
1038 } // namespace content 1039 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698