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

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

Issue 2171503005: Rename WebTestProxy to WebViewTestProxy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing comments Created 4 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_TEST_RUNNER_WEB_TEST_PROXY_H_
6 #define COMPONENTS_TEST_RUNNER_WEB_TEST_PROXY_H_
7
8 #include <memory>
9 #include <string>
10 #include <utility>
11
12 #include "base/callback.h"
13 #include "base/macros.h"
14 #include "build/build_config.h"
15 #include "components/test_runner/test_runner_export.h"
16 #include "components/test_runner/web_view_test_client.h"
17 #include "components/test_runner/web_widget_test_client.h"
18 #include "third_party/WebKit/public/platform/WebDragOperation.h"
19 #include "third_party/WebKit/public/platform/WebRect.h"
20 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
21 #include "third_party/WebKit/public/platform/WebURLError.h"
22 #include "third_party/WebKit/public/platform/WebURLRequest.h"
23 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
24 #include "third_party/WebKit/public/web/WebHistoryCommitType.h"
25 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
26 #include "third_party/WebKit/public/web/WebTextDirection.h"
27 #include "third_party/WebKit/public/web/WebViewClient.h"
28 #include "third_party/WebKit/public/web/WebWidgetClient.h"
29
30 namespace blink {
31 class WebDragData;
32 class WebFileChooserCompletion;
33 class WebImage;
34 class WebLocalFrame;
35 class WebString;
36 class WebView;
37 class WebWidget;
38 struct WebFileChooserParams;
39 struct WebPoint;
40 struct WebWindowFeatures;
41 }
42
43 namespace test_runner {
44
45 class AccessibilityController;
46 class EventSender;
47 class TestInterfaces;
48 class TestRunnerForSpecificView;
49 class TextInputController;
50 class WebTestDelegate;
51 class WebTestInterfaces;
52
53 // WebTestProxyBase is the "brain" of WebTestProxy in the sense that
54 // WebTestProxy does the bridge between RenderViewImpl and WebTestProxyBase and
55 // when it requires a behavior to be different from the usual, it will call
56 // WebTestProxyBase that implements the expected behavior.
57 // See WebTestProxy class comments for more information.
58 class TEST_RUNNER_EXPORT WebTestProxyBase {
59 public:
60 blink::WebWidget* web_widget() { return web_widget_; }
61 void set_web_widget(blink::WebWidget* widget) {
62 DCHECK(widget);
63 DCHECK(!web_widget_);
64 web_widget_ = widget;
65 }
66
67 blink::WebView* web_view() { return web_view_; }
68 void set_web_view(blink::WebView* view) {
69 DCHECK(view);
70 DCHECK(!web_view_);
71 web_view_ = view;
72 }
73
74 void set_view_test_client(
75 std::unique_ptr<WebViewTestClient> view_test_client) {
76 DCHECK(view_test_client);
77 DCHECK(!view_test_client_);
78 view_test_client_ = std::move(view_test_client);
79 }
80
81 void set_widget_test_client(
82 std::unique_ptr<WebWidgetTestClient> widget_test_client) {
83 DCHECK(widget_test_client);
84 DCHECK(!widget_test_client_);
85 widget_test_client_ = std::move(widget_test_client);
86 }
87
88 WebTestDelegate* delegate() { return delegate_; }
89 void set_delegate(WebTestDelegate* delegate) {
90 DCHECK(delegate);
91 DCHECK(!delegate_);
92 delegate_ = delegate;
93 }
94
95 TestInterfaces* test_interfaces() { return test_interfaces_; }
96 void SetInterfaces(WebTestInterfaces* web_test_interfaces);
97
98 EventSender* event_sender() { return event_sender_.get(); }
99
100 AccessibilityController* accessibility_controller() {
101 return accessibility_controller_.get();
102 }
103
104 TestRunnerForSpecificView* view_test_runner() {
105 return view_test_runner_.get();
106 }
107
108 void Reset();
109 void BindTo(blink::WebLocalFrame* frame);
110
111 void GetScreenOrientationForTesting(blink::WebScreenInfo&);
112
113 protected:
114 WebTestProxyBase();
115 ~WebTestProxyBase();
116
117 blink::WebViewClient* view_test_client() { return view_test_client_.get(); }
118 blink::WebWidgetClient* widget_test_client() {
119 return widget_test_client_.get();
120 }
121
122 private:
123 TestInterfaces* test_interfaces_;
124 WebTestDelegate* delegate_;
125 blink::WebView* web_view_;
126 blink::WebWidget* web_widget_;
127 std::unique_ptr<WebViewTestClient> view_test_client_;
128 std::unique_ptr<WebWidgetTestClient> widget_test_client_;
129 std::unique_ptr<AccessibilityController> accessibility_controller_;
130 std::unique_ptr<EventSender> event_sender_;
131 std::unique_ptr<TextInputController> text_input_controller_;
132 std::unique_ptr<TestRunnerForSpecificView> view_test_runner_;
133
134 DISALLOW_COPY_AND_ASSIGN(WebTestProxyBase);
135 };
136
137 // WebTestProxy is used during LayoutTests and always instantiated, at time of
138 // writing with Base=RenderViewImpl. It does not directly inherit from it for
139 // layering purposes.
140 // The intent of that class is to wrap RenderViewImpl for tests purposes in
141 // order to reduce the amount of test specific code in the production code.
142 // WebTestProxy is only doing the glue between RenderViewImpl and
143 // WebTestProxyBase, that means that there is no logic living in this class
144 // except deciding which base class should be called (could be both).
145 //
146 // Examples of usage:
147 // * when a fooClient has a mock implementation, WebTestProxy can override the
148 // fooClient() call and have WebTestProxyBase return the mock implementation.
149 // * when a value needs to be overridden by LayoutTests, WebTestProxy can
150 // override RenderViewImpl's getter and call a getter from WebTestProxyBase
151 // instead. In addition, WebTestProxyBase will have a public setter that
152 // could be called from the TestRunner.
153 #if defined(OS_WIN)
154 // WebTestProxy is a diamond-shaped hierarchy, with WebWidgetClient at the root.
155 // VS warns when we inherit the WebWidgetClient method implementations from
156 // RenderWidget. It's safe to ignore that warning.
157 #pragma warning(disable: 4250)
158 #endif
159 template <class Base, typename... Args>
160 class WebTestProxy : public Base, public WebTestProxyBase {
161 public:
162 explicit WebTestProxy(Args... args) : Base(args...) {}
163
164 // WebWidgetClient implementation.
165 blink::WebScreenInfo screenInfo() override {
166 blink::WebScreenInfo info = Base::screenInfo();
167 blink::WebScreenInfo test_info = widget_test_client()->screenInfo();
168 if (test_info.orientationType != blink::WebScreenOrientationUndefined) {
169 info.orientationType = test_info.orientationType;
170 info.orientationAngle = test_info.orientationAngle;
171 }
172 return info;
173 }
174 void scheduleAnimation() override {
175 widget_test_client()->scheduleAnimation();
176 }
177 bool requestPointerLock() override {
178 return widget_test_client()->requestPointerLock();
179 }
180 void requestPointerUnlock() override {
181 widget_test_client()->requestPointerUnlock();
182 }
183 bool isPointerLocked() override {
184 return widget_test_client()->isPointerLocked();
185 }
186 void didFocus() override {
187 view_test_client()->didFocus();
188 Base::didFocus();
189 }
190 void setToolTipText(const blink::WebString& text,
191 blink::WebTextDirection hint) override {
192 widget_test_client()->setToolTipText(text, hint);
193 Base::setToolTipText(text, hint);
194 }
195 void resetInputMethod() override { widget_test_client()->resetInputMethod(); }
196
197 // WebViewClient implementation.
198 void startDragging(blink::WebLocalFrame* frame,
199 const blink::WebDragData& data,
200 blink::WebDragOperationsMask mask,
201 const blink::WebImage& image,
202 const blink::WebPoint& point) override {
203 view_test_client()->startDragging(frame, data, mask, image, point);
204 // Don't forward this call to Base because we don't want to do a real
205 // drag-and-drop.
206 }
207 void didChangeContents() override {
208 view_test_client()->didChangeContents();
209 Base::didChangeContents();
210 }
211 blink::WebView* createView(blink::WebLocalFrame* creator,
212 const blink::WebURLRequest& request,
213 const blink::WebWindowFeatures& features,
214 const blink::WebString& frame_name,
215 blink::WebNavigationPolicy policy,
216 bool suppress_opener) override {
217 if (!view_test_client()->createView(creator, request, features, frame_name,
218 policy, suppress_opener))
219 return nullptr;
220 return Base::createView(
221 creator, request, features, frame_name, policy, suppress_opener);
222 }
223 void setStatusText(const blink::WebString& text) override {
224 view_test_client()->setStatusText(text);
225 Base::setStatusText(text);
226 }
227 void printPage(blink::WebLocalFrame* frame) override {
228 view_test_client()->printPage(frame);
229 }
230 blink::WebSpeechRecognizer* speechRecognizer() override {
231 return view_test_client()->speechRecognizer();
232 }
233 void showValidationMessage(
234 const blink::WebRect& anchor_in_root_view,
235 const blink::WebString& main_message,
236 blink::WebTextDirection main_message_hint,
237 const blink::WebString& sub_message,
238 blink::WebTextDirection sub_message_hint) override {
239 view_test_client()->showValidationMessage(anchor_in_root_view, main_message,
240 main_message_hint, sub_message,
241 sub_message_hint);
242 }
243 blink::WebString acceptLanguages() override {
244 return view_test_client()->acceptLanguages();
245 }
246
247 private:
248 virtual ~WebTestProxy() {}
249
250 DISALLOW_COPY_AND_ASSIGN(WebTestProxy);
251 };
252
253 } // namespace test_runner
254
255 #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