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

Side by Side Diff: components/test_runner/web_view_test_client.cc

Issue 2707183003: Move //components/test_runner back into //content/shell (Closed)
Patch Set: Trim DEPS 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/test_runner/web_view_test_client.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/i18n/rtl.h"
10 #include "base/strings/string16.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h"
13 #include "components/test_runner/event_sender.h"
14 #include "components/test_runner/mock_web_speech_recognizer.h"
15 #include "components/test_runner/test_common.h"
16 #include "components/test_runner/test_interfaces.h"
17 #include "components/test_runner/test_runner.h"
18 #include "components/test_runner/test_runner_for_specific_view.h"
19 #include "components/test_runner/web_test_delegate.h"
20 #include "components/test_runner/web_view_test_proxy.h"
21 #include "components/test_runner/web_widget_test_proxy.h"
22 #include "third_party/WebKit/public/platform/WebURLRequest.h"
23 #include "third_party/WebKit/public/web/WebFrame.h"
24 #include "third_party/WebKit/public/web/WebLocalFrame.h"
25 #include "third_party/WebKit/public/web/WebPagePopup.h"
26 #include "third_party/WebKit/public/web/WebPrintParams.h"
27 #include "third_party/WebKit/public/web/WebView.h"
28 #include "third_party/WebKit/public/web/WebWidget.h"
29
30 namespace test_runner {
31
32 WebViewTestClient::WebViewTestClient(
33 WebViewTestProxyBase* web_view_test_proxy_base)
34 : web_view_test_proxy_base_(web_view_test_proxy_base) {
35 DCHECK(web_view_test_proxy_base);
36 }
37
38 WebViewTestClient::~WebViewTestClient() {}
39
40 // The output from these methods in layout test mode should match that
41 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree.
42
43 void WebViewTestClient::didChangeContents() {
44 if (test_runner()->shouldDumpEditingCallbacks())
45 delegate()->PrintMessage(
46 "EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n");
47 }
48
49 blink::WebView* WebViewTestClient::createView(
50 blink::WebLocalFrame* frame,
51 const blink::WebURLRequest& request,
52 const blink::WebWindowFeatures& features,
53 const blink::WebString& frame_name,
54 blink::WebNavigationPolicy policy,
55 bool suppress_opener) {
56 if (test_runner()->shouldDumpNavigationPolicy()) {
57 delegate()->PrintMessage("Default policy for createView for '" +
58 URLDescription(request.url()) + "' is '" +
59 WebNavigationPolicyToString(policy) + "'\n");
60 }
61
62 if (!test_runner()->canOpenWindows())
63 return nullptr;
64 if (test_runner()->shouldDumpCreateView())
65 delegate()->PrintMessage(std::string("createView(") +
66 URLDescription(request.url()) + ")\n");
67
68 // The return value below is used to communicate to WebViewTestProxy whether
69 // it should forward the createView request to RenderViewImpl or not. The
70 // somewhat ugly cast is used to do this while fitting into the existing
71 // WebViewClient interface.
72 return reinterpret_cast<blink::WebView*>(0xdeadbeef);
73 }
74
75 void WebViewTestClient::setStatusText(const blink::WebString& text) {
76 if (!test_runner()->shouldDumpStatusCallbacks())
77 return;
78 delegate()->PrintMessage(
79 std::string("UI DELEGATE STATUS CALLBACK: setStatusText:") +
80 text.utf8().data() + "\n");
81 }
82
83 // Simulate a print by going into print mode and then exit straight away.
84 void WebViewTestClient::printPage(blink::WebLocalFrame* frame) {
85 blink::WebSize page_size_in_pixels = frame->view()->size();
86 if (page_size_in_pixels.isEmpty())
87 return;
88 blink::WebPrintParams printParams(page_size_in_pixels);
89 frame->printBegin(printParams);
90 frame->printEnd();
91 }
92
93 void WebViewTestClient::showValidationMessage(
94 const blink::WebRect& anchor_in_root_view,
95 const blink::WebString& main_message,
96 blink::WebTextDirection main_message_hint,
97 const blink::WebString& sub_message,
98 blink::WebTextDirection sub_message_hint) {
99 if (test_runner()->is_web_platform_tests_mode())
100 return;
101
102 base::string16 wrapped_main_text = main_message.utf16();
103 base::string16 wrapped_sub_text = sub_message.utf16();
104
105 if (main_message_hint == blink::WebTextDirectionLeftToRight) {
106 wrapped_main_text =
107 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_main_text);
108 } else if (main_message_hint == blink::WebTextDirectionRightToLeft &&
109 !base::i18n::IsRTL()) {
110 base::i18n::WrapStringWithRTLFormatting(&wrapped_main_text);
111 }
112
113 if (!wrapped_sub_text.empty()) {
114 if (sub_message_hint == blink::WebTextDirectionLeftToRight) {
115 wrapped_sub_text =
116 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_sub_text);
117 } else if (sub_message_hint == blink::WebTextDirectionRightToLeft) {
118 base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text);
119 }
120 }
121 delegate()->PrintMessage("ValidationMessageClient: main-message=" +
122 base::UTF16ToUTF8(wrapped_main_text) +
123 " sub-message=" +
124 base::UTF16ToUTF8(wrapped_sub_text) + "\n");
125 }
126
127 blink::WebSpeechRecognizer* WebViewTestClient::speechRecognizer() {
128 return test_runner()->getMockWebSpeechRecognizer();
129 }
130
131 blink::WebString WebViewTestClient::acceptLanguages() {
132 return blink::WebString::fromUTF8(test_runner()->GetAcceptLanguages());
133 }
134
135 WebTestDelegate* WebViewTestClient::delegate() {
136 return web_view_test_proxy_base_->delegate();
137 }
138
139 void WebViewTestClient::didFocus() {
140 test_runner()->SetFocus(web_view_test_proxy_base_->web_view(), true);
141 }
142
143 TestRunner* WebViewTestClient::test_runner() {
144 return web_view_test_proxy_base_->test_interfaces()->GetTestRunner();
145 }
146
147 } // namespace test_runner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698