Comitted Adam's patch to improve DumpRenderTree for the Qt build.
authorhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Sep 2007 09:27:30 +0000 (09:27 +0000)
committerhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Sep 2007 09:27:30 +0000 (09:27 +0000)
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@25722 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKitQt/Api/qwebframe.cpp
WebKitQt/Api/qwebframe.h
WebKitQt/ChangeLog
WebKitQt/WebCoreSupport/FrameLoaderClientQt.cpp
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/DumpRenderTree.qtproj/DumpRenderTree.cpp
WebKitTools/DumpRenderTree/DumpRenderTree.qtproj/DumpRenderTree.h
WebKitTools/DumpRenderTree/DumpRenderTree.qtproj/jsobjects.cpp
WebKitTools/DumpRenderTree/DumpRenderTree.qtproj/jsobjects.h
WebKitTools/DumpRenderTree/DumpRenderTree.qtproj/main.cpp

index 8409e73..f1f6f2c 100644 (file)
@@ -51,6 +51,7 @@
 #include "bindings/runtime.h"
 #include "bindings/runtime_root.h"
 #include "kjs_proxy.h"
+#include "kjs_window.h"
 #include "kjs_binding.h"
 #include "ExecState.h"
 #include "object.h"
@@ -133,20 +134,19 @@ QWebFrame::~QWebFrame()
 
 void QWebFrame::addToJSWindowObject(const QByteArray &name, QObject *object)
 {
-    KJS::Bindings::RootObject *root = d->frame->bindingRootObject();
-    KJS::ExecState *exec = root->interpreter()->globalExec();
-    KJS::JSObject *rootObject = root->interpreter()->globalObject();
-    KJS::JSObject *window = rootObject->get(exec, KJS::Identifier("window"))->getObject();
-    if (!window) {
-        qDebug() << "Warning: couldn't get window object";
-        return;
-    }
-
-    KJS::JSObject *testController =
+      KJS::JSLock lock;
+      KJS::Window *window = KJS::Window::retrieveWindow(d->frame.get());
+      KJS::Bindings::RootObject *root = d->frame->bindingRootObject();
+      if (!window) {
+          qDebug() << "Warning: couldn't get window object";
+          return;
+      }
+
+      KJS::JSObject *runtimeObject =
         KJS::Bindings::Instance::createRuntimeObject(KJS::Bindings::Instance::QtLanguage,
                                                      object, root);
 
-    window->put(exec, KJS::Identifier(name.constData()), testController);
+      window->put(window->interpreter()->globalExec(), KJS::Identifier(name.constData()), runtimeObject);
 }
 
 
index 727873d..2a143de 100644 (file)
@@ -80,6 +80,7 @@ public Q_SLOTS:
 signals:
     void cleared();
     void loadDone(bool ok);
+    void provisionalLoad();
     void titleChanged(const QString &title);
     void hoveringOverLink(const QString &link, const QString &title);
 
index 48186d7..9eb9d7d 100644 (file)
@@ -1,3 +1,20 @@
+2007-09-25  Adam Treat  <treat@kde.org>
+
+        Reviewed by Simon and Lars.
+
+        Modifies the addToJSWindowObject to bind js objects using the built-in
+        kst_window class.  Make sure to protect the created runtime object from
+        garbage collection.
+
+        Adds a signal to QWebFrame to notify clients of the beginning of a
+        provisional load.  DRT needs this.
+
+        * Api/qwebframe.cpp:
+        (QWebFrame::addToJSWindowObject):
+        * Api/qwebframe.h:
+        * WebCoreSupport/FrameLoaderClientQt.cpp:
+        (WebCore::FrameLoaderClientQt::dispatchDidStartProvisionalLoad):
+
 2007-09-10  Qing Zhao  <qing@staikos.net>
 
         Reviewed by George Staikos.
index a202b4b..277b8ef 100644 (file)
@@ -294,7 +294,8 @@ void FrameLoaderClientQt::dispatchWillClose()
 
 void FrameLoaderClientQt::dispatchDidStartProvisionalLoad()
 {
-    // we're not interested in this neither I think
+    if (m_webFrame)
+        emit m_webFrame->provisionalLoad();
 }
 
 
