1 /* 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> 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 DumpRenderTreeQt_h 31 #define DumpRenderTreeQt_h 32 33 #include <QList> 34 #include <QNetworkAccessManager> 35 #include <QObject> 36 #include <QTextStream> 37 #include <QSocketNotifier> 38 39 #ifndef QT_NO_OPENSSL 40 #include <QSslError> 41 #endif 42 43 #include <qwebframe.h> 44 #include <qwebinspector.h> 45 #include <qwebpage.h> 46 #include <qwebview.h> 47 48 QT_BEGIN_NAMESPACE 49 class QUrl; 50 class QFile; 51 QT_END_NAMESPACE 52 53 class QWebFrame; 54 55 class LayoutTestController; 56 class EventSender; 57 class TextInputController; 58 class GCController; 59 60 namespace WebCore { 61 62 class WebPage; 63 64 class DumpRenderTree : public QObject { 65 Q_OBJECT 66 67 public: 68 DumpRenderTree(); 69 virtual ~DumpRenderTree(); 70 71 // Initialize in single-file mode. 72 void open(const QUrl& url); 73 setTextOutputEnabled(bool enable)74 void setTextOutputEnabled(bool enable) { m_enableTextOutput = enable; } isTextOutputEnabled()75 bool isTextOutputEnabled() { return m_enableTextOutput; } 76 setSingleFileMode(bool flag)77 void setSingleFileMode(bool flag) { m_singleFileMode = flag; } isSingleFileMode()78 bool isSingleFileMode() { return m_singleFileMode; } 79 80 void setDumpPixels(bool); 81 82 void closeRemainingWindows(); 83 void resetToConsistentStateBeforeTesting(); 84 layoutTestController()85 LayoutTestController *layoutTestController() const { return m_controller; } eventSender()86 EventSender *eventSender() const { return m_eventSender; } textInputController()87 TextInputController *textInputController() const { return m_textInputController; } 88 89 QWebPage *createWindow(); 90 int windowCount() const; 91 92 void switchFocus(bool focused); 93 webPage()94 WebPage *webPage() const { return m_page; } 95 96 97 #if defined(Q_WS_X11) 98 static void initializeFonts(); 99 #endif 100 101 public Q_SLOTS: 102 void initJSObjects(); 103 104 void readLine(); 105 void processLine(const QString&); 106 107 void dump(); 108 void titleChanged(const QString &s); 109 void connectFrame(QWebFrame *frame); 110 void dumpDatabaseQuota(QWebFrame* frame, const QString& dbName); 111 void statusBarMessage(const QString& message); 112 void windowCloseRequested(); 113 114 Q_SIGNALS: 115 void quit(); 116 void ready(); 117 118 private Q_SLOTS: 119 void showPage(); 120 void hidePage(); 121 122 private: 123 QString dumpFramesAsText(QWebFrame* frame); 124 QString dumpBackForwardList(); 125 LayoutTestController *m_controller; 126 127 bool m_dumpPixels; 128 QString m_expectedHash; 129 130 WebPage *m_page; 131 QWebView* m_mainView; 132 133 EventSender *m_eventSender; 134 TextInputController *m_textInputController; 135 GCController* m_gcController; 136 137 QFile *m_stdin; 138 139 QList<QObject*> windows; 140 bool m_enableTextOutput; 141 bool m_singleFileMode; 142 }; 143 144 class NetworkAccessManager : public QNetworkAccessManager { 145 Q_OBJECT 146 public: 147 NetworkAccessManager(QObject* parent); 148 149 private slots: 150 #ifndef QT_NO_OPENSSL 151 void sslErrorsEncountered(QNetworkReply*, const QList<QSslError>&); 152 #endif 153 }; 154 155 class WebPage : public QWebPage { 156 Q_OBJECT 157 public: 158 WebPage(QObject* parent, DumpRenderTree*); 159 virtual ~WebPage(); 160 QWebInspector* webInspector(); 161 162 QWebPage *createWindow(QWebPage::WebWindowType); 163 164 void javaScriptAlert(QWebFrame *frame, const QString& message); 165 void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID); 166 bool javaScriptConfirm(QWebFrame *frame, const QString& msg); 167 bool javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString* result); 168 169 void resetSettings(); 170 171 virtual bool supportsExtension(QWebPage::Extension extension) const; 172 virtual bool extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output); 173 174 QObject* createPlugin(const QString&, const QUrl&, const QStringList&, const QStringList&); 175 176 public slots: shouldInterruptJavaScript()177 bool shouldInterruptJavaScript() { return false; } 178 179 protected: 180 bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, NavigationType type); isTextOutputEnabled()181 bool isTextOutputEnabled() { return m_drt->isTextOutputEnabled(); } 182 183 private slots: setViewGeometry(const QRect & r)184 void setViewGeometry(const QRect &r) 185 { 186 QWidget *v = view(); 187 if (v) 188 v->setGeometry(r); 189 } 190 private: 191 QWebInspector* m_webInspector; 192 DumpRenderTree *m_drt; 193 }; 194 195 } 196 197 #endif 198