[Qt] Add test for correct order of load signals in QWebPage
authorcaio.oliveira@openbossa.org <caio.oliveira@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Aug 2011 15:15:16 +0000 (15:15 +0000)
committercaio.oliveira@openbossa.org <caio.oliveira@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Aug 2011 15:15:16 +0000 (15:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=66016

Reviewed by Benjamin Poulain.

Add API test to ensure the order of load signals: loadStarted() needs to be emitted
first, then loadProgress(100), followed by loadFinished().

The test is skipped since this right now is broken, the bug
https://bugs.webkit.org/show_bug.cgi?id=28851 tracks one possible way to fix.

* tests/qwebpage/tst_qwebpage.cpp:
(SpyForLoadSignalsOrder::SpyForLoadSignalsOrder):
(SpyForLoadSignalsOrder::isFinished):
(SpyForLoadSignalsOrder::onLoadProgress):
(tst_QWebPage::loadSignalsOrder_data):
(tst_QWebPage::loadSignalsOrder):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@92963 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/qt/ChangeLog
Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp

index cc7b5bb..ed6c578 100644 (file)
@@ -1,3 +1,23 @@
+2011-08-12  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
+
+        [Qt] Add test for correct order of load signals in QWebPage
+        https://bugs.webkit.org/show_bug.cgi?id=66016
+
+        Reviewed by Benjamin Poulain.
+
+        Add API test to ensure the order of load signals: loadStarted() needs to be emitted
+        first, then loadProgress(100), followed by loadFinished().
+
+        The test is skipped since this right now is broken, the bug
+        https://bugs.webkit.org/show_bug.cgi?id=28851 tracks one possible way to fix.
+
+        * tests/qwebpage/tst_qwebpage.cpp:
+        (SpyForLoadSignalsOrder::SpyForLoadSignalsOrder):
+        (SpyForLoadSignalsOrder::isFinished):
+        (SpyForLoadSignalsOrder::onLoadProgress):
+        (tst_QWebPage::loadSignalsOrder_data):
+        (tst_QWebPage::loadSignalsOrder):
+
 2011-08-12  Alexis Menard  <alexis.menard@openbossa.org>
 
         [Qt] Make sure QtWebKit correctly compiles when building WebKit2 with Qt5.
index e1f85c8..a45aedb 100644 (file)
@@ -28,6 +28,7 @@
 #include <QMainWindow>
 #include <QMenu>
 #include <QPushButton>
+#include <QStateMachine>
 #include <QStyle>
 #include <QtTest/QtTest>
 #include <QTextCharFormat>
@@ -159,6 +160,8 @@ private slots:
     void navigatorCookieEnabled();
     void deleteQWebViewTwice();
     void renderOnRepaintRequestedShouldNotRecurse();
+    void loadSignalsOrder_data();
+    void loadSignalsOrder();
 
 #ifdef Q_OS_MAC
     void macCopyUnicodeToClipboard();
@@ -3141,5 +3144,59 @@ void tst_QWebPage::renderOnRepaintRequestedShouldNotRecurse()
     QVERIFY(::waitForSignal(&r, SIGNAL(finished())));
 }
 
+class SpyForLoadSignalsOrder : public QStateMachine {
+    Q_OBJECT
+public:
+    SpyForLoadSignalsOrder(QWebPage* page, QObject* parent = 0)
+        : QStateMachine(parent)
+    {
+        connect(page, SIGNAL(loadProgress(int)), SLOT(onLoadProgress(int)));
+
+        QState* waitingForLoadStarted = new QState(this);
+        QState* waitingForLastLoadProgress = new QState(this);
+        QState* waitingForLoadFinished = new QState(this);
+        QFinalState* final = new QFinalState(this);
+
+        waitingForLoadStarted->addTransition(page, SIGNAL(loadStarted()), waitingForLastLoadProgress);
+        waitingForLastLoadProgress->addTransition(this, SIGNAL(lastLoadProgress()), waitingForLoadFinished);
+        waitingForLoadFinished->addTransition(page, SIGNAL(loadFinished(bool)), final);
+
+        setInitialState(waitingForLoadStarted);
+        start();
+    }
+    bool isFinished() const
+    {
+        return !isRunning();
+    }
+public Q_SLOTS:
+    void onLoadProgress(int progress)
+    {
+        if (progress == 100)
+            emit lastLoadProgress();
+    }
+signals:
+    void lastLoadProgress();
+};
+
+void tst_QWebPage::loadSignalsOrder_data()
+{
+    QTest::addColumn<QUrl>("url");
+    QTest::newRow("inline data") << QUrl("data:text/html,This is first page");
+    QTest::newRow("simple page") << QUrl("qrc:///resources/content.html");
+    QTest::newRow("frameset page") << QUrl("qrc:///resources/index.html");
+}
+
+void tst_QWebPage::loadSignalsOrder()
+{
+    QSKIP("https://bugs.webkit.org/show_bug.cgi?id=28851", SkipAll);
+
+    QFETCH(QUrl, url);
+    QWebPage page;
+    SpyForLoadSignalsOrder loadSpy(&page);
+    waitForSignal(&loadSpy, SIGNAL(started()));
+    page.mainFrame()->load(url);
+    QTRY_VERIFY(loadSpy.isFinished());
+}
+
 QTEST_MAIN(tst_QWebPage)
 #include "tst_qwebpage.moc"