index 5396e85..ed13777 100644 (file)
@@ -1,3 +1,54 @@
+2007-09-25  Adam Treat  <treat@kde.org>
+
+        Reviewed by Simon and Lars.
+
+        Refactors and cleans up Qt DRT member variable names, member variable
+        initialization, style fixes and general code cleanup.
+
+        Adds queueReload slot to LayoutTestController that some tests require.
+
+        Subclasses QWebFrame to make sure that all frames have an associated
+        LayoutTestController JS window object.
+
+        Takes advantage of new QWebFrame provisionalLoad signal to ensure frames
+        aren't dumped twice.
+
+        EOF fixes.
+
+        Together, this patch fixes some 20+ layout tests in QtWebKit.
+
+        * DumpRenderTree/DumpRenderTree.qtproj/DumpRenderTree.cpp:
+        (WebCore::WebFrame::WebFrame):
+        (WebCore::WebPage::WebPage):
+        (WebCore::WebPage::createFrame):
+        (WebCore::DumpRenderTree::DumpRenderTree):
+        (WebCore::DumpRenderTree::open):
+        (WebCore::DumpRenderTree::readStdin):
+        (WebCore::DumpRenderTree::initJSObjects):
+        (WebCore::DumpRenderTree::dump):
+        * DumpRenderTree/DumpRenderTree.qtproj/DumpRenderTree.h:
+        (WebCore::DumpRenderTree::layoutTestController):
+        (WebCore::DumpRenderTree::eventSender):
+        * DumpRenderTree/DumpRenderTree.qtproj/jsobjects.cpp:
+        (LayoutTestController::LayoutTestController):
+        (LayoutTestController::reset):
+        (LayoutTestController::maybeDump):
+        (LayoutTestController::waitUntilDone):
+        (LayoutTestController::notifyDone):
+        (LayoutTestController::queueReload):
+        (LayoutTestController::provisionalLoad):
+        (EventSender::EventSender):
+        (EventSender::mouseDown):
+        (EventSender::mouseUp):
+        (EventSender::mouseMoveTo):
+        (EventSender::frameUnderMouse):
+        * DumpRenderTree/DumpRenderTree.qtproj/jsobjects.h:
+        (LayoutTestController::isLoading):
+        (LayoutTestController::setLoading):
+        (LayoutTestController::dumpAsText):
+        * DumpRenderTree/DumpRenderTree.qtproj/main.cpp:
+        (main):
+
 2007-09-24  Kevin McCullough  <kmccullough@apple.com>
 
 
