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