2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "MockSpellCheck.h"
35 #include "TestNavigationController.h"
36 #include "WebAccessibilityNotification.h"
37 #include "WebCursorInfo.h"
38 #include "WebFrameClient.h"
39 #include "WebViewClient.h"
40 #include <wtf/HashMap.h>
41 #include <wtf/HashSet.h>
42 #include <wtf/Vector.h>
43 #include <wtf/text/WTFString.h>
45 class LayoutTestController;
49 class WebDeviceOrientationClient;
50 class WebGeolocationServiceMock;
51 class WebSpeechInputController;
52 class WebSpeechInputListener;
56 struct WebWindowFeatures;
62 class WebViewHost : public WebKit::WebViewClient, public WebKit::WebFrameClient, public NavigationHost {
64 WebViewHost(TestShell* shell);
66 void setWebWidget(WebKit::WebWidget* widget) { m_webWidget = widget; }
67 WebKit::WebView* webView() const;
68 WebKit::WebWidget* webWidget() const;
70 void setSelectTrailingWhitespaceEnabled(bool);
71 void setSmartInsertDeleteEnabled(bool);
72 void waitForPolicyDelegate();
73 void setCustomPolicyDelegate(bool, bool);
74 WebKit::WebFrame* topLoadingFrame() { return m_topLoadingFrame; }
75 void setBlockRedirects(bool block) { m_blocksRedirects = block; }
76 void setRequestReturnNull(bool returnNull) { m_requestReturnNull = returnNull; }
77 void setEditCommand(const std::string& name, const std::string& value);
78 void clearEditCommand();
79 void setPendingExtraData(TestShellExtraData*);
81 void paintRect(const WebKit::WebRect&);
82 void updatePaintRect(const WebKit::WebRect&);
83 void paintInvalidatedRegion();
84 skia::PlatformCanvas* canvas();
85 void displayRepaintMask();
87 void loadURLForFrame(const WebKit::WebURL&, const WebKit::WebString& frameName);
88 TestNavigationController* navigationController() { return m_navigationController.get(); }
90 void addClearHeader(const WTF::String& header) { m_clearHeaders.add(header); }
91 const HashSet<WTF::String>& clearHeaders() const { return m_clearHeaders; }
94 virtual bool navigate(const TestNavigationEntry&, bool reload);
96 // WebKit::WebViewClient
97 virtual WebKit::WebView* createView(WebKit::WebFrame*, const WebKit::WebWindowFeatures&, const WebKit::WebString&);
98 virtual WebKit::WebWidget* createPopupMenu(WebKit::WebPopupType);
99 virtual WebKit::WebWidget* createPopupMenu(const WebKit::WebPopupMenuInfo&);
100 virtual WebKit::WebStorageNamespace* createSessionStorageNamespace(unsigned quota);
101 virtual void didAddMessageToConsole(const WebKit::WebConsoleMessage&, const WebKit::WebString& sourceName, unsigned sourceLine);
102 virtual void didStartLoading();
103 virtual void didStopLoading();
104 virtual bool shouldBeginEditing(const WebKit::WebRange&);
105 virtual bool shouldEndEditing(const WebKit::WebRange&);
106 virtual bool shouldInsertNode(const WebKit::WebNode&, const WebKit::WebRange&, WebKit::WebEditingAction);
107 virtual bool shouldInsertText(const WebKit::WebString&, const WebKit::WebRange&, WebKit::WebEditingAction);
108 virtual bool shouldChangeSelectedRange(const WebKit::WebRange& from, const WebKit::WebRange& to, WebKit::WebTextAffinity, bool stillSelecting);
109 virtual bool shouldDeleteRange(const WebKit::WebRange&);
110 virtual bool shouldApplyStyle(const WebKit::WebString& style, const WebKit::WebRange&);
111 virtual bool isSmartInsertDeleteEnabled();
112 virtual bool isSelectTrailingWhitespaceEnabled();
113 virtual void didBeginEditing();
114 virtual void didChangeSelection(bool isSelectionEmpty);
115 virtual void didChangeContents();
116 virtual void didEndEditing();
117 virtual bool handleCurrentKeyboardEvent();
118 virtual void spellCheck(const WebKit::WebString&, int& offset, int& length);
119 virtual WebKit::WebString autoCorrectWord(const WebKit::WebString&);
120 virtual void runModalAlertDialog(WebKit::WebFrame*, const WebKit::WebString&);
121 virtual bool runModalConfirmDialog(WebKit::WebFrame*, const WebKit::WebString&);
122 virtual bool runModalPromptDialog(WebKit::WebFrame*, const WebKit::WebString& message, const WebKit::WebString& defaultValue, WebKit::WebString* actualValue);
123 virtual bool runModalBeforeUnloadDialog(WebKit::WebFrame*, const WebKit::WebString&);
124 virtual void showContextMenu(WebKit::WebFrame*, const WebKit::WebContextMenuData&);
125 virtual void setStatusText(const WebKit::WebString&);
126 virtual void startDragging(const WebKit::WebDragData&, WebKit::WebDragOperationsMask, const WebKit::WebImage&, const WebKit::WebPoint&);
127 virtual void navigateBackForwardSoon(int offset);
128 virtual int historyBackListCount();
129 virtual int historyForwardListCount();
130 virtual void postAccessibilityNotification(const WebKit::WebAccessibilityObject&, WebKit::WebAccessibilityNotification);
131 virtual WebKit::WebNotificationPresenter* notificationPresenter();
132 #if !ENABLE(CLIENT_BASED_GEOLOCATION)
133 virtual WebKit::WebGeolocationService* geolocationService();
135 virtual WebKit::WebSpeechInputController* speechInputController(WebKit::WebSpeechInputListener*);
136 virtual WebKit::WebDeviceOrientationClient* deviceOrientationClient();
138 // WebKit::WebWidgetClient
139 virtual void didInvalidateRect(const WebKit::WebRect&);
140 virtual void didScrollRect(int dx, int dy, const WebKit::WebRect&);
141 virtual void scheduleComposite();
142 virtual void didFocus();
143 virtual void didBlur();
144 virtual void didChangeCursor(const WebKit::WebCursorInfo&);
145 virtual void closeWidgetSoon();
146 virtual void show(WebKit::WebNavigationPolicy);
147 virtual void runModal();
148 virtual WebKit::WebRect windowRect();
149 virtual void setWindowRect(const WebKit::WebRect&);
150 virtual WebKit::WebRect rootWindowRect();
151 virtual WebKit::WebRect windowResizerRect();
152 virtual WebKit::WebScreenInfo screenInfo();
154 // WebKit::WebFrameClient
155 virtual WebKit::WebPlugin* createPlugin(WebKit::WebFrame*, const WebKit::WebPluginParams&);
156 virtual WebKit::WebWorker* createWorker(WebKit::WebFrame*, WebKit::WebWorkerClient*);
157 virtual WebKit::WebMediaPlayer* createMediaPlayer(WebKit::WebFrame*, WebKit::WebMediaPlayerClient*);
158 virtual WebKit::WebApplicationCacheHost* createApplicationCacheHost(WebKit::WebFrame*, WebKit::WebApplicationCacheHostClient*);
159 virtual bool allowPlugins(WebKit::WebFrame*, bool enabledPerSettings);
160 virtual bool allowImages(WebKit::WebFrame*, bool enabledPerSettings);
161 virtual void loadURLExternally(WebKit::WebFrame*, const WebKit::WebURLRequest&, WebKit::WebNavigationPolicy);
162 virtual WebKit::WebNavigationPolicy decidePolicyForNavigation(
163 WebKit::WebFrame*, const WebKit::WebURLRequest&,
164 WebKit::WebNavigationType, const WebKit::WebNode&,
165 WebKit::WebNavigationPolicy, bool isRedirect);
166 virtual bool canHandleRequest(WebKit::WebFrame*, const WebKit::WebURLRequest&);
167 virtual WebKit::WebURLError cannotHandleRequestError(WebKit::WebFrame*, const WebKit::WebURLRequest&);
168 virtual WebKit::WebURLError cancelledError(WebKit::WebFrame*, const WebKit::WebURLRequest&);
169 virtual void unableToImplementPolicyWithError(WebKit::WebFrame*, const WebKit::WebURLError&);
170 virtual void willPerformClientRedirect(
171 WebKit::WebFrame*, const WebKit::WebURL& from, const WebKit::WebURL& to,
172 double interval, double fireTime);
173 virtual void didCancelClientRedirect(WebKit::WebFrame*);
174 virtual void didCreateDataSource(WebKit::WebFrame*, WebKit::WebDataSource*);
175 virtual void didStartProvisionalLoad(WebKit::WebFrame*);
176 virtual void didReceiveServerRedirectForProvisionalLoad(WebKit::WebFrame*);
177 virtual void didFailProvisionalLoad(WebKit::WebFrame*, const WebKit::WebURLError&);
178 virtual void didCommitProvisionalLoad(WebKit::WebFrame*, bool isNewNavigation);
179 virtual void didClearWindowObject(WebKit::WebFrame*);
180 virtual void didReceiveTitle(WebKit::WebFrame*, const WebKit::WebString&);
181 virtual void didFinishDocumentLoad(WebKit::WebFrame*);
182 virtual void didHandleOnloadEvents(WebKit::WebFrame*);
183 virtual void didFailLoad(WebKit::WebFrame*, const WebKit::WebURLError&);
184 virtual void didFinishLoad(WebKit::WebFrame*);
185 virtual void didNavigateWithinPage(WebKit::WebFrame*, bool isNewNavigation);
186 virtual void didChangeLocationWithinPage(WebKit::WebFrame*);
187 virtual void assignIdentifierToRequest(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLRequest&);
188 virtual void willSendRequest(WebKit::WebFrame*, unsigned identifier, WebKit::WebURLRequest&, const WebKit::WebURLResponse&);
189 virtual void didReceiveResponse(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLResponse&);
190 virtual void didFinishResourceLoad(WebKit::WebFrame*, unsigned identifier);
191 virtual void didFailResourceLoad(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLError&);
192 virtual void didDisplayInsecureContent(WebKit::WebFrame*);
193 virtual void didRunInsecureContent(WebKit::WebFrame*, const WebKit::WebSecurityOrigin&);
194 virtual bool allowScript(WebKit::WebFrame*, bool enabledPerSettings);
195 virtual void openFileSystem(WebKit::WebFrame*, WebKit::WebFileSystem::Type, long long size, bool create, WebKit::WebFileSystemCallbacks*);
198 LayoutTestController* layoutTestController() const;
200 // Called the title of the page changes.
201 // Can be used to update the title of the window.
202 void setPageTitle(const WebKit::WebString&);
204 // Called when the URL of the page changes.
205 // Extracts the URL and forwards on to SetAddressBarURL().
206 void updateAddressBar(WebKit::WebView*);
208 // Called when the URL of the page changes.
209 // Should be used to update the text of the URL bar.
210 void setAddressBarURL(const WebKit::WebURL&);
212 // In the Mac code, this is called to trigger the end of a test after the
213 // page has finished loading. From here, we can generate the dump for the
215 void locationChangeDone(WebKit::WebFrame*);
217 void updateForCommittedLoad(WebKit::WebFrame*, bool isNewNavigation);
218 void updateURL(WebKit::WebFrame*);
219 void updateSessionHistory(WebKit::WebFrame*);
221 // Dumping a frame to the console.
222 void printFrameDescription(WebKit::WebFrame*);
224 // Dumping the user gesture status to the console.
225 void printFrameUserGestureStatus(WebKit::WebFrame*, const char*);
227 bool hasWindow() const { return m_hasWindow; }
228 void resetScrollRect();
229 void discardBackingStore();
231 // Causes navigation actions just printout the intended navigation instead
232 // of taking you to the page. This is used for cases like mailto, where you
233 // don't actually want to open the mail program.
234 bool m_policyDelegateEnabled;
236 // Toggles the behavior of the policy delegate. If true, then navigations
237 // will be allowed. Otherwise, they will be ignored (dropped).
238 bool m_policyDelegateIsPermissive;
240 // If true, the policy delegate will signal layout test completion.
241 bool m_policyDelegateShouldNotifyDone;
243 // Non-owning pointer. The WebViewHost instance is owned by this TestShell instance.
246 // This delegate works for the following widget.
247 WebKit::WebWidget* m_webWidget;
249 // This is non-0 IFF a load is in progress.
250 WebKit::WebFrame* m_topLoadingFrame;
252 // For tracking session history. See RenderView.
254 int m_lastPageIdUpdated;
256 OwnPtr<TestShellExtraData> m_pendingExtraData;
258 // Maps resource identifiers to a descriptive string.
259 typedef HashMap<unsigned, std::string> ResourceMap;
260 ResourceMap m_resourceIdentifierMap;
261 void printResourceDescription(unsigned identifier);
263 WebKit::WebCursorInfo m_currentCursor;
267 WebKit::WebRect m_windowRect;
269 // true if we want to enable smart insert/delete.
270 bool m_smartInsertDeleteEnabled;
272 // true if we want to enable selection of trailing whitespaces
273 bool m_selectTrailingWhitespaceEnabled;
275 // Set of headers to clear in willSendRequest.
276 HashSet<WTF::String> m_clearHeaders;
278 // true if we should block any redirects
279 bool m_blocksRedirects;
281 // true if we should block (set an empty request for) any requests
282 bool m_requestReturnNull;
284 // Edit command associated to the current keyboard event.
285 std::string m_editCommandName;
286 std::string m_editCommandValue;
288 // The mock spellchecker used in spellCheck().
289 MockSpellCheck m_spellcheck;
292 OwnPtr<skia::PlatformCanvas> m_canvas;
293 WebKit::WebRect m_paintRect;
296 #if !ENABLE(CLIENT_BASED_GEOLOCATION)
298 OwnPtr<WebKit::WebGeolocationServiceMock> m_geolocationServiceMock;
301 OwnPtr<TestNavigationController*> m_navigationController;
304 #endif // WebViewHost_h