index 6fca5b5..19735b9 100644 (file)
@@ -50,14 +50,52 @@ namespace WebCore {
 const unsigned int maxViewWidth = 800;
 const unsigned int maxViewHeight = 600;
 
+class WebFrame : public QWebFrame {
+public:
+    WebFrame(QWebPage *parent, QWebFrameData *frameData)
+        : QWebFrame(parent, frameData) {}
+    WebFrame(QWebFrame *parent, QWebFrameData *frameData)
+        : QWebFrame(parent, frameData) {}
+};
+
 class WebPage : public QWebPage {
 public:
-    WebPage(QWidget *parent) : QWebPage(parent) {}
+    WebPage(QWidget *parent, DumpRenderTree *drt)
+        : QWebPage(parent), m_drt(drt) {}
+
+    QWebFrame *createFrame(QWebFrame *parentFrame, QWebFrameData *frameData);
 
     void javaScriptAlert(QWebFrame *frame, const QString& message);
     void javaScriptConsoleMessage(const QString& message, unsigned int lineNumber, const QString& sourceID);
+
+private:
+    DumpRenderTree *m_drt;
 };
 
+QWebFrame *WebPage::createFrame(QWebFrame *parentFrame, QWebFrameData *frameData)
+{
+    if (parentFrame) {
+        WebFrame *f = new WebFrame(parentFrame, frameData);
+        connect(f, SIGNAL(cleared()), m_drt, SLOT(initJSObjects()));
+        connect(f, SIGNAL(provisionalLoad()),
+                m_drt->layoutTestController(), SLOT(provisionalLoad()));
+        return f;
+    }
+    WebFrame *f = new WebFrame(this, frameData);
+    connect(f, SIGNAL(titleChanged(const QString&)),
+            SIGNAL(titleChanged(const QString&)));
+    connect(f, SIGNAL(hoveringOverLink(const QString&, const QString&)),
+            SIGNAL(hoveringOverLink(const QString&, const QString&)));
+
+    connect(f, SIGNAL(cleared()), m_drt, SLOT(initJSObjects()));
+    connect(f, SIGNAL(provisionalLoad()),
+            m_drt->layoutTestController(), SLOT(provisionalLoad()));
+    connect(f, SIGNAL(loadDone(bool)),
+            m_drt->layoutTestController(), SLOT(maybeDump(bool)));
+
+    return f;
+}
+
 void WebPage::javaScriptAlert(QWebFrame *frame, const QString& message)
 {
     fprintf(stdout, "ALERT: %s\n", message.toUtf8().constData());
@@ -70,29 +108,24 @@ void WebPage::javaScriptConsoleMessage(const QString& message, unsigned int line
 
 DumpRenderTree::DumpRenderTree()
     : m_stdin(0)
-    , m_notifier()
-    , m_loading(false)
+    , m_notifier(0)
 {
-    page = new WebPage(0);
-    page->resize(maxViewWidth, maxViewHeight);
-    frame = page->mainFrame();
-    frame->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-    frame->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-
     m_controller = new LayoutTestController();
-    QObject::connect(m_controller, SIGNAL(done()), this, SLOT(dump()), Qt::QueuedConnection);
-    QObject::connect(this, SIGNAL(quit()), qApp, SLOT(quit()), Qt::QueuedConnection);
-    QObject::connect(frame, SIGNAL(cleared()), this, SLOT(initJSObjects()));
-    QObject::connect(frame, SIGNAL(loadDone(bool)), this, SLOT(maybeDump(bool)));
+    connect(m_controller, SIGNAL(done()), this, SLOT(dump()), Qt::QueuedConnection);
 
-    m_eventSender = new EventSender(page);
-    
-//     page->resize(800, 800);
+    m_page = new WebPage(0, this);
+    m_page->resize(maxViewWidth, maxViewHeight);
+    m_page->mainFrame()->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    m_page->mainFrame()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+    m_eventSender = new EventSender(m_page);
+
+    QObject::connect(this, SIGNAL(quit()), qApp, SLOT(quit()), Qt::QueuedConnection);
 }
 
 DumpRenderTree::~DumpRenderTree()
 {
-    delete page;
+    delete m_page;
 
     delete m_stdin;
     delete m_notifier;
@@ -104,7 +137,7 @@ void DumpRenderTree::open()
         m_stdin = new QFile;
         m_stdin->open(stdin, QFile::ReadOnly);
     }
-    
+
     if (!m_notifier) {
         m_notifier = new QSocketNotifier(STDIN_FILENO, QSocketNotifier::Read);
         connect(m_notifier, SIGNAL(activated(int)), this, SLOT(readStdin(int)));
@@ -114,14 +147,11 @@ void DumpRenderTree::open()
 void DumpRenderTree::open(const QUrl& url)
 {
     resetJSObjects();
-    page->open(url);
+    m_page->open(url);
 }
 
 void DumpRenderTree::readStdin(int /* socket */)
 {
-    if (m_loading)
-        fprintf(stderr, "=========================== still loading\n");
-    
     // Read incoming data from stdin...
     QByteArray line = m_stdin->readLine();
     if (line.endsWith('\n'))
@@ -130,6 +160,7 @@ void DumpRenderTree::readStdin(int /* socket */)
     if (line.isEmpty())
         quit();
     open(QUrl(QString(line)));
+    fflush(stdout);
 }
 
 void DumpRenderTree::resetJSObjects()
@@ -139,19 +170,23 @@ void DumpRenderTree::resetJSObjects()
 
 void DumpRenderTree::initJSObjects()
 {
-    frame->addToJSWindowObject("layoutTestController", m_controller);    
-    frame->addToJSWindowObject("eventSender", m_eventSender);    
+    QWebFrame *frame = qobject_cast<QWebFrame*>(sender());
+    Q_ASSERT(frame);
+    frame->addToJSWindowObject("layoutTestController", m_controller);
+    frame->addToJSWindowObject("eventSender", m_eventSender);
 }
 
 void DumpRenderTree::dump()
 {
+    QWebFrame *frame = m_page->mainFrame();
+
     //fprintf(stderr, "    Dumping\n");
     if (!m_notifier) {
         // Dump markup in single file mode...
         QString markup = frame->markup();
         fprintf(stdout, "Source:\n\n%s\n", markup.toUtf8().constData());
     }
-    
+
     // Dump render text...
     QString renderDump;
     if (m_controller->shouldDumpAsText()) {
@@ -161,25 +196,20 @@ void DumpRenderTree::dump()
         renderDump = frame->renderTreeDump();
     }
     if (renderDump.isEmpty()) {
-        printf("ERROR: nil result from %s", m_controller->shouldDumpAsText() ? "[documentElement innerText]" : "[frame renderTreeAsExternalRepresentation]\n#EOF\n");
+        printf("ERROR: nil result from %s", m_controller->shouldDumpAsText() ? "[documentElement innerText]" : "[frame renderTreeAsExternalRepresentation]");
     } else {
-        fprintf(stdout, "%s#EOF\n", renderDump.toUtf8().constData());
+        fprintf(stdout, "%s", renderDump.toUtf8().constData());
     }
+
+    fprintf(stdout, "#EOF\n");
+
     fflush(stdout);
 
-    m_loading = false;
-    
     if (!m_notifier) {
         // Exit now in single file mode...
         quit();
     }
 }
-    
-void DumpRenderTree::maybeDump(bool ok)
-{
-    if (!ok || !m_controller->shouldWaitUntilDone()) 
-        dump();
-}
 
 }
 
index 7d02bd2..19b4646 100644 (file)
@@ -33,6 +33,7 @@
 #include <QObject>
 #include <QTextStream>
 #include <QSocketNotifier>
+
 class QUrl;
 class QFile;
 class QWebPage;
@@ -48,7 +49,7 @@ Q_OBJECT
 
 public:
     DumpRenderTree();
-    ~DumpRenderTree();
+    virtual ~DumpRenderTree();
 
     // Initialize in multi-file mode, used by run-webkit-tests.
     void open();
@@ -57,27 +58,27 @@ public:
     void open(const QUrl& url);
 
     void resetJSObjects();
-   
+
+    LayoutTestController *layoutTestController() const { return m_controller; }
+    EventSender *eventSender() const { return m_eventSender; }
+
 public Q_SLOTS:
     void initJSObjects();
     void readStdin(int);
-    void maybeDump(bool);
     void dump();
 
 Q_SIGNALS:
     void quit();
 
 private:
-    QWebPage *page;
-    QWebFrame *frame;
-    
     LayoutTestController *m_controller;
+
+    QWebPage *m_page;
+
     EventSender *m_eventSender;
 
     QFile *m_stdin;
     QSocketNotifier* m_notifier;
-
-    bool m_loading;
 };
 
 }
index b01763e..0d52aa4 100644 (file)
@@ -49,34 +49,55 @@ protected:
 
 LayoutTestController::LayoutTestController() : QObject()
 {
-    textDump = false;
-    waitForDone = false;
-    timeoutTimer = 0;
+    m_isLoading = true;
+    m_textDump = false;
+    m_waitForDone = false;
+    m_timeoutTimer = 0;
+    m_topLoadingFrame = 0;
 }
 
 void LayoutTestController::reset()
 {
-    textDump = false;
-    waitForDone = false;
-    if (timeoutTimer)
-        killTimer(timeoutTimer);
+    m_isLoading = true;
+    m_textDump = false;
+    m_waitForDone = false;
+    if (m_timeoutTimer) {
+        killTimer(m_timeoutTimer);
+        m_timeoutTimer = 0;
+    }
+    m_topLoadingFrame = 0;
+}
+
+void LayoutTestController::maybeDump(bool ok)
+{
+    QWebFrame *frame = qobject_cast<QWebFrame*>(sender());
+    if (frame != m_topLoadingFrame)
+        return;
+
+    m_topLoadingFrame = 0;
+
+    if (!ok || !shouldWaitUntilDone()) {
+        emit done();
+        m_isLoading = false;
+    }
 }
 
 void LayoutTestController::waitUntilDone()
 {
     //qDebug() << ">>>>waitForDone";
-    waitForDone = true;
-    timeoutTimer = startTimer(5000);
+    m_waitForDone = true;
+    m_timeoutTimer = startTimer(5000);
 }
 
 void LayoutTestController::notifyDone()
 {
     //qDebug() << ">>>>notifyDone";
-    if (!timeoutTimer)
+    if (!m_timeoutTimer)
         return;
-    killTimer(timeoutTimer);
-    timeoutTimer = 0;
+    killTimer(m_timeoutTimer);
+    m_timeoutTimer = 0;
     emit done();
+    m_isLoading = false;
 }
 
 void LayoutTestController::dumpEditingCallbacks()
@@ -84,6 +105,18 @@ void LayoutTestController::dumpEditingCallbacks()
     //qDebug() << ">>>dumpEditingCallbacks";
 }
 
