OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_ |
| 6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "content/shell/renderer/test_runner/TestInterfaces.h" |
| 10 #include "content/shell/renderer/test_runner/WebTestDelegate.h" |
| 11 #include "content/shell/renderer/test_runner/test_runner.h" |
| 12 #include "content/shell/renderer/test_runner/web_test_proxy.h" |
| 13 #include "third_party/WebKit/public/platform/WebString.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 // Templetized wrapper around RenderFrameImpl objects, which implement |
| 18 // the WebFrameClient interface. |
| 19 template <class Base, typename P, typename R> |
| 20 class WebFrameTestProxy : public Base { |
| 21 public: |
| 22 WebFrameTestProxy(P p, R r) : Base(p, r), base_proxy_(NULL) {} |
| 23 |
| 24 virtual ~WebFrameTestProxy() {} |
| 25 |
| 26 void set_base_proxy(WebTestProxyBase* proxy) { base_proxy_ = proxy; } |
| 27 |
| 28 // WebFrameClient implementation. |
| 29 virtual blink::WebPlugin* createPlugin(blink::WebLocalFrame* frame, |
| 30 const blink::WebPluginParams& params) { |
| 31 blink::WebPlugin* plugin = base_proxy_->CreatePlugin(frame, params); |
| 32 if (plugin) return plugin; |
| 33 return Base::createPlugin(frame, params); |
| 34 } |
| 35 |
| 36 virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message, |
| 37 const blink::WebString& sourceName, |
| 38 unsigned sourceLine, |
| 39 const blink::WebString& stackTrace) { |
| 40 base_proxy_->DidAddMessageToConsole(message, sourceName, sourceLine); |
| 41 Base::didAddMessageToConsole(message, sourceName, sourceLine, stackTrace); |
| 42 } |
| 43 |
| 44 virtual bool canCreatePluginWithoutRenderer( |
| 45 const blink::WebString& mimeType) { |
| 46 using blink::WebString; |
| 47 |
| 48 const CR_DEFINE_STATIC_LOCAL(WebString, suffix, |
| 49 ("-can-create-without-renderer")); |
| 50 return mimeType.utf8().find(suffix.utf8()) != std::string::npos; |
| 51 } |
| 52 |
| 53 virtual void loadURLExternally(blink::WebLocalFrame* frame, |
| 54 const blink::WebURLRequest& request, |
| 55 blink::WebNavigationPolicy policy, |
| 56 const blink::WebString& suggested_name) { |
| 57 base_proxy_->LoadURLExternally(frame, request, policy, suggested_name); |
| 58 Base::loadURLExternally(frame, request, policy, suggested_name); |
| 59 } |
| 60 |
| 61 virtual void didStartProvisionalLoad(blink::WebLocalFrame* frame) { |
| 62 base_proxy_->DidStartProvisionalLoad(frame); |
| 63 Base::didStartProvisionalLoad(frame); |
| 64 } |
| 65 |
| 66 virtual void didReceiveServerRedirectForProvisionalLoad( |
| 67 blink::WebLocalFrame* frame) { |
| 68 base_proxy_->DidReceiveServerRedirectForProvisionalLoad(frame); |
| 69 Base::didReceiveServerRedirectForProvisionalLoad(frame); |
| 70 } |
| 71 |
| 72 virtual void didFailProvisionalLoad(blink::WebLocalFrame* frame, |
| 73 const blink::WebURLError& error) { |
| 74 // If the test finished, don't notify the embedder of the failed load, |
| 75 // as we already destroyed the document loader. |
| 76 if (base_proxy_->DidFailProvisionalLoad(frame, error)) return; |
| 77 Base::didFailProvisionalLoad(frame, error); |
| 78 } |
| 79 |
| 80 virtual void didCommitProvisionalLoad( |
| 81 blink::WebLocalFrame* frame, const blink::WebHistoryItem& item, |
| 82 blink::WebHistoryCommitType commit_type) { |
| 83 base_proxy_->DidCommitProvisionalLoad(frame, item, commit_type); |
| 84 Base::didCommitProvisionalLoad(frame, item, commit_type); |
| 85 } |
| 86 |
| 87 virtual void didReceiveTitle(blink::WebLocalFrame* frame, |
| 88 const blink::WebString& title, |
| 89 blink::WebTextDirection direction) { |
| 90 base_proxy_->DidReceiveTitle(frame, title, direction); |
| 91 Base::didReceiveTitle(frame, title, direction); |
| 92 } |
| 93 |
| 94 virtual void didChangeIcon(blink::WebLocalFrame* frame, |
| 95 blink::WebIconURL::Type iconType) { |
| 96 base_proxy_->DidChangeIcon(frame, iconType); |
| 97 Base::didChangeIcon(frame, iconType); |
| 98 } |
| 99 |
| 100 virtual void didFinishDocumentLoad(blink::WebLocalFrame* frame) { |
| 101 base_proxy_->DidFinishDocumentLoad(frame); |
| 102 Base::didFinishDocumentLoad(frame); |
| 103 } |
| 104 |
| 105 virtual void didHandleOnloadEvents(blink::WebLocalFrame* frame) { |
| 106 base_proxy_->DidHandleOnloadEvents(frame); |
| 107 Base::didHandleOnloadEvents(frame); |
| 108 } |
| 109 |
| 110 virtual void didFailLoad(blink::WebLocalFrame* frame, |
| 111 const blink::WebURLError& error) { |
| 112 base_proxy_->DidFailLoad(frame, error); |
| 113 Base::didFailLoad(frame, error); |
| 114 } |
| 115 |
| 116 virtual void didFinishLoad(blink::WebLocalFrame* frame) { |
| 117 base_proxy_->DidFinishLoad(frame); |
| 118 Base::didFinishLoad(frame); |
| 119 } |
| 120 |
| 121 virtual blink::WebNotificationPresenter* notificationPresenter() { |
| 122 return base_proxy_->GetNotificationPresenter(); |
| 123 } |
| 124 |
| 125 virtual void didChangeSelection(bool is_selection_empty) { |
| 126 base_proxy_->DidChangeSelection(is_selection_empty); |
| 127 Base::didChangeSelection(is_selection_empty); |
| 128 } |
| 129 |
| 130 virtual blink::WebColorChooser* createColorChooser( |
| 131 blink::WebColorChooserClient* client, |
| 132 const blink::WebColor& initial_color, |
| 133 const blink::WebVector<blink::WebColorSuggestion>& suggestions) { |
| 134 return base_proxy_->CreateColorChooser(client, initial_color, suggestions); |
| 135 } |
| 136 |
| 137 virtual void runModalAlertDialog(const blink::WebString& message) { |
| 138 base_proxy_->delegate_->printMessage(std::string("ALERT: ") + |
| 139 message.utf8().data() + "\n"); |
| 140 } |
| 141 |
| 142 virtual bool runModalConfirmDialog(const blink::WebString& message) { |
| 143 base_proxy_->delegate_->printMessage(std::string("CONFIRM: ") + |
| 144 message.utf8().data() + "\n"); |
| 145 return true; |
| 146 } |
| 147 |
| 148 virtual bool runModalPromptDialog(const blink::WebString& message, |
| 149 const blink::WebString& defaultValue, |
| 150 blink::WebString*) { |
| 151 base_proxy_->delegate_->printMessage( |
| 152 std::string("PROMPT: ") + message.utf8().data() + ", default text: " + |
| 153 defaultValue.utf8().data() + "\n"); |
| 154 return true; |
| 155 } |
| 156 |
| 157 virtual bool runModalBeforeUnloadDialog(bool is_reload, |
| 158 const blink::WebString& message) { |
| 159 base_proxy_->delegate_->printMessage(std::string("CONFIRM NAVIGATION: ") + |
| 160 message.utf8().data() + "\n"); |
| 161 return !base_proxy_->test_interfaces_->testRunner() |
| 162 ->shouldStayOnPageAfterHandlingBeforeUnload(); |
| 163 } |
| 164 |
| 165 virtual void showContextMenu( |
| 166 const blink::WebContextMenuData& contextMenuData) { |
| 167 base_proxy_->ShowContextMenu(Base::GetWebFrame()->toWebLocalFrame(), |
| 168 contextMenuData); |
| 169 Base::showContextMenu(contextMenuData); |
| 170 } |
| 171 |
| 172 virtual void didDetectXSS(blink::WebLocalFrame* frame, |
| 173 const blink::WebURL& insecureURL, |
| 174 bool didBlockEntirePage) { |
| 175 // This is not implemented in RenderFrameImpl, so need to explicitly call |
| 176 // into the base proxy. |
| 177 base_proxy_->DidDetectXSS(frame, insecureURL, didBlockEntirePage); |
| 178 Base::didDetectXSS(frame, insecureURL, didBlockEntirePage); |
| 179 } |
| 180 |
| 181 virtual void didDispatchPingLoader(blink::WebLocalFrame* frame, |
| 182 const blink::WebURL& url) { |
| 183 // This is not implemented in RenderFrameImpl, so need to explicitly call |
| 184 // into the base proxy. |
| 185 base_proxy_->DidDispatchPingLoader(frame, url); |
| 186 Base::didDispatchPingLoader(frame, url); |
| 187 } |
| 188 |
| 189 virtual void willRequestResource(blink::WebLocalFrame* frame, |
| 190 const blink::WebCachedURLRequest& request) { |
| 191 // This is not implemented in RenderFrameImpl, so need to explicitly call |
| 192 // into the base proxy. |
| 193 base_proxy_->WillRequestResource(frame, request); |
| 194 Base::willRequestResource(frame, request); |
| 195 } |
| 196 |
| 197 virtual void didCreateDataSource(blink::WebLocalFrame* frame, |
| 198 blink::WebDataSource* ds) { |
| 199 Base::didCreateDataSource(frame, ds); |
| 200 } |
| 201 |
| 202 virtual void willSendRequest(blink::WebLocalFrame* frame, unsigned identifier, |
| 203 blink::WebURLRequest& request, |
| 204 const blink::WebURLResponse& redirectResponse) { |
| 205 base_proxy_->WillSendRequest(frame, identifier, request, redirectResponse); |
| 206 Base::willSendRequest(frame, identifier, request, redirectResponse); |
| 207 } |
| 208 |
| 209 virtual void didReceiveResponse(blink::WebLocalFrame* frame, |
| 210 unsigned identifier, |
| 211 const blink::WebURLResponse& response) { |
| 212 base_proxy_->DidReceiveResponse(frame, identifier, response); |
| 213 Base::didReceiveResponse(frame, identifier, response); |
| 214 } |
| 215 |
| 216 virtual void didChangeResourcePriority( |
| 217 blink::WebLocalFrame* frame, unsigned identifier, |
| 218 const blink::WebURLRequest::Priority& priority, |
| 219 int intra_priority_value) { |
| 220 // This is not implemented in RenderFrameImpl, so need to explicitly call |
| 221 // into the base proxy. |
| 222 base_proxy_->DidChangeResourcePriority(frame, identifier, priority, |
| 223 intra_priority_value); |
| 224 Base::didChangeResourcePriority(frame, identifier, priority, |
| 225 intra_priority_value); |
| 226 } |
| 227 |
| 228 virtual void didFinishResourceLoad(blink::WebLocalFrame* frame, |
| 229 unsigned identifier) { |
| 230 base_proxy_->DidFinishResourceLoad(frame, identifier); |
| 231 Base::didFinishResourceLoad(frame, identifier); |
| 232 } |
| 233 |
| 234 virtual blink::WebNavigationPolicy decidePolicyForNavigation( |
| 235 blink::WebLocalFrame* frame, blink::WebDataSource::ExtraData* extraData, |
| 236 const blink::WebURLRequest& request, blink::WebNavigationType type, |
| 237 blink::WebNavigationPolicy defaultPolicy, bool isRedirect) { |
| 238 blink::WebNavigationPolicy policy = base_proxy_->DecidePolicyForNavigation( |
| 239 frame, extraData, request, type, defaultPolicy, isRedirect); |
| 240 if (policy == blink::WebNavigationPolicyIgnore) return policy; |
| 241 |
| 242 return Base::decidePolicyForNavigation(frame, extraData, request, type, |
| 243 defaultPolicy, isRedirect); |
| 244 } |
| 245 |
| 246 virtual void willStartUsingPeerConnectionHandler( |
| 247 blink::WebLocalFrame* frame, |
| 248 blink::WebRTCPeerConnectionHandler* handler) { |
| 249 // RenderFrameImpl::willStartUsingPeerConnectionHandler can not be mocked. |
| 250 // See http://crbug/363285. |
| 251 } |
| 252 |
| 253 virtual blink::WebUserMediaClient* userMediaClient() { |
| 254 return base_proxy_->GetUserMediaClient(); |
| 255 } |
| 256 |
| 257 virtual bool willCheckAndDispatchMessageEvent( |
| 258 blink::WebLocalFrame* sourceFrame, blink::WebFrame* targetFrame, |
| 259 blink::WebSecurityOrigin target, blink::WebDOMMessageEvent event) { |
| 260 if (base_proxy_->WillCheckAndDispatchMessageEvent(sourceFrame, targetFrame, |
| 261 target, event)) |
| 262 return true; |
| 263 return Base::willCheckAndDispatchMessageEvent(sourceFrame, targetFrame, |
| 264 target, event); |
| 265 } |
| 266 |
| 267 virtual void didStopLoading() { |
| 268 base_proxy_->DidStopLoading(); |
| 269 Base::didStopLoading(); |
| 270 } |
| 271 |
| 272 private: |
| 273 WebTestProxyBase* base_proxy_; |
| 274 |
| 275 DISALLOW_COPY_AND_ASSIGN(WebFrameTestProxy); |
| 276 }; |
| 277 |
| 278 } // namespace content |
| 279 |
| 280 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_ |
OLD | NEW |