Changeset 91669 in webkit


Ignore:
Timestamp:
Jul 25, 2011 8:51:16 AM (13 years ago)
Author:
caio.oliveira@openbossa.org
Message:

[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.

Location:
trunk/Source/WebKit/qt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/qt/ChangeLog

    r91335 r91669  
     12011-07-25  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
     2
     3        [Qt] Add more tests to cover the behavior of loadFinished() signal
     4        https://bugs.webkit.org/show_bug.cgi?id=63490
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * tests/qwebframe/tst_qwebframe.cpp:
     9        (FakeReply::FakeReply):
     10        (FakeNetworkManager::createRequest): Add a fake reply that gives 404 error code.
     11
     12        (tst_QWebFrame::loadFinishedAfterNotFoundError): Verify that we get loadFinished(false)
     13        after a 404 error without contents.
     14
     15        * tests/qwebpage/tst_qwebpage.cpp:
     16        (tst_QWebPage::errorPageExtensionLoadFinished): Verify if the argument of loadFinished()
     17        is true when we use error page extension to produce our own error pages.
     18
    1192011-07-19  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
    220
  • trunk/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp

    r90403 r91669  
    660660    void setUrlThenLoads_data();
    661661    void setUrlThenLoads();
     662    void loadFinishedAfterNotFoundError();
    662663
    663664private:
     
    23032304
    23042305public:
     2306    static const QUrl urlFor404ErrorWithoutContents;
     2307
    23052308    FakeReply(const QNetworkRequest& request, QObject* parent = 0)
    23062309        : QNetworkReply(parent)
     
    23222325            setError(QNetworkReply::HostNotFoundError, tr("Invalid URL"));
    23232326            QTimer::singleShot(0, this, SLOT(continueError()));
     2327        } else if (request.url() == FakeReply::urlFor404ErrorWithoutContents) {
     2328            setError(QNetworkReply::ContentNotFoundError, "Not found");
     2329            setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 404);
     2330            QTimer::singleShot(0, this, SLOT(continueError()));
    23242331        }
    23252332
     
    23532360};
    23542361
     2362const QUrl FakeReply::urlFor404ErrorWithoutContents = QUrl("http://this.will/return-http-404-error-without-contents.html");
     2363
    23552364class FakeNetworkManager : public QNetworkAccessManager {
    23562365    Q_OBJECT
     
    23642373        QString url = request.url().toString();
    23652374        if (op == QNetworkAccessManager::GetOperation) {
    2366             if (url == "qrc:/test1.html" ||  url == "http://abcdef.abcdef/")
    2367                 return new FakeReply(request, this);
    23682375#ifndef QT_NO_OPENSSL
    2369             else if (url == "qrc:/fake-ssl-error.html") {
     2376            if (url == "qrc:/fake-ssl-error.html") {
    23702377                FakeReply* reply = new FakeReply(request, this);
    23712378                QList<QSslError> errors;
     
    23742381            }
    23752382#endif
    2376        }
     2383            if (url == "qrc:/test1.html" || url == "http://abcdef.abcdef/" || request.url() == FakeReply::urlFor404ErrorWithoutContents)
     2384                return new FakeReply(request, this);
     2385        }
    23772386
    23782387        return QNetworkAccessManager::createRequest(op, request, outgoingData);
     
    36803689}
    36813690
     3691void tst_QWebFrame::loadFinishedAfterNotFoundError()
     3692{
     3693    QWebPage page;
     3694    QWebFrame* frame = page.mainFrame();
     3695
     3696    QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
     3697    FakeNetworkManager* networkManager = new FakeNetworkManager(&page);
     3698    page.setNetworkAccessManager(networkManager);
     3699
     3700    frame->setUrl(FakeReply::urlFor404ErrorWithoutContents);
     3701    QTRY_COMPARE(spy.count(), 1);
     3702    const bool wasLoadOk = spy.at(0).at(0).toBool();
     3703    QVERIFY(!wasLoadOk);
     3704}
     3705
    36823706QTEST_MAIN(tst_QWebFrame)
    36833707#include "tst_qwebframe.moc"
  • trunk/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp

    r91302 r91669  
    135135    void errorPageExtensionInIFrames();
    136136    void errorPageExtensionInFrameset();
     137    void errorPageExtensionLoadFinished();
    137138    void userAgentApplicationName();
    138139
     
    25772578}
    25782579
     2580void tst_QWebPage::errorPageExtensionLoadFinished()
     2581{
     2582    ErrorPage page;
     2583    m_view->setPage(&page);
     2584
     2585    QSignalSpy spyLoadFinished(m_view, SIGNAL(loadFinished(bool)));
     2586    QSignalSpy spyFrameLoadFinished(m_view->page()->mainFrame(), SIGNAL(loadFinished(bool)));
     2587
     2588    m_view->setUrl(QUrl("data:text/html,foo"));
     2589    QTRY_COMPARE(spyLoadFinished.count(), 1);
     2590    QTRY_COMPARE(spyFrameLoadFinished.count(), 1);
     2591
     2592    const bool loadSucceded = spyLoadFinished.at(0).at(0).toBool();
     2593    QVERIFY(loadSucceded);
     2594    const bool frameLoadSucceded = spyFrameLoadFinished.at(0).at(0).toBool();
     2595    QVERIFY(frameLoadSucceded);
     2596
     2597    m_view->page()->mainFrame()->setUrl(QUrl("http://non.existent/url"));
     2598    QTRY_COMPARE(spyLoadFinished.count(), 2);
     2599    QTRY_COMPARE(spyFrameLoadFinished.count(), 2);
     2600
     2601    const bool nonExistantLoadSucceded = spyLoadFinished.at(1).at(0).toBool();
     2602    QVERIFY(nonExistantLoadSucceded);
     2603    const bool nonExistantFrameLoadSucceded = spyFrameLoadFinished.at(1).at(0).toBool();
     2604    QVERIFY(nonExistantFrameLoadSucceded);
     2605
     2606    m_view->setPage(0);
     2607}
     2608
    25792609class FriendlyWebPage : public QWebPage
    25802610{
Note: See TracChangeset for help on using the changeset viewer.