• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
3  * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef LayoutTestControllerQt_h
31 #define LayoutTestControllerQt_h
32 
33 #include <QBasicTimer>
34 #include <QObject>
35 #include <QSize>
36 #include <QString>
37 #include <QtDebug>
38 #include <QTimer>
39 #include <QTimerEvent>
40 #include <QVariant>
41 
42 #include <qwebdatabase.h>
43 #include <qwebelement.h>
44 #include <qwebframe.h>
45 #include <qwebhistory.h>
46 #include <qwebpage.h>
47 #include <qwebsecurityorigin.h>
48 
49 class QWebFrame;
50 class DumpRenderTreeSupportQt;
51 namespace WebCore {
52     class DumpRenderTree;
53 }
54 class LayoutTestController : public QObject {
55     Q_OBJECT
56     Q_PROPERTY(int webHistoryItemCount READ webHistoryItemCount)
57     Q_PROPERTY(int workerThreadCount READ workerThreadCount)
58     Q_PROPERTY(bool globalFlag READ globalFlag WRITE setGlobalFlag)
59 public:
60     LayoutTestController(WebCore::DumpRenderTree* drt);
61 
shouldDumpAsText()62     bool shouldDumpAsText() const { return m_textDump; }
shouldDumpBackForwardList()63     bool shouldDumpBackForwardList() const { return m_dumpBackForwardList; }
shouldDumpChildrenAsText()64     bool shouldDumpChildrenAsText() const { return m_dumpChildrenAsText; }
shouldDumpChildFrameScrollPositions()65     bool shouldDumpChildFrameScrollPositions() const { return m_dumpChildFrameScrollPositions; }
shouldDumpDatabaseCallbacks()66     bool shouldDumpDatabaseCallbacks() const { return m_dumpDatabaseCallbacks; }
shouldDumpApplicationCacheDelegateCallbacks()67     bool shouldDumpApplicationCacheDelegateCallbacks() const { return m_dumpApplicationCacheDelegateCallbacks; }
shouldDumpStatusCallbacks()68     bool shouldDumpStatusCallbacks() const { return m_dumpStatusCallbacks; }
shouldWaitUntilDone()69     bool shouldWaitUntilDone() const { return m_waitForDone; }
shouldHandleErrorPages()70     bool shouldHandleErrorPages() const { return m_handleErrorPages; }
canOpenWindows()71     bool canOpenWindows() const { return m_canOpenWindows; }
shouldDumpTitleChanges()72     bool shouldDumpTitleChanges() const { return m_dumpTitleChanges; }
waitForPolicy()73     bool waitForPolicy() const { return m_waitForPolicy; }
ignoreReqestForPermission()74     bool ignoreReqestForPermission() const { return m_ignoreDesktopNotification; }
isPrinting()75     bool isPrinting() { return m_isPrinting; }
76 
77     void reset();
78 
79     static const unsigned int maxViewWidth;
80     static const unsigned int maxViewHeight;
81 
82 protected:
83     void timerEvent(QTimerEvent*);
84 
85 signals:
86     void done();
87 
88     void showPage();
89     void hidePage();
90     void geolocationPermissionSet();
91 
92 public slots:
93     void maybeDump(bool ok);
dumpAsText()94     void dumpAsText() { m_textDump = true; }
dumpChildFramesAsText()95     void dumpChildFramesAsText() { m_dumpChildrenAsText = true; }
dumpChildFrameScrollPositions()96     void dumpChildFrameScrollPositions() { m_dumpChildFrameScrollPositions = true; }
dumpDatabaseCallbacks()97     void dumpDatabaseCallbacks() { m_dumpDatabaseCallbacks = true; }
dumpApplicationCacheDelegateCallbacks()98     void dumpApplicationCacheDelegateCallbacks() { m_dumpApplicationCacheDelegateCallbacks = true;}
dumpStatusCallbacks()99     void dumpStatusCallbacks() { m_dumpStatusCallbacks = true; }
setCanOpenWindows()100     void setCanOpenWindows() { m_canOpenWindows = true; }
setPrinting()101     void setPrinting() { m_isPrinting = true; }
102     void waitUntilDone();
103     QString counterValueForElementById(const QString& id);
104     int webHistoryItemCount();
105     void keepWebHistory();
106     void notifyDone();
dumpBackForwardList()107     void dumpBackForwardList() { m_dumpBackForwardList = true; }
globalFlag()108     bool globalFlag() const { return m_globalFlag; }
setGlobalFlag(bool flag)109     void setGlobalFlag(bool flag) { m_globalFlag = flag; }
handleErrorPages()110     void handleErrorPages() { m_handleErrorPages = true; }
111     void dumpEditingCallbacks();
112     void dumpFrameLoadCallbacks();
113     void dumpUserGestureInFrameLoadCallbacks();
114     void dumpResourceLoadCallbacks();
115     void dumpResourceResponseMIMETypes();
116     void dumpHistoryCallbacks();
117     void dumpConfigurationForViewport(int deviceDPI, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight);
118     void setWillSendRequestReturnsNullOnRedirect(bool enabled);
119     void setWillSendRequestReturnsNull(bool enabled);
120     void setWillSendRequestClearHeader(const QStringList& headers);
121     void queueBackNavigation(int howFarBackward);
122     void queueForwardNavigation(int howFarForward);
123     void queueLoad(const QString& url, const QString& target = QString());
124     void queueLoadHTMLString(const QString& content, const QString& baseURL = QString(), const QString& failingURL = QString());
125     void queueReload();
126     void queueLoadingScript(const QString& script);
127     void queueNonLoadingScript(const QString& script);
128     void provisionalLoad();
129     void setCloseRemainingWindowsWhenComplete(bool = false) {}
130     int windowCount();
131     void grantDesktopNotificationPermission(const QString& origin);
132     void ignoreDesktopNotificationPermissionRequests();
133     bool checkDesktopNotificationPermission(const QString& origin);
134     void simulateDesktopNotificationClick(const QString& title);
135     void display();
136     void clearBackForwardList();
137     QString pathToLocalResource(const QString& url);
dumpTitleChanges()138     void dumpTitleChanges() { m_dumpTitleChanges = true; }
139     QString encodeHostName(const QString& host);
140     QString decodeHostName(const QString& host);
dumpSelectionRect()141     void dumpSelectionRect() const {}
142     void setDeveloperExtrasEnabled(bool);
143     void setAsynchronousSpellCheckingEnabled(bool);
144     void showWebInspector();
145     void closeWebInspector();
146     void evaluateInWebInspector(long callId, const QString& script);
147     void removeAllVisitedLinks();
148 
149     void setMediaType(const QString& type);
150     void setFrameFlatteningEnabled(bool enable);
151     void setAllowUniversalAccessFromFileURLs(bool enable);
152     void setAllowFileAccessFromFileURLs(bool enable);
153     void setAppCacheMaximumSize(unsigned long long quota);
154     void setJavaScriptProfilingEnabled(bool enable);
155     void setTimelineProfilingEnabled(bool enable);
156     void setFixedContentsSize(int width, int height);
157     void setPrivateBrowsingEnabled(bool enable);
158     void setSpatialNavigationEnabled(bool enabled);
159     void setPluginsEnabled(bool flag);
160     void setPopupBlockingEnabled(bool enable);
161     void setPOSIXLocale(const QString& locale);
resetLoadFinished()162     void resetLoadFinished() { m_loadFinished = false; }
163     void setWindowIsKey(bool isKey);
164     void setMainFrameIsFirstResponder(bool isFirst);
165     void setDeferMainResourceDataLoad(bool);
166     void setJavaScriptCanAccessClipboard(bool enable);
167     void setXSSAuditorEnabled(bool enable);
168     void setCaretBrowsingEnabled(bool enable);
169     void setViewModeMediaFeature(const QString& mode);
170     void setSmartInsertDeleteEnabled(bool enable);
171     void setSelectTrailingWhitespaceEnabled(bool enable);
172     void execCommand(const QString& name, const QString& value = QString());
173     bool isCommandEnabled(const QString& name) const;
174     bool findString(const QString& string, const QStringList& optionArray);
175 
176     bool pauseAnimationAtTimeOnElementWithId(const QString& animationName, double time, const QString& elementId);
177     bool pauseTransitionAtTimeOnElementWithId(const QString& propertyName, double time, const QString& elementId);
178     bool sampleSVGAnimationForElementAtTime(const QString& animationId, double time, const QString& elementId);
179     bool elementDoesAutoCompleteForElementWithId(const QString& elementId);
180 
181     unsigned numberOfActiveAnimations() const;
182     void suspendAnimations() const;
183     void resumeAnimations() const;
184 
185     void addOriginAccessWhitelistEntry(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains);
186     void removeOriginAccessWhitelistEntry(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains);
187 
188     void dispatchPendingLoadRequests();
189     void disableImageLoading();
190 
191     void clearAllApplicationCaches();
192     void clearApplicationCacheForOrigin(const QString& url);
193     void setApplicationCacheOriginQuota(unsigned long long quota);
194     QStringList originsWithApplicationCache();
195 
196     void setDatabaseQuota(int size);
197     void clearAllDatabases();
198     void setIconDatabaseEnabled(bool enable);
199 
200     void setCustomPolicyDelegate(bool enabled, bool permissive = false);
201     void waitForPolicyDelegate();
202 
203     void overridePreference(const QString& name, const QVariant& value);
204     void setUserStyleSheetLocation(const QString& url);
205     void setUserStyleSheetEnabled(bool enabled);
206     void setDomainRelaxationForbiddenForURLScheme(bool forbidden, const QString& scheme);
207     int workerThreadCount();
208     int pageNumberForElementById(const QString& id, float width = 0, float height = 0);
209     int numberOfPages(float width = maxViewWidth, float height = maxViewHeight);
210     bool callShouldCloseOnWebView();
211     // For now, this is a no-op. This may change depending on outcome of
212     // https://bugs.webkit.org/show_bug.cgi?id=33333
setCallCloseOnWebViews()213     void setCallCloseOnWebViews() {}
214     // This is a no-op - it allows us to pass
215     // plugins/get-url-that-the-resource-load-delegate-will-disallow.html
216     // which is a Mac-specific test.
addDisallowedURL(const QString &)217     void addDisallowedURL(const QString&) {}
218 
219     void setMockDeviceOrientation(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma);
220 
221     void setMockGeolocationError(int code, const QString& message);
222     void setMockGeolocationPosition(double latitude, double longitude, double accuracy);
223     void setGeolocationPermission(bool allow);
224     int numberOfPendingGeolocationPermissionRequests();
isGeolocationPermissionSet()225     bool isGeolocationPermissionSet() const { return m_isGeolocationPermissionSet; }
geolocationPermission()226     bool geolocationPermission() const { return m_geolocationPermission; }
227 
228     void addMockSpeechInputResult(const QString& result, double confidence, const QString& language);
229 
230     // Empty stub method to keep parity with object model exposed by global LayoutTestController.
abortModal()231     void abortModal() {}
232     bool hasSpellingMarker(int from, int length);
233 
234     QVariantList nodesFromRect(const QWebElement& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping);
235 
236     void addURLToRedirect(const QString& origin, const QString& destination);
237 
238     /*
239         Policy values: 'on', 'auto' or 'off'.
240         Orientation values: 'vertical' or 'horizontal'.
241     */
242     void setScrollbarPolicy(const QString& orientation, const QString& policy);
243 
244     QString markerTextForListItem(const QWebElement& listItem);
245     QVariantMap computedStyleIncludingVisitedInfo(const QWebElement& element) const;
246 
247     // Simulate a request an embedding application could make, populating per-session credential storage.
248     void authenticateSession(const QString& url, const QString& username, const QString& password);
249 
250     void setEditingBehavior(const QString& editingBehavior);
251 
252     QVariant shadowRoot(const QWebElement&);
253 
254     void evaluateScriptInIsolatedWorld(int worldID, const QString& script);
255     bool isPageBoxVisible(int pageIndex);
256     QString pageSizeAndMarginsInPixels(int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft);
257     QString pageProperty(const QString& propertyName, int pageNumber);
258     void addUserStyleSheet(const QString& sourceCode);
259 
260     void setMinimumTimerInterval(double);
261 
262     void originsWithLocalStorage();
263     void deleteAllLocalStorage();
264     void deleteLocalStorageForOrigin(const QString& originIdentifier);
265     void observeStorageTrackerNotifications(unsigned number);
266     void syncLocalStorage();
267 
268 private slots:
269     void processWork();
270 
271 private:
272     void setGeolocationPermissionCommon(bool allow);
273 
274 private:
275     bool m_hasDumped;
276     bool m_textDump;
277     bool m_dumpBackForwardList;
278     bool m_dumpChildrenAsText;
279     bool m_dumpChildFrameScrollPositions;
280     bool m_canOpenWindows;
281     bool m_waitForDone;
282     bool m_dumpTitleChanges;
283     bool m_dumpDatabaseCallbacks;
284     bool m_dumpApplicationCacheDelegateCallbacks;
285     bool m_dumpStatusCallbacks;
286     bool m_waitForPolicy;
287     bool m_handleErrorPages;
288     bool m_loadFinished;
289     bool m_globalFlag;
290     bool m_userStyleSheetEnabled;
291     bool m_isGeolocationPermissionSet;
292     bool m_isPrinting;
293     bool m_geolocationPermission;
294 
295     QUrl m_userStyleSheetLocation;
296     QBasicTimer m_timeoutTimer;
297     QWebFrame* m_topLoadingFrame;
298     WebCore::DumpRenderTree* m_drt;
299     QWebHistory* m_webHistory;
300     QStringList m_desktopNotificationAllowedOrigins;
301     bool m_ignoreDesktopNotification;
302 };
303 
304 #endif // LayoutTestControllerQt_h
305