2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 #ifndef DumpRenderTreeQt_h
31 #define DumpRenderTreeQt_h
34 #include <QNetworkAccessManager>
36 #include <QTextStream>
37 #include <QSocketNotifier>
43 #include "DumpRenderTreeSupportQt.h"
44 #include <qgraphicsview.h>
45 #include <qgraphicswebview.h>
46 #include <qwebframe.h>
47 #include <qwebinspector.h>
58 class LayoutTestController;
59 class DumpRenderTreeSupportQt;
61 class TextInputController;
63 class PlainTextController;
68 class NetworkAccessManager;
70 class DumpRenderTree : public QObject {
75 virtual ~DumpRenderTree();
77 // Initialize in single-file mode.
78 void open(const QUrl& url);
80 void setTextOutputEnabled(bool enable) { m_enableTextOutput = enable; }
81 bool isTextOutputEnabled() { return m_enableTextOutput; }
83 void setGraphicsBased(bool flag) { m_graphicsBased = flag; }
84 bool isGraphicsBased() { return m_graphicsBased; }
86 void setDumpPixels(bool);
88 void closeRemainingWindows();
89 void resetToConsistentStateBeforeTesting(const QUrl&);
91 LayoutTestController *layoutTestController() const { return m_controller; }
92 EventSender *eventSender() const { return m_eventSender; }
93 TextInputController *textInputController() const { return m_textInputController; }
94 QString persistentStoragePath() const { return m_persistentStoragePath; }
95 NetworkAccessManager *networkAccessManager() const { return m_networkAccessManager; }
97 QWebPage *createWindow();
98 int windowCount() const;
100 void switchFocus(bool focused);
102 WebPage *webPage() const { return m_page; }
103 QList<WebPage*> getAllPages() const;
105 #if defined(Q_WS_X11)
106 static void initializeFonts();
108 void processArgsLine(const QStringList&);
109 void setRedirectOutputFileName(const QString& fileName) { m_redirectOutputFileName = fileName; }
110 void setRedirectErrorFileName(const QString& fileName) { m_redirectErrorFileName = fileName; }
113 void initJSObjects();
116 void processLine(const QString&);
119 void titleChanged(const QString &s);
120 void connectFrame(QWebFrame *frame);
121 void dumpDatabaseQuota(QWebFrame* frame, const QString& dbName);
122 void dumpApplicationCacheQuota(QWebSecurityOrigin* origin, quint64 defaultOriginQuota, quint64 totalSpaceNeeded);
123 void statusBarMessage(const QString& message);
124 void windowCloseRequested();
133 void dryRunPrint(QWebFrame*);
134 void loadNextTestInStandAloneMode();
135 void geolocationPermissionSet();
138 void setStandAloneMode(bool flag) { m_standAloneMode = flag; }
139 bool isStandAloneMode() { return m_standAloneMode; }
141 QString dumpFramesAsText(QWebFrame* frame);
142 QString dumpBackForwardList(QWebPage* page);
143 QString dumpFrameScrollPosition(QWebFrame* frame);
144 LayoutTestController *m_controller;
147 QString m_expectedHash;
148 QStringList m_standAloneModeTestList;
153 EventSender *m_eventSender;
154 TextInputController *m_textInputController;
155 GCController* m_gcController;
156 PlainTextController* m_plainTextController;
157 NetworkAccessManager* m_networkAccessManager;
161 QList<QObject*> windows;
162 bool m_enableTextOutput;
163 bool m_standAloneMode;
164 bool m_graphicsBased;
165 QString m_persistentStoragePath;
166 QString m_redirectOutputFileName;
167 QString m_redirectErrorFileName;
170 class NetworkAccessManager : public QNetworkAccessManager {
173 NetworkAccessManager(QObject* parent);
176 #ifndef QT_NO_OPENSSL
177 void sslErrorsEncountered(QNetworkReply*, const QList<QSslError>&);
181 class WebPage : public QWebPage {
184 WebPage(QObject* parent, DumpRenderTree*);
186 QWebInspector* webInspector();
187 void closeWebInspector();
189 QWebPage *createWindow(QWebPage::WebWindowType);
191 void javaScriptAlert(QWebFrame *frame, const QString& message);
192 void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID);
193 bool javaScriptConfirm(QWebFrame *frame, const QString& msg);
194 bool javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString* result);
196 void resetSettings();
198 virtual bool supportsExtension(QWebPage::Extension extension) const;
199 virtual bool extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output);
201 QObject* createPlugin(const QString&, const QUrl&, const QStringList&, const QStringList&);
203 void permissionSet(QWebPage::Feature feature);
206 bool shouldInterruptJavaScript() { return false; }
207 void requestPermission(QWebFrame* frame, QWebPage::Feature feature);
208 void cancelPermission(QWebFrame* frame, QWebPage::Feature feature);
211 bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, NavigationType type);
212 bool isTextOutputEnabled() { return m_drt->isTextOutputEnabled(); }
215 void setViewGeometry(const QRect&);
218 QWebInspector* m_webInspector;
219 QList<QWebFrame*> m_pendingGeolocationRequests;
220 DumpRenderTree *m_drt;
223 class WebViewGraphicsBased : public QGraphicsView {
227 WebViewGraphicsBased(QWidget* parent);
228 QGraphicsWebView* graphicsView() const { return m_item; }
229 void setPage(QWebPage* page) { m_item->setPage(page); }
232 QGraphicsWebView* m_item;