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 <qwebframe.h> 44 #include <qwebhistory.h> 45 #include <qwebpage.h> 46 #include <qwebsecurityorigin.h> 47 48 class QWebFrame; 49 namespace WebCore { 50 class DumpRenderTree; 51 } 52 class LayoutTestController : public QObject { 53 Q_OBJECT 54 Q_PROPERTY(int webHistoryItemCount READ webHistoryItemCount) 55 Q_PROPERTY(int workerThreadCount READ workerThreadCount) 56 Q_PROPERTY(bool globalFlag READ globalFlag WRITE setGlobalFlag) 57 public: 58 LayoutTestController(WebCore::DumpRenderTree* drt); 59 shouldDumpAsText()60 bool shouldDumpAsText() const { return m_textDump; } shouldDumpBackForwardList()61 bool shouldDumpBackForwardList() const { return m_dumpBackForwardList; } shouldDumpChildrenAsText()62 bool shouldDumpChildrenAsText() const { return m_dumpChildrenAsText; } shouldDumpDatabaseCallbacks()63 bool shouldDumpDatabaseCallbacks() const { return m_dumpDatabaseCallbacks; } shouldDumpStatusCallbacks()64 bool shouldDumpStatusCallbacks() const { return m_dumpStatusCallbacks; } shouldWaitUntilDone()65 bool shouldWaitUntilDone() const { return m_waitForDone; } shouldHandleErrorPages()66 bool shouldHandleErrorPages() const { return m_handleErrorPages; } canOpenWindows()67 bool canOpenWindows() const { return m_canOpenWindows; } shouldDumpTitleChanges()68 bool shouldDumpTitleChanges() const { return m_dumpTitleChanges; } waitForPolicy()69 bool waitForPolicy() const { return m_waitForPolicy; } 70 71 void reset(); 72 73 protected: 74 void timerEvent(QTimerEvent*); 75 76 signals: 77 void done(); 78 79 void showPage(); 80 void hidePage(); 81 82 public slots: 83 void maybeDump(bool ok); dumpAsText()84 void dumpAsText() { m_textDump = true; } dumpChildFramesAsText()85 void dumpChildFramesAsText() { m_dumpChildrenAsText = true; } dumpDatabaseCallbacks()86 void dumpDatabaseCallbacks() { m_dumpDatabaseCallbacks = true; } dumpStatusCallbacks()87 void dumpStatusCallbacks() { m_dumpStatusCallbacks = true; } setCanOpenWindows()88 void setCanOpenWindows() { m_canOpenWindows = true; } 89 void waitUntilDone(); 90 QString counterValueForElementById(const QString& id); 91 int webHistoryItemCount(); 92 void keepWebHistory(); 93 void notifyDone(); dumpBackForwardList()94 void dumpBackForwardList() { m_dumpBackForwardList = true; } globalFlag()95 bool globalFlag() const { return m_globalFlag; } setGlobalFlag(bool flag)96 void setGlobalFlag(bool flag) { m_globalFlag = flag; } handleErrorPages()97 void handleErrorPages() { m_handleErrorPages = true; } 98 void dumpEditingCallbacks(); 99 void dumpFrameLoadCallbacks(); 100 void dumpResourceLoadCallbacks(); 101 void queueBackNavigation(int howFarBackward); 102 void queueForwardNavigation(int howFarForward); 103 void queueLoad(const QString& url, const QString& target = QString()); 104 void queueReload(); 105 void queueLoadingScript(const QString& script); 106 void queueNonLoadingScript(const QString& script); 107 void provisionalLoad(); 108 void setCloseRemainingWindowsWhenComplete(bool = false) {} 109 int windowCount(); 110 void display(); 111 void clearBackForwardList(); 112 QString pathToLocalResource(const QString& url); dumpTitleChanges()113 void dumpTitleChanges() { m_dumpTitleChanges = true; } 114 QString encodeHostName(const QString& host); 115 QString decodeHostName(const QString& host); dumpSelectionRect()116 void dumpSelectionRect() const {} 117 void showWebInspector(); 118 void hideWebInspector(); 119 120 void setFrameSetFlatteningEnabled(bool enable); 121 void setAllowUniversalAccessFromFileURLs(bool enable); 122 void setJavaScriptProfilingEnabled(bool enable); 123 void setFixedContentsSize(int width, int height); 124 void setPrivateBrowsingEnabled(bool enable); 125 void setPopupBlockingEnabled(bool enable); 126 void setPOSIXLocale(const QString& locale); resetLoadFinished()127 void resetLoadFinished() { m_loadFinished = false; } 128 void setWindowIsKey(bool isKey); 129 void setMainFrameIsFirstResponder(bool isFirst); 130 void setXSSAuditorEnabled(bool enable); 131 132 bool pauseAnimationAtTimeOnElementWithId(const QString& animationName, double time, const QString& elementId); 133 bool pauseTransitionAtTimeOnElementWithId(const QString& propertyName, double time, const QString& elementId); 134 bool sampleSVGAnimationForElementAtTime(const QString& animationId, double time, const QString& elementId); 135 136 unsigned numberOfActiveAnimations() const; 137 138 void whiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains); 139 140 void dispatchPendingLoadRequests(); 141 void disableImageLoading(); 142 143 void setDatabaseQuota(int size); 144 void clearAllDatabases(); 145 146 void waitForPolicyDelegate(); 147 void overridePreference(const QString& name, const QVariant& value); 148 void setUserStyleSheetLocation(const QString& url); 149 void setUserStyleSheetEnabled(bool enabled); 150 void setDomainRelaxationForbiddenForURLScheme(bool forbidden, const QString& scheme); 151 int workerThreadCount(); 152 int pageNumberForElementById(const QString& id, float width = 0, float height = 0); 153 154 private slots: 155 void processWork(); 156 157 private: 158 bool m_hasDumped; 159 bool m_textDump; 160 bool m_dumpBackForwardList; 161 bool m_dumpChildrenAsText; 162 bool m_canOpenWindows; 163 bool m_waitForDone; 164 bool m_dumpTitleChanges; 165 bool m_dumpDatabaseCallbacks; 166 bool m_dumpStatusCallbacks; 167 bool m_waitForPolicy; 168 bool m_handleErrorPages; 169 bool m_loadFinished; 170 bool m_globalFlag; 171 172 QUrl m_userStyleSheetLocation; 173 QBasicTimer m_timeoutTimer; 174 QWebFrame* m_topLoadingFrame; 175 WebCore::DumpRenderTree* m_drt; 176 QWebHistory* m_webHistory; 177 }; 178 179 #endif // LayoutTestControllerQt_h 180