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

Side by Side Diff: components/test_runner/web_test_proxy.h

Issue 1840823002: Extract WebViewClient implementation out of WebTestProxyBase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@separate-pixel-dump-code
Patch Set: Expanding a comment + an IWYU fix. Created 4 years, 8 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
« no previous file with comments | « components/test_runner/web_test_interfaces.cc ('k') | components/test_runner/web_test_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef COMPONENTS_TEST_RUNNER_WEB_TEST_PROXY_H_ 5 #ifndef COMPONENTS_TEST_RUNNER_WEB_TEST_PROXY_H_
6 #define COMPONENTS_TEST_RUNNER_WEB_TEST_PROXY_H_ 6 #define COMPONENTS_TEST_RUNNER_WEB_TEST_PROXY_H_
7 7
8 #include <string> 8 #include <string>
9 #include <utility>
9 10
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 #include "components/test_runner/test_runner_export.h" 15 #include "components/test_runner/test_runner_export.h"
15 #include "components/test_runner/web_task.h" 16 #include "components/test_runner/web_view_test_client.h"
16 #include "third_party/WebKit/public/platform/WebRect.h" 17 #include "third_party/WebKit/public/platform/WebRect.h"
17 #include "third_party/WebKit/public/platform/WebScreenInfo.h" 18 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
18 #include "third_party/WebKit/public/platform/WebURLError.h" 19 #include "third_party/WebKit/public/platform/WebURLError.h"
19 #include "third_party/WebKit/public/platform/WebURLRequest.h" 20 #include "third_party/WebKit/public/platform/WebURLRequest.h"
20 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" 21 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
21 #include "third_party/WebKit/public/web/WebDragOperation.h" 22 #include "third_party/WebKit/public/web/WebDragOperation.h"
22 #include "third_party/WebKit/public/web/WebHistoryCommitType.h" 23 #include "third_party/WebKit/public/web/WebHistoryCommitType.h"
23 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" 24 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
24 #include "third_party/WebKit/public/web/WebTextDirection.h" 25 #include "third_party/WebKit/public/web/WebTextDirection.h"
26 #include "third_party/WebKit/public/web/WebViewClient.h"
27 #include "third_party/WebKit/public/web/WebWidgetClient.h"
25 28
26 namespace blink { 29 namespace blink {
27 class WebDragData; 30 class WebDragData;
28 class WebFileChooserCompletion; 31 class WebFileChooserCompletion;
29 class WebImage; 32 class WebImage;
30 class WebLocalFrame; 33 class WebLocalFrame;
31 class WebSpeechRecognizer;
32 class WebSpellCheckClient; 34 class WebSpellCheckClient;
33 class WebString; 35 class WebString;
34 class WebView; 36 class WebView;
35 class WebWidget; 37 class WebWidget;
36 struct WebFileChooserParams; 38 struct WebFileChooserParams;
37 struct WebPoint; 39 struct WebPoint;
38 struct WebWindowFeatures; 40 struct WebWindowFeatures;
39 } 41 }
40 42
41 namespace test_runner { 43 namespace test_runner {
42 44
43 class MockCredentialManagerClient; 45 class MockCredentialManagerClient;
44 class MockWebSpeechRecognizer;
45 class SpellCheckClient; 46 class SpellCheckClient;
46 class TestInterfaces; 47 class TestInterfaces;
47 class WebTestDelegate; 48 class WebTestDelegate;
48 class WebTestInterfaces; 49 class WebTestInterfaces;
49 50
50 // WebTestProxyBase is the "brain" of WebTestProxy in the sense that 51 // WebTestProxyBase is the "brain" of WebTestProxy in the sense that
51 // WebTestProxy does the bridge between RenderViewImpl and WebTestProxyBase and 52 // WebTestProxy does the bridge between RenderViewImpl and WebTestProxyBase and
52 // when it requires a behavior to be different from the usual, it will call 53 // when it requires a behavior to be different from the usual, it will call
53 // WebTestProxyBase that implements the expected behavior. 54 // WebTestProxyBase that implements the expected behavior.
54 // See WebTestProxy class comments for more information. 55 // See WebTestProxy class comments for more information.
55 class TEST_RUNNER_EXPORT WebTestProxyBase { 56 class TEST_RUNNER_EXPORT WebTestProxyBase {
56 public: 57 public:
58 blink::WebWidget* web_widget() { return web_widget_; }
59 void set_web_widget(blink::WebWidget* widget) {
60 DCHECK(widget);
61 DCHECK(!web_widget_);
62 web_widget_ = widget;
63 }
64
65 blink::WebView* web_view() { return web_view_; }
66 void set_web_view(blink::WebView* view) {
67 DCHECK(view);
68 DCHECK(!web_view_);
69 web_view_ = view;
70 }
71
72 void set_view_test_client(scoped_ptr<WebViewTestClient> view_test_client) {
73 DCHECK(view_test_client);
74 DCHECK(!view_test_client_);
75 view_test_client_ = std::move(view_test_client);
76 }
77
57 void SetInterfaces(WebTestInterfaces* interfaces); 78 void SetInterfaces(WebTestInterfaces* interfaces);
58 void SetDelegate(WebTestDelegate* delegate); 79 void SetDelegate(WebTestDelegate* delegate);
59 void set_widget(blink::WebWidget* widget) { web_widget_ = widget; }
60
61 void Reset();
62 80
63 blink::WebSpellCheckClient* GetSpellCheckClient() const; 81 blink::WebSpellCheckClient* GetSpellCheckClient() const;
64 bool RunFileChooser(const blink::WebFileChooserParams& params,
65 blink::WebFileChooserCompletion* completion);
66 void ShowValidationMessage(const blink::WebString& main_message,
67 blink::WebTextDirection main_message_hint,
68 const blink::WebString& sub_message,
69 blink::WebTextDirection sub_message_hint);
70 82
71 std::string DumpBackForwardLists(); 83 std::string DumpBackForwardLists();
72 84
73 void LayoutAndPaintAsyncThen(const base::Closure& callback); 85 void LayoutAndPaintAsyncThen(const base::Closure& callback);
74 86
75 void GetScreenOrientationForTesting(blink::WebScreenInfo&); 87 void GetScreenOrientationForTesting(blink::WebScreenInfo&);
76 MockWebSpeechRecognizer* GetSpeechRecognizerMock();
77 MockCredentialManagerClient* GetCredentialManagerClientMock(); 88 MockCredentialManagerClient* GetCredentialManagerClientMock();
78 89
79 WebTaskList* mutable_task_list() { return &task_list_; }
80
81 blink::WebView* GetWebView() const;
82
83 void PostSpellCheckEvent(const blink::WebString& event_name); 90 void PostSpellCheckEvent(const blink::WebString& event_name);
84 91
85 bool AnimationScheduled() { return animate_scheduled_; }
86
87 protected: 92 protected:
88 WebTestProxyBase(); 93 WebTestProxyBase();
89 ~WebTestProxyBase(); 94 ~WebTestProxyBase();
90 95
91 void ScheduleAnimation(); 96 blink::WebViewClient* view_test_client() { return view_test_client_.get(); }
92 void StartDragging(blink::WebLocalFrame* frame,
93 const blink::WebDragData& data,
94 blink::WebDragOperationsMask mask,
95 const blink::WebImage& image,
96 const blink::WebPoint& point);
97 void DidChangeContents();
98 void DidEndEditing();
99 bool CreateView(blink::WebLocalFrame* creator,
100 const blink::WebURLRequest& request,
101 const blink::WebWindowFeatures& features,
102 const blink::WebString& frame_name,
103 blink::WebNavigationPolicy policy,
104 bool suppress_opener);
105 void SetStatusText(const blink::WebString& text);
106 void PrintPage(blink::WebLocalFrame* frame);
107 blink::WebSpeechRecognizer* GetSpeechRecognizer();
108 bool RequestPointerLock();
109 void RequestPointerUnlock();
110 bool IsPointerLocked();
111 void DidFocus();
112 void SetToolTipText(const blink::WebString& text,
113 blink::WebTextDirection direction);
114 void DidChangeLocationWithinPage(blink::WebLocalFrame* frame);
115 void ResetInputMethod();
116
117 blink::WebString acceptLanguages();
118 97
119 private: 98 private:
120 void AnimateNow();
121
122 TestInterfaces* test_interfaces_; 99 TestInterfaces* test_interfaces_;
123 WebTestDelegate* delegate_; 100 WebTestDelegate* delegate_;
101 blink::WebView* web_view_;
124 blink::WebWidget* web_widget_; 102 blink::WebWidget* web_widget_;
125 103 scoped_ptr<WebViewTestClient> view_test_client_;
126 WebTaskList task_list_;
127 104
128 scoped_ptr<SpellCheckClient> spellcheck_; 105 scoped_ptr<SpellCheckClient> spellcheck_;
106 scoped_ptr<MockCredentialManagerClient> credential_manager_client_;
129 107
130 bool animate_scheduled_;
131
132 scoped_ptr<MockCredentialManagerClient> credential_manager_client_;
133 scoped_ptr<MockWebSpeechRecognizer> speech_recognizer_;
134
135 private:
136 DISALLOW_COPY_AND_ASSIGN(WebTestProxyBase); 108 DISALLOW_COPY_AND_ASSIGN(WebTestProxyBase);
137 }; 109 };
138 110
139 // WebTestProxy is used during LayoutTests and always instantiated, at time of 111 // WebTestProxy is used during LayoutTests and always instantiated, at time of
140 // writing with Base=RenderViewImpl. It does not directly inherit from it for 112 // writing with Base=RenderViewImpl. It does not directly inherit from it for
141 // layering purposes. 113 // layering purposes.
142 // The intent of that class is to wrap RenderViewImpl for tests purposes in 114 // The intent of that class is to wrap RenderViewImpl for tests purposes in
143 // order to reduce the amount of test specific code in the production code. 115 // order to reduce the amount of test specific code in the production code.
144 // WebTestProxy is only doing the glue between RenderViewImpl and 116 // WebTestProxy is only doing the glue between RenderViewImpl and
145 // WebTestProxyBase, that means that there is no logic living in this class 117 // WebTestProxyBase, that means that there is no logic living in this class
(...skipping 18 matching lines...) Expand all
164 explicit WebTestProxy(Args... args) : Base(args...) {} 136 explicit WebTestProxy(Args... args) : Base(args...) {}
165 137
166 // WebWidgetClient implementation. 138 // WebWidgetClient implementation.
167 blink::WebScreenInfo screenInfo() override { 139 blink::WebScreenInfo screenInfo() override {
168 blink::WebScreenInfo info = Base::screenInfo(); 140 blink::WebScreenInfo info = Base::screenInfo();
169 WebTestProxyBase::GetScreenOrientationForTesting(info); 141 WebTestProxyBase::GetScreenOrientationForTesting(info);
170 return info; 142 return info;
171 } 143 }
172 144
173 // WebViewClient implementation. 145 // WebViewClient implementation.
174 void scheduleAnimation() override { WebTestProxyBase::ScheduleAnimation(); } 146 void scheduleAnimation() override { view_test_client()->scheduleAnimation(); }
175 void startDragging(blink::WebLocalFrame* frame, 147 void startDragging(blink::WebLocalFrame* frame,
176 const blink::WebDragData& data, 148 const blink::WebDragData& data,
177 blink::WebDragOperationsMask mask, 149 blink::WebDragOperationsMask mask,
178 const blink::WebImage& image, 150 const blink::WebImage& image,
179 const blink::WebPoint& point) override { 151 const blink::WebPoint& point) override {
180 WebTestProxyBase::StartDragging(frame, data, mask, image, point); 152 view_test_client()->startDragging(frame, data, mask, image, point);
181 // Don't forward this call to Base because we don't want to do a real 153 // Don't forward this call to Base because we don't want to do a real
182 // drag-and-drop. 154 // drag-and-drop.
183 } 155 }
184 void didChangeContents() override { 156 void didChangeContents() override {
185 WebTestProxyBase::DidChangeContents(); 157 view_test_client()->didChangeContents();
186 Base::didChangeContents(); 158 Base::didChangeContents();
187 } 159 }
188 blink::WebView* createView(blink::WebLocalFrame* creator, 160 blink::WebView* createView(blink::WebLocalFrame* creator,
189 const blink::WebURLRequest& request, 161 const blink::WebURLRequest& request,
190 const blink::WebWindowFeatures& features, 162 const blink::WebWindowFeatures& features,
191 const blink::WebString& frame_name, 163 const blink::WebString& frame_name,
192 blink::WebNavigationPolicy policy, 164 blink::WebNavigationPolicy policy,
193 bool suppress_opener) override { 165 bool suppress_opener) override {
194 if (!WebTestProxyBase::CreateView( 166 if (!view_test_client()->createView(creator, request, features, frame_name,
195 creator, request, features, frame_name, policy, suppress_opener)) 167 policy, suppress_opener))
196 return 0; 168 return nullptr;
197 return Base::createView( 169 return Base::createView(
198 creator, request, features, frame_name, policy, suppress_opener); 170 creator, request, features, frame_name, policy, suppress_opener);
199 } 171 }
200 void setStatusText(const blink::WebString& text) override { 172 void setStatusText(const blink::WebString& text) override {
201 WebTestProxyBase::SetStatusText(text); 173 view_test_client()->setStatusText(text);
202 Base::setStatusText(text); 174 Base::setStatusText(text);
203 } 175 }
204 void printPage(blink::WebLocalFrame* frame) override { 176 void printPage(blink::WebLocalFrame* frame) override {
205 WebTestProxyBase::PrintPage(frame); 177 view_test_client()->printPage(frame);
206 } 178 }
207 blink::WebSpeechRecognizer* speechRecognizer() override { 179 blink::WebSpeechRecognizer* speechRecognizer() override {
208 return WebTestProxyBase::GetSpeechRecognizer(); 180 return view_test_client()->speechRecognizer();
209 } 181 }
210 bool requestPointerLock() override { 182 bool requestPointerLock() override {
211 return WebTestProxyBase::RequestPointerLock(); 183 return view_test_client()->requestPointerLock();
212 } 184 }
213 void requestPointerUnlock() override { 185 void requestPointerUnlock() override {
214 WebTestProxyBase::RequestPointerUnlock(); 186 view_test_client()->requestPointerUnlock();
215 } 187 }
216 bool isPointerLocked() override { 188 bool isPointerLocked() override {
217 return WebTestProxyBase::IsPointerLocked(); 189 return view_test_client()->isPointerLocked();
218 } 190 }
219 void didFocus() override { 191 void didFocus() override {
220 WebTestProxyBase::DidFocus(); 192 view_test_client()->didFocus();
221 Base::didFocus(); 193 Base::didFocus();
222 } 194 }
223 void setToolTipText(const blink::WebString& text, 195 void setToolTipText(const blink::WebString& text,
224 blink::WebTextDirection hint) override { 196 blink::WebTextDirection hint) override {
225 WebTestProxyBase::SetToolTipText(text, hint); 197 view_test_client()->setToolTipText(text, hint);
226 Base::setToolTipText(text, hint); 198 Base::setToolTipText(text, hint);
227 } 199 }
228 void resetInputMethod() override { WebTestProxyBase::ResetInputMethod(); } 200 void resetInputMethod() override { view_test_client()->resetInputMethod(); }
229 bool runFileChooser(const blink::WebFileChooserParams& params, 201 bool runFileChooser(const blink::WebFileChooserParams& params,
230 blink::WebFileChooserCompletion* completion) override { 202 blink::WebFileChooserCompletion* completion) override {
231 return WebTestProxyBase::RunFileChooser(params, completion); 203 return view_test_client()->runFileChooser(params, completion);
232 } 204 }
233 void showValidationMessage( 205 void showValidationMessage(
234 const blink::WebRect& anchor_in_root_view, 206 const blink::WebRect& anchor_in_root_view,
235 const blink::WebString& main_message, 207 const blink::WebString& main_message,
236 blink::WebTextDirection main_message_hint, 208 blink::WebTextDirection main_message_hint,
237 const blink::WebString& sub_message, 209 const blink::WebString& sub_message,
238 blink::WebTextDirection sub_message_hint) override { 210 blink::WebTextDirection sub_message_hint) override {
239 WebTestProxyBase::ShowValidationMessage(main_message, main_message_hint, 211 view_test_client()->showValidationMessage(anchor_in_root_view, main_message,
240 sub_message, sub_message_hint); 212 main_message_hint, sub_message,
213 sub_message_hint);
241 } 214 }
242 blink::WebString acceptLanguages() override { 215 blink::WebString acceptLanguages() override {
243 return WebTestProxyBase::acceptLanguages(); 216 return view_test_client()->acceptLanguages();
244 } 217 }
245 218
246 private: 219 private:
247 virtual ~WebTestProxy() {} 220 virtual ~WebTestProxy() {}
248 221
249 DISALLOW_COPY_AND_ASSIGN(WebTestProxy); 222 DISALLOW_COPY_AND_ASSIGN(WebTestProxy);
250 }; 223 };
251 224
252 } // namespace test_runner 225 } // namespace test_runner
253 226
254 #endif // COMPONENTS_TEST_RUNNER_WEB_TEST_PROXY_H_ 227 #endif // COMPONENTS_TEST_RUNNER_WEB_TEST_PROXY_H_
OLDNEW
« no previous file with comments | « components/test_runner/web_test_interfaces.cc ('k') | components/test_runner/web_test_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698