Home | History | Annotate | Download | only in qt
      1 /*
      2  * Copyright (C) 2006 Nikolas Zimmermann <zimmermann (at) 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 "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 class PlainTextController;
     64 
     65 namespace WebCore {
     66 
     67 class WebPage;
     68 class NetworkAccessManager;
     69 
     70 class DumpRenderTree : public QObject {
     71 Q_OBJECT
     72 
     73 public:
     74     DumpRenderTree();
     75     virtual ~DumpRenderTree();
     76 
     77     // Initialize in single-file mode.
     78     void open(const QUrl& url);
     79 
     80     void setTextOutputEnabled(bool enable) { m_enableTextOutput = enable; }
     81     bool isTextOutputEnabled() { return m_enableTextOutput; }
     82 
     83     void setGraphicsBased(bool flag) { m_graphicsBased = flag; }
     84     bool isGraphicsBased() { return m_graphicsBased; }
     85 
     86     void setDumpPixels(bool);
     87 
     88     void closeRemainingWindows();
     89     void resetToConsistentStateBeforeTesting(const QUrl&);
     90 
     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; }
     96 
     97     QWebPage *createWindow();
     98     int windowCount() const;
     99 
    100     void switchFocus(bool focused);
    101 
    102     WebPage *webPage() const { return m_page; }
    103     QList<WebPage*> getAllPages() const;
    104 
    105 #if defined(Q_WS_X11)
    106     static void initializeFonts();
    107 #endif
    108     void processArgsLine(const QStringList&);
    109     void setRedirectOutputFileName(const QString& fileName) { m_redirectOutputFileName = fileName; }
    110     void setRedirectErrorFileName(const QString& fileName) { m_redirectErrorFileName = fileName; }
    111 
    112 public Q_SLOTS:
    113     void initJSObjects();
    114 
    115     void readLine();
    116     void processLine(const QString&);
    117 
    118     void dump();
    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);
    123     void statusBarMessage(const QString& message);
    124     void windowCloseRequested();
    125 
    126 Q_SIGNALS:
    127     void quit();
    128     void ready();
    129 
    130 private Q_SLOTS:
    131     void showPage();
    132     void hidePage();
    133     void dryRunPrint(QWebFrame*);
    134     void loadNextTestInStandAloneMode();
    135     void geolocationPermissionSet();
    136 
    137 private:
    138     void setStandAloneMode(bool flag) { m_standAloneMode = flag; }
    139     bool isStandAloneMode() { return m_standAloneMode; }
    140 
    141     QString dumpFramesAsText(QWebFrame* frame);
    142     QString dumpBackForwardList(QWebPage* page);
    143     QString dumpFrameScrollPosition(QWebFrame* frame);
    144     LayoutTestController *m_controller;
    145 
    146     bool m_dumpPixels;
    147     QString m_expectedHash;
    148     QStringList m_standAloneModeTestList;
    149 
    150     WebPage *m_page;
    151     QWidget* m_mainView;
    152 
    153     EventSender *m_eventSender;
    154     TextInputController *m_textInputController;
    155     GCController* m_gcController;
    156     PlainTextController* m_plainTextController;
    157     NetworkAccessManager* m_networkAccessManager;
    158 
    159     QFile *m_stdin;
    160 
    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;
    168 };
    169 
    170 class NetworkAccessManager : public QNetworkAccessManager {
    171     Q_OBJECT
    172 public:
    173     NetworkAccessManager(QObject* parent);
    174 
    175 private slots:
    176 #ifndef QT_NO_OPENSSL
    177     void sslErrorsEncountered(QNetworkReply*, const QList<QSslError>&);
    178 #endif
    179 };
    180 
    181 class WebPage : public QWebPage {
    182     Q_OBJECT
    183 public:
    184     WebPage(QObject* parent, DumpRenderTree*);
    185     virtual ~WebPage();
    186     QWebInspector* webInspector();
    187     void closeWebInspector();
    188 
    189     QWebPage *createWindow(QWebPage::WebWindowType);
    190 
    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);
    195 
    196     void resetSettings();
    197 
    198     virtual bool supportsExtension(QWebPage::Extension extension) const;
    199     virtual bool extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output);
    200 
    201     QObject* createPlugin(const QString&, const QUrl&, const QStringList&, const QStringList&);
    202 
    203     void permissionSet(QWebPage::Feature feature);
    204 
    205 public slots:
    206     bool shouldInterruptJavaScript() { return false; }
    207     void requestPermission(QWebFrame* frame, QWebPage::Feature feature);
    208     void cancelPermission(QWebFrame* frame, QWebPage::Feature feature);
    209 
    210 protected:
    211     bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, NavigationType type);
    212     bool isTextOutputEnabled() { return m_drt->isTextOutputEnabled(); }
    213 
    214 private slots:
    215     void setViewGeometry(const QRect&);
    216 
    217 private:
    218     QWebInspector* m_webInspector;
    219     QList<QWebFrame*> m_pendingGeolocationRequests;
    220     DumpRenderTree *m_drt;
    221 };
    222 
    223 class WebViewGraphicsBased : public QGraphicsView {
    224     Q_OBJECT
    225 
    226 public:
    227     WebViewGraphicsBased(QWidget* parent);
    228     QGraphicsWebView* graphicsView() const { return m_item; }
    229     void setPage(QWebPage* page) { m_item->setPage(page); }
    230 
    231 private:
    232     QGraphicsWebView* m_item;
    233 };
    234 
    235 }
    236 
    237 #endif
    238