[Qt] Add more tests to cover the behavior of loadFinished() signal
authorcaio.oliveira@openbossa.org <caio.oliveira@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Jul 2011 15:51:16 +0000 (15:51 +0000)
committercaio.oliveira@openbossa.org <caio.oliveira@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Jul 2011 15:51:16 +0000 (15:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=63490

Reviewed by Benjamin Poulain.

* tests/qwebframe/tst_qwebframe.cpp:
(FakeReply::FakeReply):
(FakeNetworkManager::createRequest): Add a fake reply that gives 404 error code.

(tst_QWebFrame::loadFinishedAfterNotFoundError): Verify that we get loadFinished(false)
after a 404 error without contents.

* tests/qwebpage/tst_qwebpage.cpp:
(tst_QWebPage::errorPageExtensionLoadFinished): Verify if the argument of loadFinished()
is true when we use error page extension to produce our own error pages.

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

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

index c0b897a..eae4ed8 100644 (file)
@@ -1,3 +1,21 @@
+2011-07-25  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
+
+        [Qt] Add more tests to cover the behavior of loadFinished() signal
+        https://bugs.webkit.org/show_bug.cgi?id=63490
+
+        Reviewed by Benjamin Poulain.
+
+        * tests/qwebframe/tst_qwebframe.cpp:
+        (FakeReply::FakeReply):
+        (FakeNetworkManager::createRequest): Add a fake reply that gives 404 error code.
+
+        (tst_QWebFrame::loadFinishedAfterNotFoundError): Verify that we get loadFinished(false)
+        after a 404 error without contents.
+
+        * tests/qwebpage/tst_qwebpage.cpp:
+        (tst_QWebPage::errorPageExtensionLoadFinished): Verify if the argument of loadFinished()
+        is true when we use error page extension to produce our own error pages.
+
 2011-07-19  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
 
         [Qt] Improve documentation of QWebView::setPage()
 2011-07-19  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
 
         [Qt] Improve documentation of QWebView::setPage()
index c3680cb..cf5d600 100644 (file)
@@ -659,6 +659,7 @@ private slots:
     void setUrlSameUrl();
     void setUrlThenLoads_data();
     void setUrlThenLoads();
     void setUrlSameUrl();
     void setUrlThenLoads_data();
     void setUrlThenLoads();
+    void loadFinishedAfterNotFoundError();
 
 private:
     QString  evalJS(const QString&s) {
 
 private:
     QString  evalJS(const QString&s) {
@@ -2302,6 +2303,8 @@ class FakeReply : public QNetworkReply {
     Q_OBJECT
 
 public:
     Q_OBJECT
 
 public:
+    static const QUrl urlFor404ErrorWithoutContents;
+
     FakeReply(const QNetworkRequest& request, QObject* parent = 0)
         : QNetworkReply(parent)
     {
     FakeReply(const QNetworkRequest& request, QObject* parent = 0)
         : QNetworkReply(parent)
     {
@@ -2321,6 +2324,10 @@ public:
         else if (request.url().host() == QLatin1String("abcdef.abcdef")) {
             setError(QNetworkReply::HostNotFoundError, tr("Invalid URL"));
             QTimer::singleShot(0, this, SLOT(continueError()));
         else if (request.url().host() == QLatin1String("abcdef.abcdef")) {
             setError(QNetworkReply::HostNotFoundError, tr("Invalid URL"));
             QTimer::singleShot(0, this, SLOT(continueError()));
+        } else if (request.url() == FakeReply::urlFor404ErrorWithoutContents) {
+            setError(QNetworkReply::ContentNotFoundError, "Not found");
+            setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 404);
+            QTimer::singleShot(0, this, SLOT(continueError()));
         }
 
         open(QIODevice::ReadOnly);
         }
 
         open(QIODevice::ReadOnly);
@@ -2352,6 +2359,8 @@ private slots:
     }
 };
 
     }
 };
 
+const QUrl FakeReply::urlFor404ErrorWithoutContents = QUrl("http://this.will/return-http-404-error-without-contents.html");
+
 class FakeNetworkManager : public QNetworkAccessManager {
     Q_OBJECT
 
 class FakeNetworkManager : public QNetworkAccessManager {
     Q_OBJECT
 
@@ -2363,17 +2372,17 @@ protected:
     {
         QString url = request.url().toString();
         if (op == QNetworkAccessManager::GetOperation) {
     {
         QString url = request.url().toString();
         if (op == QNetworkAccessManager::GetOperation) {
-            if (url == "qrc:/test1.html" ||  url == "http://abcdef.abcdef/")
-                return new FakeReply(request, this);
 #ifndef QT_NO_OPENSSL
 #ifndef QT_NO_OPENSSL
-            else if (url == "qrc:/fake-ssl-error.html") {
+            if (url == "qrc:/fake-ssl-error.html") {
                 FakeReply* reply = new FakeReply(request, this);
                 QList<QSslError> errors;
                 emit sslErrors(reply, errors << QSslError(QSslError::UnspecifiedError));
                 return reply;
             }
 #endif
                 FakeReply* reply = new FakeReply(request, this);
                 QList<QSslError> errors;
                 emit sslErrors(reply, errors << QSslError(QSslError::UnspecifiedError));
                 return reply;
             }
 #endif
-       }
+            if (url == "qrc:/test1.html" || url == "http://abcdef.abcdef/" || request.url() == FakeReply::urlFor404ErrorWithoutContents)
+                return new FakeReply(request, this);
+        }
 
         return QNetworkAccessManager::createRequest(op, request, outgoingData);
     }
 
         return QNetworkAccessManager::createRequest(op, request, outgoingData);
     }
@@ -3679,5 +3688,20 @@ void tst_QWebFrame::setUrlThenLoads()
     QCOMPARE(frame->baseUrl(), extractBaseUrl(urlToLoad2));
 }
 
     QCOMPARE(frame->baseUrl(), extractBaseUrl(urlToLoad2));
 }
 
+void tst_QWebFrame::loadFinishedAfterNotFoundError()
+{
+    QWebPage page;
+    QWebFrame* frame = page.mainFrame();
+
+    QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
+    FakeNetworkManager* networkManager = new FakeNetworkManager(&page);
+    page.setNetworkAccessManager(networkManager);
+
+    frame->setUrl(FakeReply::urlFor404ErrorWithoutContents);
+    QTRY_COMPARE(spy.count(), 1);
+    const bool wasLoadOk = spy.at(0).at(0).toBool();
+    QVERIFY(!wasLoadOk);
+}
+
 QTEST_MAIN(tst_QWebFrame)
 #include "tst_qwebframe.moc"
 QTEST_MAIN(tst_QWebFrame)
 #include "tst_qwebframe.moc"
index a6baa64..7af26fb 100644 (file)
@@ -134,6 +134,7 @@ private slots:
     void errorPageExtension();
     void errorPageExtensionInIFrames();
     void errorPageExtensionInFrameset();
     void errorPageExtension();
     void errorPageExtensionInIFrames();
     void errorPageExtensionInFrameset();
+    void errorPageExtensionLoadFinished();
     void userAgentApplicationName();
 
     void viewModes();
     void userAgentApplicationName();
 
     void viewModes();
@@ -2576,6 +2577,35 @@ void tst_QWebPage::errorPageExtensionInFrameset()
     m_view->setPage(0);
 }
 
     m_view->setPage(0);
 }
 
