WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.h
changeset 2 303757a437d3
parent 0 4f2f89ce4247
equal deleted inserted replaced
0:4f2f89ce4247 2:303757a437d3
     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 "../../../WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h"
       
    44 #include <qgraphicsview.h>
       
    45 #include <qgraphicswebview.h>
       
    46 #include <qwebframe.h>
       
    47 #include <qwebinspector.h>
       
    48 #include <qwebpage.h>
       
    49 #include <qwebview.h>
       
    50 
       
    51 QT_BEGIN_NAMESPACE
       
    52 class QUrl;
       
    53 class QFile;
       
    54 QT_END_NAMESPACE
       
    55 
       
    56 class QWebFrame;
       
    57 
       
    58 class LayoutTestController;
       
    59 class DumpRenderTreeSupportQt;
       
    60 class EventSender;
       
    61 class TextInputController;
       
    62 class GCController;
       
    63 
       
    64 namespace WebCore {
       
    65 
       
    66 class WebPage;
       
    67 class NetworkAccessManager;
       
    68 
       
    69 class DumpRenderTree : public QObject {
       
    70 Q_OBJECT
       
    71 
       
    72 public:
       
    73     DumpRenderTree();
       
    74     virtual ~DumpRenderTree();
       
    75 
       
    76     // Initialize in single-file mode.
       
    77     void open(const QUrl& url);
       
    78 
       
    79     void setTextOutputEnabled(bool enable) { m_enableTextOutput = enable; }
       
    80     bool isTextOutputEnabled() { return m_enableTextOutput; }
       
    81 
       
    82     void setSingleFileMode(bool flag) { m_singleFileMode = flag; }
       
    83     bool isSingleFileMode() { return m_singleFileMode; }
       
    84 
       
    85     void setGraphicsBased(bool flag) { m_graphicsBased = flag; }
       
    86     bool isGraphicsBased() { return m_graphicsBased; }
       
    87 
       
    88     void setDumpPixels(bool);
       
    89 
       
    90     void closeRemainingWindows();
       
    91     void resetToConsistentStateBeforeTesting();
       
    92 
       
    93     LayoutTestController *layoutTestController() const { return m_controller; }
       
    94     EventSender *eventSender() const { return m_eventSender; }
       
    95     TextInputController *textInputController() const { return m_textInputController; }
       
    96     QString persistentStoragePath() const { return m_persistentStoragePath; }
       
    97     NetworkAccessManager *networkAccessManager() const { return m_networkAccessManager; }
       
    98 
       
    99     QWebPage *createWindow();
       
   100     int windowCount() const;
       
   101 
       
   102     void switchFocus(bool focused);
       
   103 
       
   104     WebPage *webPage() const { return m_page; }
       
   105 
       
   106 #if defined(Q_WS_X11)
       
   107     static void initializeFonts();
       
   108 #endif
       
   109 
       
   110 public Q_SLOTS:
       
   111     void initJSObjects();
       
   112 
       
   113     void readLine();
       
   114     void processLine(const QString&);
       
   115 
       
   116     void dump();
       
   117     void titleChanged(const QString &s);
       
   118     void connectFrame(QWebFrame *frame);
       
   119     void dumpDatabaseQuota(QWebFrame* frame, const QString& dbName);
       
   120     void statusBarMessage(const QString& message);
       
   121     void windowCloseRequested();
       
   122 
       
   123 Q_SIGNALS:
       
   124     void quit();
       
   125     void ready();
       
   126 
       
   127 private Q_SLOTS:
       
   128     void showPage();
       
   129     void hidePage();
       
   130     void dryRunPrint(QWebFrame*);
       
   131 
       
   132 private:
       
   133     QString dumpFramesAsText(QWebFrame* frame);
       
   134     QString dumpBackForwardList(QWebPage* page);
       
   135     QString dumpFrameScrollPosition(QWebFrame* frame);
       
   136     LayoutTestController *m_controller;
       
   137 
       
   138     bool m_dumpPixels;
       
   139     QString m_expectedHash;
       
   140 
       
   141     WebPage *m_page;
       
   142     QWidget* m_mainView;
       
   143 
       
   144     EventSender *m_eventSender;
       
   145     TextInputController *m_textInputController;
       
   146     GCController* m_gcController;
       
   147     NetworkAccessManager* m_networkAccessManager;
       
   148 
       
   149     QFile *m_stdin;
       
   150 
       
   151     QList<QObject*> windows;
       
   152     bool m_enableTextOutput;
       
   153     bool m_singleFileMode;
       
   154     bool m_graphicsBased;
       
   155     QString m_persistentStoragePath;
       
   156 };
       
   157 
       
   158 class NetworkAccessManager : public QNetworkAccessManager {
       
   159     Q_OBJECT
       
   160 public:
       
   161     NetworkAccessManager(QObject* parent);
       
   162 
       
   163 private slots:
       
   164 #ifndef QT_NO_OPENSSL
       
   165     void sslErrorsEncountered(QNetworkReply*, const QList<QSslError>&);
       
   166 #endif
       
   167 };
       
   168 
       
   169 class WebPage : public QWebPage {
       
   170     Q_OBJECT
       
   171 public:
       
   172     WebPage(QObject* parent, DumpRenderTree*);
       
   173     virtual ~WebPage();
       
   174     QWebInspector* webInspector();
       
   175     void closeWebInspector();
       
   176 
       
   177     QWebPage *createWindow(QWebPage::WebWindowType);
       
   178 
       
   179     void javaScriptAlert(QWebFrame *frame, const QString& message);
       
   180     void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID);
       
   181     bool javaScriptConfirm(QWebFrame *frame, const QString& msg);
       
   182     bool javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString* result);
       
   183 
       
   184     void resetSettings();
       
   185 
       
   186     virtual bool supportsExtension(QWebPage::Extension extension) const;
       
   187     virtual bool extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output);
       
   188 
       
   189     QObject* createPlugin(const QString&, const QUrl&, const QStringList&, const QStringList&);
       
   190 
       
   191 public slots:
       
   192     bool shouldInterruptJavaScript() { return false; }
       
   193     bool allowGeolocationRequest(QWebFrame *frame);
       
   194     void requestPermission(QWebFrame* frame, QWebPage::PermissionDomain domain);
       
   195     void checkPermission(QWebFrame* frame, QWebPage::PermissionDomain domain, QWebPage::PermissionPolicy& policy);
       
   196     void cancelRequestsForPermission(QWebFrame* frame, QWebPage::PermissionDomain domain);
       
   197 
       
   198 protected:
       
   199     bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, NavigationType type);
       
   200     bool isTextOutputEnabled() { return m_drt->isTextOutputEnabled(); }
       
   201 
       
   202 private slots:
       
   203     void setViewGeometry(const QRect&);
       
   204 
       
   205 private:
       
   206     QWebInspector* m_webInspector;
       
   207     DumpRenderTree *m_drt;
       
   208 };
       
   209 
       
   210 class WebViewGraphicsBased : public QGraphicsView {
       
   211     Q_OBJECT
       
   212 
       
   213 public:
       
   214     WebViewGraphicsBased(QWidget* parent);
       
   215     QGraphicsWebView* graphicsView() const { return m_item; }
       
   216     void setPage(QWebPage* page) { m_item->setPage(page); }
       
   217 
       
   218 private:
       
   219     QGraphicsWebView* m_item;
       
   220 };
       
   221 
       
   222 }
       
   223 
       
   224 #endif