| OLD | NEW |
| 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 <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "components/test_runner/test_runner_export.h" | 15 #include "components/test_runner/test_runner_export.h" |
| 16 #include "components/test_runner/web_view_test_client.h" | 16 #include "components/test_runner/web_view_test_client.h" |
| 17 #include "components/test_runner/web_widget_test_client.h" |
| 17 #include "third_party/WebKit/public/platform/WebDragOperation.h" | 18 #include "third_party/WebKit/public/platform/WebDragOperation.h" |
| 18 #include "third_party/WebKit/public/platform/WebRect.h" | 19 #include "third_party/WebKit/public/platform/WebRect.h" |
| 19 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 20 #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
| 20 #include "third_party/WebKit/public/platform/WebURLError.h" | 21 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 21 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 22 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 22 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" | 23 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" |
| 23 #include "third_party/WebKit/public/web/WebHistoryCommitType.h" | 24 #include "third_party/WebKit/public/web/WebHistoryCommitType.h" |
| 24 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" | 25 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" |
| 25 #include "third_party/WebKit/public/web/WebTextDirection.h" | 26 #include "third_party/WebKit/public/web/WebTextDirection.h" |
| 26 #include "third_party/WebKit/public/web/WebViewClient.h" | 27 #include "third_party/WebKit/public/web/WebViewClient.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 web_view_ = view; | 71 web_view_ = view; |
| 71 } | 72 } |
| 72 | 73 |
| 73 void set_view_test_client( | 74 void set_view_test_client( |
| 74 std::unique_ptr<WebViewTestClient> view_test_client) { | 75 std::unique_ptr<WebViewTestClient> view_test_client) { |
| 75 DCHECK(view_test_client); | 76 DCHECK(view_test_client); |
| 76 DCHECK(!view_test_client_); | 77 DCHECK(!view_test_client_); |
| 77 view_test_client_ = std::move(view_test_client); | 78 view_test_client_ = std::move(view_test_client); |
| 78 } | 79 } |
| 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 |
| 80 WebTestDelegate* delegate() { return delegate_; } | 88 WebTestDelegate* delegate() { return delegate_; } |
| 81 void set_delegate(WebTestDelegate* delegate) { | 89 void set_delegate(WebTestDelegate* delegate) { |
| 82 DCHECK(delegate); | 90 DCHECK(delegate); |
| 83 DCHECK(!delegate_); | 91 DCHECK(!delegate_); |
| 84 delegate_ = delegate; | 92 delegate_ = delegate; |
| 85 } | 93 } |
| 86 | 94 |
| 87 TestInterfaces* test_interfaces() { return test_interfaces_; } | 95 TestInterfaces* test_interfaces() { return test_interfaces_; } |
| 88 void SetInterfaces(WebTestInterfaces* web_test_interfaces); | 96 void SetInterfaces(WebTestInterfaces* web_test_interfaces); |
| 89 | 97 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 101 void Reset(); | 109 void Reset(); |
| 102 void BindTo(blink::WebLocalFrame* frame); | 110 void BindTo(blink::WebLocalFrame* frame); |
| 103 | 111 |
| 104 void GetScreenOrientationForTesting(blink::WebScreenInfo&); | 112 void GetScreenOrientationForTesting(blink::WebScreenInfo&); |
| 105 | 113 |
| 106 protected: | 114 protected: |
| 107 WebTestProxyBase(); | 115 WebTestProxyBase(); |
| 108 ~WebTestProxyBase(); | 116 ~WebTestProxyBase(); |
| 109 | 117 |
| 110 blink::WebViewClient* view_test_client() { return view_test_client_.get(); } | 118 blink::WebViewClient* view_test_client() { return view_test_client_.get(); } |
| 119 blink::WebWidgetClient* widget_test_client() { |
| 120 return widget_test_client_.get(); |
| 121 } |
| 111 | 122 |
| 112 private: | 123 private: |
| 113 TestInterfaces* test_interfaces_; | 124 TestInterfaces* test_interfaces_; |
| 114 WebTestDelegate* delegate_; | 125 WebTestDelegate* delegate_; |
| 115 blink::WebView* web_view_; | 126 blink::WebView* web_view_; |
| 116 blink::WebWidget* web_widget_; | 127 blink::WebWidget* web_widget_; |
| 117 std::unique_ptr<WebViewTestClient> view_test_client_; | 128 std::unique_ptr<WebViewTestClient> view_test_client_; |
| 129 std::unique_ptr<WebWidgetTestClient> widget_test_client_; |
| 118 std::unique_ptr<AccessibilityController> accessibility_controller_; | 130 std::unique_ptr<AccessibilityController> accessibility_controller_; |
| 119 std::unique_ptr<EventSender> event_sender_; | 131 std::unique_ptr<EventSender> event_sender_; |
| 120 std::unique_ptr<TextInputController> text_input_controller_; | 132 std::unique_ptr<TextInputController> text_input_controller_; |
| 121 std::unique_ptr<TestRunnerForSpecificView> view_test_runner_; | 133 std::unique_ptr<TestRunnerForSpecificView> view_test_runner_; |
| 122 | 134 |
| 123 DISALLOW_COPY_AND_ASSIGN(WebTestProxyBase); | 135 DISALLOW_COPY_AND_ASSIGN(WebTestProxyBase); |
| 124 }; | 136 }; |
| 125 | 137 |
| 126 // WebTestProxy is used during LayoutTests and always instantiated, at time of | 138 // WebTestProxy is used during LayoutTests and always instantiated, at time of |
| 127 // writing with Base=RenderViewImpl. It does not directly inherit from it for | 139 // writing with Base=RenderViewImpl. It does not directly inherit from it for |
| (...skipping 18 matching lines...) Expand all Loading... |
| 146 #pragma warning(disable: 4250) | 158 #pragma warning(disable: 4250) |
| 147 #endif | 159 #endif |
| 148 template <class Base, typename... Args> | 160 template <class Base, typename... Args> |
| 149 class WebTestProxy : public Base, public WebTestProxyBase { | 161 class WebTestProxy : public Base, public WebTestProxyBase { |
| 150 public: | 162 public: |
| 151 explicit WebTestProxy(Args... args) : Base(args...) {} | 163 explicit WebTestProxy(Args... args) : Base(args...) {} |
| 152 | 164 |
| 153 // WebWidgetClient implementation. | 165 // WebWidgetClient implementation. |
| 154 blink::WebScreenInfo screenInfo() override { | 166 blink::WebScreenInfo screenInfo() override { |
| 155 blink::WebScreenInfo info = Base::screenInfo(); | 167 blink::WebScreenInfo info = Base::screenInfo(); |
| 156 WebTestProxyBase::GetScreenOrientationForTesting(info); | 168 blink::WebScreenInfo test_info = widget_test_client()->screenInfo(); |
| 169 if (test_info.orientationType != blink::WebScreenOrientationUndefined) { |
| 170 info.orientationType = test_info.orientationType; |
| 171 info.orientationAngle = test_info.orientationAngle; |
| 172 } |
| 157 return info; | 173 return info; |
| 158 } | 174 } |
| 175 void scheduleAnimation() override { |
| 176 widget_test_client()->scheduleAnimation(); |
| 177 } |
| 178 bool requestPointerLock() override { |
| 179 return widget_test_client()->requestPointerLock(); |
| 180 } |
| 181 void requestPointerUnlock() override { |
| 182 widget_test_client()->requestPointerUnlock(); |
| 183 } |
| 184 bool isPointerLocked() override { |
| 185 return widget_test_client()->isPointerLocked(); |
| 186 } |
| 187 void didFocus() override { |
| 188 widget_test_client()->didFocus(); |
| 189 Base::didFocus(); |
| 190 } |
| 191 void setToolTipText(const blink::WebString& text, |
| 192 blink::WebTextDirection hint) override { |
| 193 widget_test_client()->setToolTipText(text, hint); |
| 194 Base::setToolTipText(text, hint); |
| 195 } |
| 196 void resetInputMethod() override { widget_test_client()->resetInputMethod(); } |
| 159 | 197 |
| 160 // WebViewClient implementation. | 198 // WebViewClient implementation. |
| 161 void scheduleAnimation() override { view_test_client()->scheduleAnimation(); } | |
| 162 void startDragging(blink::WebLocalFrame* frame, | 199 void startDragging(blink::WebLocalFrame* frame, |
| 163 const blink::WebDragData& data, | 200 const blink::WebDragData& data, |
| 164 blink::WebDragOperationsMask mask, | 201 blink::WebDragOperationsMask mask, |
| 165 const blink::WebImage& image, | 202 const blink::WebImage& image, |
| 166 const blink::WebPoint& point) override { | 203 const blink::WebPoint& point) override { |
| 167 view_test_client()->startDragging(frame, data, mask, image, point); | 204 view_test_client()->startDragging(frame, data, mask, image, point); |
| 168 // Don't forward this call to Base because we don't want to do a real | 205 // Don't forward this call to Base because we don't want to do a real |
| 169 // drag-and-drop. | 206 // drag-and-drop. |
| 170 } | 207 } |
| 171 void didChangeContents() override { | 208 void didChangeContents() override { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 187 void setStatusText(const blink::WebString& text) override { | 224 void setStatusText(const blink::WebString& text) override { |
| 188 view_test_client()->setStatusText(text); | 225 view_test_client()->setStatusText(text); |
| 189 Base::setStatusText(text); | 226 Base::setStatusText(text); |
| 190 } | 227 } |
| 191 void printPage(blink::WebLocalFrame* frame) override { | 228 void printPage(blink::WebLocalFrame* frame) override { |
| 192 view_test_client()->printPage(frame); | 229 view_test_client()->printPage(frame); |
| 193 } | 230 } |
| 194 blink::WebSpeechRecognizer* speechRecognizer() override { | 231 blink::WebSpeechRecognizer* speechRecognizer() override { |
| 195 return view_test_client()->speechRecognizer(); | 232 return view_test_client()->speechRecognizer(); |
| 196 } | 233 } |
| 197 bool requestPointerLock() override { | |
| 198 return view_test_client()->requestPointerLock(); | |
| 199 } | |
| 200 void requestPointerUnlock() override { | |
| 201 view_test_client()->requestPointerUnlock(); | |
| 202 } | |
| 203 bool isPointerLocked() override { | |
| 204 return view_test_client()->isPointerLocked(); | |
| 205 } | |
| 206 void didFocus() override { | |
| 207 view_test_client()->didFocus(); | |
| 208 Base::didFocus(); | |
| 209 } | |
| 210 void setToolTipText(const blink::WebString& text, | |
| 211 blink::WebTextDirection hint) override { | |
| 212 view_test_client()->setToolTipText(text, hint); | |
| 213 Base::setToolTipText(text, hint); | |
| 214 } | |
| 215 void resetInputMethod() override { view_test_client()->resetInputMethod(); } | |
| 216 bool runFileChooser(const blink::WebFileChooserParams& params, | 234 bool runFileChooser(const blink::WebFileChooserParams& params, |
| 217 blink::WebFileChooserCompletion* completion) override { | 235 blink::WebFileChooserCompletion* completion) override { |
| 218 return view_test_client()->runFileChooser(params, completion); | 236 return view_test_client()->runFileChooser(params, completion); |
| 219 } | 237 } |
| 220 void showValidationMessage( | 238 void showValidationMessage( |
| 221 const blink::WebRect& anchor_in_root_view, | 239 const blink::WebRect& anchor_in_root_view, |
| 222 const blink::WebString& main_message, | 240 const blink::WebString& main_message, |
| 223 blink::WebTextDirection main_message_hint, | 241 blink::WebTextDirection main_message_hint, |
| 224 const blink::WebString& sub_message, | 242 const blink::WebString& sub_message, |
| 225 blink::WebTextDirection sub_message_hint) override { | 243 blink::WebTextDirection sub_message_hint) override { |
| 226 view_test_client()->showValidationMessage(anchor_in_root_view, main_message, | 244 view_test_client()->showValidationMessage(anchor_in_root_view, main_message, |
| 227 main_message_hint, sub_message, | 245 main_message_hint, sub_message, |
| 228 sub_message_hint); | 246 sub_message_hint); |
| 229 } | 247 } |
| 230 blink::WebString acceptLanguages() override { | 248 blink::WebString acceptLanguages() override { |
| 231 return view_test_client()->acceptLanguages(); | 249 return view_test_client()->acceptLanguages(); |
| 232 } | 250 } |
| 233 | 251 |
| 234 private: | 252 private: |
| 235 virtual ~WebTestProxy() {} | 253 virtual ~WebTestProxy() {} |
| 236 | 254 |
| 237 DISALLOW_COPY_AND_ASSIGN(WebTestProxy); | 255 DISALLOW_COPY_AND_ASSIGN(WebTestProxy); |
| 238 }; | 256 }; |
| 239 | 257 |
| 240 } // namespace test_runner | 258 } // namespace test_runner |
| 241 | 259 |
| 242 #endif // COMPONENTS_TEST_RUNNER_WEB_TEST_PROXY_H_ | 260 #endif // COMPONENTS_TEST_RUNNER_WEB_TEST_PROXY_H_ |
| OLD | NEW |