+void tst_QWebPage::errorPageExtensionLoadFinished()
+{
+    ErrorPage page;
+    m_view->setPage(&page);
+
+    QSignalSpy spyLoadFinished(m_view, SIGNAL(loadFinished(bool)));
+    QSignalSpy spyFrameLoadFinished(m_view->page()->mainFrame(), SIGNAL(loadFinished(bool)));
+
+    m_view->setUrl(QUrl("data:text/html,foo"));
+    QTRY_COMPARE(spyLoadFinished.count(), 1);
+    QTRY_COMPARE(spyFrameLoadFinished.count(), 1);
+
+    const bool loadSucceded = spyLoadFinished.at(0).at(0).toBool();
+    QVERIFY(loadSucceded);
+    const bool frameLoadSucceded = spyFrameLoadFinished.at(0).at(0).toBool();
+    QVERIFY(frameLoadSucceded);
+
+    m_view->page()->mainFrame()->setUrl(QUrl("http://non.existent/url"));
+    QTRY_COMPARE(spyLoadFinished.count(), 2);
+    QTRY_COMPARE(spyFrameLoadFinished.count(), 2);
+
+    const bool nonExistantLoadSucceded = spyLoadFinished.at(1).at(0).toBool();
+    QVERIFY(nonExistantLoadSucceded);
+    const bool nonExistantFrameLoadSucceded = spyFrameLoadFinished.at(1).at(0).toBool();
+    QVERIFY(nonExistantFrameLoadSucceded);
+
+    m_view->setPage(0);
+}
+
 class FriendlyWebPage : public QWebPage
 {
 public:
 class FriendlyWebPage : public QWebPage
 {
 public: