OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "components/test_runner/web_view_test_client.h" | 5 #include "components/test_runner/web_view_test_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "third_party/WebKit/public/web/WebFrame.h" | 21 #include "third_party/WebKit/public/web/WebFrame.h" |
22 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 22 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
23 #include "third_party/WebKit/public/web/WebPagePopup.h" | 23 #include "third_party/WebKit/public/web/WebPagePopup.h" |
24 #include "third_party/WebKit/public/web/WebPrintParams.h" | 24 #include "third_party/WebKit/public/web/WebPrintParams.h" |
25 #include "third_party/WebKit/public/web/WebView.h" | 25 #include "third_party/WebKit/public/web/WebView.h" |
26 #include "third_party/WebKit/public/web/WebWidget.h" | 26 #include "third_party/WebKit/public/web/WebWidget.h" |
27 | 27 |
28 namespace test_runner { | 28 namespace test_runner { |
29 | 29 |
30 WebViewTestClient::WebViewTestClient(TestRunner* test_runner, | 30 WebViewTestClient::WebViewTestClient(TestRunner* test_runner, |
31 WebTestDelegate* delegate, | |
32 EventSender* event_sender, | 31 EventSender* event_sender, |
33 WebTestProxyBase* web_test_proxy_base) | 32 WebTestProxyBase* web_test_proxy_base) |
34 : test_runner_(test_runner), | 33 : test_runner_(test_runner), |
35 delegate_(delegate), | |
36 event_sender_(event_sender), | 34 event_sender_(event_sender), |
37 web_test_proxy_base_(web_test_proxy_base), | 35 web_test_proxy_base_(web_test_proxy_base), |
38 animation_scheduled_(false), | 36 animation_scheduled_(false), |
39 weak_factory_(this) { | 37 weak_factory_(this) { |
40 DCHECK(test_runner); | 38 DCHECK(test_runner); |
41 DCHECK(delegate); | |
42 DCHECK(event_sender); | 39 DCHECK(event_sender); |
43 DCHECK(web_test_proxy_base); | 40 DCHECK(web_test_proxy_base); |
44 } | 41 } |
45 | 42 |
46 WebViewTestClient::~WebViewTestClient() {} | 43 WebViewTestClient::~WebViewTestClient() {} |
47 | 44 |
48 void WebViewTestClient::scheduleAnimation() { | 45 void WebViewTestClient::scheduleAnimation() { |
49 if (!test_runner_->TestIsRunning()) | 46 if (!test_runner_->TestIsRunning()) |
50 return; | 47 return; |
51 | 48 |
52 if (!animation_scheduled_) { | 49 if (!animation_scheduled_) { |
53 animation_scheduled_ = true; | 50 animation_scheduled_ = true; |
54 test_runner_->OnAnimationScheduled(web_test_proxy_base_->web_view()); | 51 test_runner_->OnAnimationScheduled(web_test_proxy_base_->web_view()); |
55 | 52 |
56 delegate_->PostDelayedTask( | 53 delegate()->PostDelayedTask( |
57 new WebCallbackTask(base::Bind(&WebViewTestClient::AnimateNow, | 54 new WebCallbackTask(base::Bind(&WebViewTestClient::AnimateNow, |
58 weak_factory_.GetWeakPtr())), | 55 weak_factory_.GetWeakPtr())), |
59 1); | 56 1); |
60 } | 57 } |
61 } | 58 } |
62 | 59 |
63 void WebViewTestClient::AnimateNow() { | 60 void WebViewTestClient::AnimateNow() { |
64 if (animation_scheduled_) { | 61 if (animation_scheduled_) { |
65 blink::WebWidget* web_widget = web_test_proxy_base_->web_widget(); | 62 blink::WebWidget* web_widget = web_test_proxy_base_->web_widget(); |
66 animation_scheduled_ = false; | 63 animation_scheduled_ = false; |
(...skipping 19 matching lines...) Expand all Loading... |
86 // When running a test, we need to fake a drag drop operation otherwise | 83 // When running a test, we need to fake a drag drop operation otherwise |
87 // Windows waits for real mouse events to know when the drag is over. | 84 // Windows waits for real mouse events to know when the drag is over. |
88 event_sender_->DoDragDrop(data, mask); | 85 event_sender_->DoDragDrop(data, mask); |
89 } | 86 } |
90 | 87 |
91 // The output from these methods in layout test mode should match that | 88 // The output from these methods in layout test mode should match that |
92 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree. | 89 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree. |
93 | 90 |
94 void WebViewTestClient::didChangeContents() { | 91 void WebViewTestClient::didChangeContents() { |
95 if (test_runner_->shouldDumpEditingCallbacks()) | 92 if (test_runner_->shouldDumpEditingCallbacks()) |
96 delegate_->PrintMessage( | 93 delegate()->PrintMessage( |
97 "EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n"); | 94 "EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n"); |
98 } | 95 } |
99 | 96 |
100 blink::WebView* WebViewTestClient::createView( | 97 blink::WebView* WebViewTestClient::createView( |
101 blink::WebLocalFrame* frame, | 98 blink::WebLocalFrame* frame, |
102 const blink::WebURLRequest& request, | 99 const blink::WebURLRequest& request, |
103 const blink::WebWindowFeatures& features, | 100 const blink::WebWindowFeatures& features, |
104 const blink::WebString& frame_name, | 101 const blink::WebString& frame_name, |
105 blink::WebNavigationPolicy policy, | 102 blink::WebNavigationPolicy policy, |
106 bool suppress_opener) { | 103 bool suppress_opener) { |
107 if (test_runner_->shouldDumpNavigationPolicy()) { | 104 if (test_runner_->shouldDumpNavigationPolicy()) { |
108 delegate_->PrintMessage("Default policy for createView for '" + | 105 delegate()->PrintMessage("Default policy for createView for '" + |
109 URLDescription(request.url()) + "' is '" + | 106 URLDescription(request.url()) + "' is '" + |
110 WebNavigationPolicyToString(policy) + "'\n"); | 107 WebNavigationPolicyToString(policy) + "'\n"); |
111 } | 108 } |
112 | 109 |
113 if (!test_runner_->canOpenWindows()) | 110 if (!test_runner_->canOpenWindows()) |
114 return nullptr; | 111 return nullptr; |
115 if (test_runner_->shouldDumpCreateView()) | 112 if (test_runner_->shouldDumpCreateView()) |
116 delegate_->PrintMessage(std::string("createView(") + | 113 delegate()->PrintMessage(std::string("createView(") + |
117 URLDescription(request.url()) + ")\n"); | 114 URLDescription(request.url()) + ")\n"); |
118 | 115 |
119 // The return value below is used to communicate to WebTestProxy whether it | 116 // The return value below is used to communicate to WebTestProxy whether it |
120 // should forward the createView request to RenderViewImpl or not. The | 117 // should forward the createView request to RenderViewImpl or not. The |
121 // somewhat ugly cast is used to do this while fitting into the existing | 118 // somewhat ugly cast is used to do this while fitting into the existing |
122 // WebViewClient interface. | 119 // WebViewClient interface. |
123 return reinterpret_cast<blink::WebView*>(0xdeadbeef); | 120 return reinterpret_cast<blink::WebView*>(0xdeadbeef); |
124 } | 121 } |
125 | 122 |
126 void WebViewTestClient::setStatusText(const blink::WebString& text) { | 123 void WebViewTestClient::setStatusText(const blink::WebString& text) { |
127 if (!test_runner_->shouldDumpStatusCallbacks()) | 124 if (!test_runner_->shouldDumpStatusCallbacks()) |
128 return; | 125 return; |
129 delegate_->PrintMessage( | 126 delegate()->PrintMessage( |
130 std::string("UI DELEGATE STATUS CALLBACK: setStatusText:") + | 127 std::string("UI DELEGATE STATUS CALLBACK: setStatusText:") + |
131 text.utf8().data() + "\n"); | 128 text.utf8().data() + "\n"); |
132 } | 129 } |
133 | 130 |
134 // Simulate a print by going into print mode and then exit straight away. | 131 // Simulate a print by going into print mode and then exit straight away. |
135 void WebViewTestClient::printPage(blink::WebLocalFrame* frame) { | 132 void WebViewTestClient::printPage(blink::WebLocalFrame* frame) { |
136 blink::WebSize page_size_in_pixels = frame->view()->size(); | 133 blink::WebSize page_size_in_pixels = frame->view()->size(); |
137 if (page_size_in_pixels.isEmpty()) | 134 if (page_size_in_pixels.isEmpty()) |
138 return; | 135 return; |
139 blink::WebPrintParams printParams(page_size_in_pixels); | 136 blink::WebPrintParams printParams(page_size_in_pixels); |
140 frame->printBegin(printParams); | 137 frame->printBegin(printParams); |
141 frame->printEnd(); | 138 frame->printEnd(); |
142 } | 139 } |
143 | 140 |
144 bool WebViewTestClient::runFileChooser( | 141 bool WebViewTestClient::runFileChooser( |
145 const blink::WebFileChooserParams& params, | 142 const blink::WebFileChooserParams& params, |
146 blink::WebFileChooserCompletion* completion) { | 143 blink::WebFileChooserCompletion* completion) { |
147 delegate_->PrintMessage("Mock: Opening a file chooser.\n"); | 144 delegate()->PrintMessage("Mock: Opening a file chooser.\n"); |
148 // FIXME: Add ability to set file names to a file upload control. | 145 // FIXME: Add ability to set file names to a file upload control. |
149 return false; | 146 return false; |
150 } | 147 } |
151 | 148 |
152 void WebViewTestClient::showValidationMessage( | 149 void WebViewTestClient::showValidationMessage( |
153 const blink::WebRect& anchor_in_root_view, | 150 const blink::WebRect& anchor_in_root_view, |
154 const blink::WebString& main_message, | 151 const blink::WebString& main_message, |
155 blink::WebTextDirection main_message_hint, | 152 blink::WebTextDirection main_message_hint, |
156 const blink::WebString& sub_message, | 153 const blink::WebString& sub_message, |
157 blink::WebTextDirection sub_message_hint) { | 154 blink::WebTextDirection sub_message_hint) { |
158 base::string16 wrapped_main_text = main_message; | 155 base::string16 wrapped_main_text = main_message; |
159 base::string16 wrapped_sub_text = sub_message; | 156 base::string16 wrapped_sub_text = sub_message; |
160 | 157 |
161 if (main_message_hint == blink::WebTextDirectionLeftToRight) { | 158 if (main_message_hint == blink::WebTextDirectionLeftToRight) { |
162 wrapped_main_text = | 159 wrapped_main_text = |
163 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_main_text); | 160 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_main_text); |
164 } else if (main_message_hint == blink::WebTextDirectionRightToLeft && | 161 } else if (main_message_hint == blink::WebTextDirectionRightToLeft && |
165 !base::i18n::IsRTL()) { | 162 !base::i18n::IsRTL()) { |
166 base::i18n::WrapStringWithRTLFormatting(&wrapped_main_text); | 163 base::i18n::WrapStringWithRTLFormatting(&wrapped_main_text); |
167 } | 164 } |
168 | 165 |
169 if (!wrapped_sub_text.empty()) { | 166 if (!wrapped_sub_text.empty()) { |
170 if (sub_message_hint == blink::WebTextDirectionLeftToRight) { | 167 if (sub_message_hint == blink::WebTextDirectionLeftToRight) { |
171 wrapped_sub_text = | 168 wrapped_sub_text = |
172 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_sub_text); | 169 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_sub_text); |
173 } else if (sub_message_hint == blink::WebTextDirectionRightToLeft) { | 170 } else if (sub_message_hint == blink::WebTextDirectionRightToLeft) { |
174 base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text); | 171 base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text); |
175 } | 172 } |
176 } | 173 } |
177 delegate_->PrintMessage("ValidationMessageClient: main-message=" + | 174 delegate()->PrintMessage("ValidationMessageClient: main-message=" + |
178 base::UTF16ToUTF8(wrapped_main_text) + | 175 base::UTF16ToUTF8(wrapped_main_text) + |
179 " sub-message=" + | 176 " sub-message=" + |
180 base::UTF16ToUTF8(wrapped_sub_text) + "\n"); | 177 base::UTF16ToUTF8(wrapped_sub_text) + "\n"); |
181 } | 178 } |
182 | 179 |
183 blink::WebSpeechRecognizer* WebViewTestClient::speechRecognizer() { | 180 blink::WebSpeechRecognizer* WebViewTestClient::speechRecognizer() { |
184 return test_runner_->getMockWebSpeechRecognizer(); | 181 return test_runner_->getMockWebSpeechRecognizer(); |
185 } | 182 } |
186 | 183 |
187 bool WebViewTestClient::requestPointerLock() { | 184 bool WebViewTestClient::requestPointerLock() { |
188 return test_runner_->RequestPointerLock(); | 185 return test_runner_->RequestPointerLock(); |
189 } | 186 } |
190 | 187 |
(...skipping 18 matching lines...) Expand all Loading... |
209 // If a composition text exists, then we need to let the browser process | 206 // If a composition text exists, then we need to let the browser process |
210 // to cancel the input method's ongoing composition session. | 207 // to cancel the input method's ongoing composition session. |
211 if (web_test_proxy_base_) | 208 if (web_test_proxy_base_) |
212 web_test_proxy_base_->web_widget()->confirmComposition(); | 209 web_test_proxy_base_->web_widget()->confirmComposition(); |
213 } | 210 } |
214 | 211 |
215 blink::WebString WebViewTestClient::acceptLanguages() { | 212 blink::WebString WebViewTestClient::acceptLanguages() { |
216 return blink::WebString::fromUTF8(test_runner_->GetAcceptLanguages()); | 213 return blink::WebString::fromUTF8(test_runner_->GetAcceptLanguages()); |
217 } | 214 } |
218 | 215 |
| 216 WebTestDelegate* WebViewTestClient::delegate() { |
| 217 return web_test_proxy_base_->delegate(); |
| 218 } |
| 219 |
219 } // namespace test_runner | 220 } // namespace test_runner |
OLD | NEW |