DumpRenderTreeQt.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. #ifndef DumpRenderTreeQt_h
  30. #define DumpRenderTreeQt_h
  31. #include <QList>
  32. #include <QNetworkAccessManager>
  33. #include <QObject>
  34. #include <QTextStream>
  35. #include <QSocketNotifier>
  36. #ifndef QT_NO_OPENSSL
  37. #include <QSslError>
  38. #endif
  39. #include "DumpRenderTreeSupportQt.h"
  40. #include "TestRunner.h"
  41. #include <qgraphicsview.h>
  42. #include <qgraphicswebview.h>
  43. #include <qwebframe.h>
  44. #include <qwebinspector.h>
  45. #include <qwebpage.h>
  46. #include <qwebview.h>
  47. #include <wtf/RefPtr.h>
  48. QT_BEGIN_NAMESPACE
  49. class QUrl;
  50. class QFile;
  51. QT_END_NAMESPACE
  52. class QWebFrameAdapter;
  53. class QWebPageAdapter;
  54. class TestRunnerQt;
  55. class DumpRenderTreeSupportQt;
  56. class EventSender;
  57. class TextInputController;
  58. class GCController;
  59. class WebPage;
  60. class NetworkAccessManager;
  61. class DumpRenderTree : public QObject {
  62. Q_OBJECT
  63. public:
  64. DumpRenderTree();
  65. virtual ~DumpRenderTree();
  66. static DumpRenderTree* instance();
  67. // Initialize in single-file mode.
  68. void open(const QUrl& url);
  69. void setTextOutputEnabled(bool enable) { m_enableTextOutput = enable; }
  70. bool isTextOutputEnabled() { return m_enableTextOutput; }
  71. void setGraphicsBased(bool flag) { m_graphicsBased = flag; }
  72. bool isGraphicsBased() { return m_graphicsBased; }
  73. void closeRemainingWindows();
  74. void resetToConsistentStateBeforeTesting(const QUrl&);
  75. TestRunnerQt *testRunner() const { return m_controller; }
  76. TestRunner *jscTestRunner() const { return m_jscController.get(); }
  77. EventSender *eventSender() const { return m_eventSender; }
  78. TextInputController *textInputController() const { return m_textInputController; }
  79. QString persistentStoragePath() const { return m_persistentStoragePath; }
  80. NetworkAccessManager *networkAccessManager() const { return m_networkAccessManager; }
  81. QWebPage *createWindow();
  82. int windowCount() const;
  83. void switchFocus(bool focused);
  84. WebPage *webPage() const { return m_page; }
  85. QWebPageAdapter *pageAdapter() const;
  86. QWebFrameAdapter *mainFrameAdapter() const;
  87. QList<WebPage*> getAllPages() const;
  88. void processArgsLine(const QStringList&);
  89. void setRedirectOutputFileName(const QString& fileName) { m_redirectOutputFileName = fileName; }
  90. void setRedirectErrorFileName(const QString& fileName) { m_redirectErrorFileName = fileName; }
  91. void setTimeout(int);
  92. void setShouldTimeout(bool flag);
  93. void setShouldDumpPixelsForAllTests() { m_dumpPixelsForAllTests = true; }
  94. public Q_SLOTS:
  95. void initJSObjects();
  96. void readLine();
  97. void processLine(const QString&);
  98. void dump();
  99. void titleChanged(const QString &s);
  100. void connectFrame(QWebFrame *frame);
  101. void dumpDatabaseQuota(QWebFrame* frame, const QString& dbName);
  102. void dumpApplicationCacheQuota(QWebSecurityOrigin* origin, quint64 defaultOriginQuota, quint64 totalSpaceNeeded);
  103. void statusBarMessage(const QString& message);
  104. void windowCloseRequested();
  105. Q_SIGNALS:
  106. void quit();
  107. void ready();
  108. private Q_SLOTS:
  109. void showPage();
  110. void hidePage();
  111. void dryRunPrint(QWebFrame*);
  112. void loadNextTestInStandAloneMode();
  113. void geolocationPermissionSet();
  114. private:
  115. void setStandAloneMode(bool flag) { m_standAloneMode = flag; }
  116. bool isStandAloneMode() { return m_standAloneMode; }
  117. QString dumpFramesAsText(QWebFrame* frame);
  118. QString dumpBackForwardList(QWebPage* page);
  119. QString dumpFrameScrollPosition(QWebFrame* frame);
  120. TestRunnerQt *m_controller;
  121. RefPtr<TestRunner> m_jscController;
  122. bool m_dumpPixelsForCurrentTest;
  123. bool m_dumpPixelsForAllTests;
  124. QString m_expectedHash;
  125. QStringList m_standAloneModeTestList;
  126. WebPage *m_page;
  127. QWidget* m_mainView;
  128. EventSender *m_eventSender;
  129. TextInputController *m_textInputController;
  130. QScopedPointer<GCController> m_gcController;
  131. NetworkAccessManager* m_networkAccessManager;
  132. QFile *m_stdin;
  133. QList<QObject*> windows;
  134. bool m_enableTextOutput;
  135. bool m_standAloneMode;
  136. bool m_graphicsBased;
  137. QString m_persistentStoragePath;
  138. QString m_redirectOutputFileName;
  139. QString m_redirectErrorFileName;
  140. };
  141. class NetworkAccessManager : public QNetworkAccessManager {
  142. Q_OBJECT
  143. public:
  144. NetworkAccessManager(QObject* parent);
  145. private Q_SLOTS:
  146. #ifndef QT_NO_OPENSSL
  147. void sslErrorsEncountered(QNetworkReply*, const QList<QSslError>&);
  148. #endif
  149. };
  150. class WebPage : public QWebPage {
  151. Q_OBJECT
  152. public:
  153. WebPage(QObject* parent, DumpRenderTree*);
  154. virtual ~WebPage();
  155. QWebInspector* webInspector();
  156. void closeWebInspector();
  157. QWebPage *createWindow(QWebPage::WebWindowType);
  158. void javaScriptAlert(QWebFrame *frame, const QString& message);
  159. void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID);
  160. bool javaScriptConfirm(QWebFrame *frame, const QString& msg);
  161. bool javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString* result);
  162. void resetSettings();
  163. virtual bool supportsExtension(QWebPage::Extension extension) const;
  164. virtual bool extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output);
  165. QObject* createPlugin(const QString&, const QUrl&, const QStringList&, const QStringList&);
  166. void permissionSet(QWebPage::Feature feature);
  167. virtual bool shouldInterruptJavaScript() { return false; }
  168. public Q_SLOTS:
  169. void requestPermission(QWebFrame* frame, QWebPage::Feature feature);
  170. void cancelPermission(QWebFrame* frame, QWebPage::Feature feature);
  171. protected:
  172. bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, NavigationType type);
  173. bool isTextOutputEnabled() { return m_drt->isTextOutputEnabled(); }
  174. private Q_SLOTS:
  175. void setViewGeometry(const QRect&);
  176. private:
  177. QWebInspector* m_webInspector;
  178. QList<QWebFrame*> m_pendingGeolocationRequests;
  179. DumpRenderTree *m_drt;
  180. };
  181. class WebViewGraphicsBased : public QGraphicsView {
  182. Q_OBJECT
  183. public:
  184. WebViewGraphicsBased(QWidget* parent);
  185. QGraphicsWebView* graphicsView() const { return m_item; }
  186. void setPage(QWebPage* page) { m_item->setPage(page); }
  187. private:
  188. QGraphicsWebView* m_item;
  189. };
  190. #endif