+void LayoutTestController::queueReload()
+{
+    //qDebug() << ">>>queueReload";
+}
+
+void LayoutTestController::provisionalLoad()
+{
+    QWebFrame *frame = qobject_cast<QWebFrame*>(sender());
+    if (!m_topLoadingFrame && m_isLoading)
+        m_topLoadingFrame = frame;
+}
+
 void LayoutTestController::timerEvent(QTimerEvent *)
 {
     qDebug() << ">>>>>>>>>>>>> timeout";
@@ -94,7 +127,7 @@ void LayoutTestController::timerEvent(QTimerEvent *)
 EventSender::EventSender(QWebPage *parent)
     : QObject(parent)
 {
-    page = parent;
+    m_page = parent;
 }
 
 void EventSender::mouseDown()
@@ -103,7 +136,7 @@ void EventSender::mouseDown()
 //     qDebug() << "EventSender::mouseDown" << frame;
     if (!frame)
         return;
-    QMouseEvent event(QEvent::MouseButtonPress, mousePos - frame->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
+    QMouseEvent event(QEvent::MouseButtonPress, m_mousePos - frame->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
     static_cast<HackWebFrame *>(frame)->mousePressEvent(&event);
 }
 
@@ -113,19 +146,19 @@ void EventSender::mouseUp()
 //     qDebug() << "EventSender::mouseUp" << frame;
     if (!frame)
         return;
-    QMouseEvent event(QEvent::MouseButtonRelease, mousePos - frame->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
+    QMouseEvent event(QEvent::MouseButtonRelease, m_mousePos - frame->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
     static_cast<HackWebFrame *>(frame)->mouseReleaseEvent(&event);
 }
 
 void EventSender::mouseMoveTo(int x, int y)
 {
 //     qDebug() << "EventSender::mouseMoveTo" << x << y;
-    mousePos = QPoint(x, y);
+    m_mousePos = QPoint(x, y);
 }
 
 void EventSender::leapForward(int ms)
 {
-    timeLeap += ms;
+    m_timeLeap += ms;
     qDebug() << "EventSender::leapForward" << ms;
 }
 
@@ -136,17 +169,17 @@ void EventSender::keyDown(const QString &string, const QStringList &modifiers)
 
 QWebFrame *EventSender::frameUnderMouse() const
 {
-    QWebFrame *frame = page->mainFrame();
+    QWebFrame *frame = m_page->mainFrame();
 
 redo:
     QList<QWebFrame*> children = frame->childFrames();
     for (int i = 0; i < children.size(); ++i) {
-        if (children.at(i)->geometry().contains(mousePos)) {
+        if (children.at(i)->geometry().contains(m_mousePos)) {
             frame = children.at(i);
             goto redo;
         }
     }
-    if (frame->geometry().contains(mousePos))
+    if (frame->geometry().contains(m_mousePos))
         return frame;
     return 0;
 }
index 8b0bec4..2c9cc84 100644 (file)
 #include <qdebug.h>
 #include <qpoint.h>
 
+class QWebFrame;
+
 class LayoutTestController : public QObject
 {
     Q_OBJECT
 public:
     LayoutTestController();
 
-    bool shouldDumpAsText() const { return textDump; }
-    bool shouldWaitUntilDone() const { return waitForDone; }
+    bool isLoading() const { return m_isLoading; }
+    void setLoading(bool loading) { m_isLoading = loading; }
+
+    bool shouldDumpAsText() const { return m_textDump; }
+    bool shouldWaitUntilDone() const { return m_waitForDone; }
 
     void reset();
 
@@ -48,17 +53,22 @@ protected:
 
 signals:
     void done();
-    
+
 public slots:
-    void dumpAsText() { textDump = true; }
+    void maybeDump(bool ok);
+    void dumpAsText() { m_textDump = true; }
     void waitUntilDone();
     void notifyDone();
     void dumpEditingCallbacks();
+    void queueReload();
+    void provisionalLoad();
 
 private:
-    bool textDump;
-    bool waitForDone;
-    int timeoutTimer;
+    bool m_isLoading;
+    bool m_textDump;
+    bool m_waitForDone;
+    int m_timeoutTimer;
+    QWebFrame *m_topLoadingFrame;
 };
 
 class QWebPage;
@@ -71,7 +81,6 @@ public:
     EventSender(QWebPage *parent);
 
 public slots:
-    
     void mouseDown();
     void mouseUp();
     void mouseMoveTo(int x, int y);
@@ -79,9 +88,9 @@ public slots:
     void keyDown(const QString &string, const QStringList &modifiers);
 
 private:
-    QPoint mousePos;
-    QWebPage *page;
-    int timeLeap;
+    QPoint m_mousePos;
+    QWebPage *m_page;
+    int m_timeLeap;
     QWebFrame *frameUnderMouse() const;
 };
 
index 587c6dd..d69aa7a 100644 (file)
@@ -120,9 +120,9 @@ int main(int argc, char* argv[])
 
     WebCore::DumpRenderTree dumper;
     
-    if (args.last() == QLatin1String("-"))
+    if (args.last() == QLatin1String("-")) {
         dumper.open();
-    else {
+    else {
         if (!args.last().startsWith("/")
             && !args.last().startsWith("file:")) {
             QString path = QDir::currentPath();