Changeset 83036 in webkit


Ignore:
Timestamp:
Apr 6, 2011 2:37:32 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-04-06 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>

Reviewed by Kenneth Rohde Christiansen.

[Qt] Improve tests for QWebFrame::url() and related methods
https://bugs.webkit.org/show_bug.cgi?id=57865

  • tests/qwebframe/tst_qwebframe.cpp: (FakeReply::FakeReply): make more URLs reply HostNotFound. We needed two different URLs in the test. (tst_QWebFrame::requestedUrlAfterSetAndLoadFailures): check the properties after an setUrl() that fails and a load() that fails (for a different URL).

(tst_QWebFrame::setUrlWithFragment_data):
(tst_QWebFrame::setUrlWithFragment): add other test cases similar to the original, but changing
the URL in the frame before the test starts.

(tst_QWebFrame::setUrlSameUrl): document existing behavior of calling setUrl() twice with
the same URL as argument.

(extractBaseUrl):
(tst_QWebFrame::setUrlThenLoads_data):
(tst_QWebFrame::setUrlThenLoads): check the URL related properties of the frame after a
sequence of set and loads. Those tests are interesting because the properties
react different to setUrl() and load(): 'requestedUrl' always change, 'url' only when setUrl()
is used or after the load() is committed and baseUrl() is similar to url() but also depends
on the contents of the page when it loads.

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

Legend:

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

    r82952 r83036  
     12011-04-06  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] Improve tests for QWebFrame::url() and related methods
     6        https://bugs.webkit.org/show_bug.cgi?id=57865
     7
     8        * tests/qwebframe/tst_qwebframe.cpp:
     9        (FakeReply::FakeReply): make more URLs reply HostNotFound. We needed two different URLs in the test.
     10        (tst_QWebFrame::requestedUrlAfterSetAndLoadFailures): check the properties after an setUrl()
     11        that fails and a load() that fails (for a different URL).
     12
     13        (tst_QWebFrame::setUrlWithFragment_data):
     14        (tst_QWebFrame::setUrlWithFragment): add other test cases similar to the original, but changing
     15        the URL in the frame before the test starts.
     16
     17        (tst_QWebFrame::setUrlSameUrl): document existing behavior of calling setUrl() twice with
     18        the same URL as argument.
     19
     20        (extractBaseUrl):
     21        (tst_QWebFrame::setUrlThenLoads_data):
     22        (tst_QWebFrame::setUrlThenLoads): check the URL related properties of the frame after a
     23        sequence of set and loads. Those tests are interesting because the properties
     24        react different to setUrl() and load(): 'requestedUrl' always change, 'url' only when setUrl()
     25        is used or after the load() is committed and baseUrl() is similar to url() but also depends
     26        on the contents of the page when it loads.
     27
    1282011-04-04  MORITA Hajime  <morrita@google.com>
    229
  • trunk/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp

    r81868 r83036  
    615615    void domCycles();
    616616    void requestedUrl();
     617    void requestedUrlAfterSetAndLoadFailures();
    617618    void javaScriptWindowObjectCleared_data();
    618619    void javaScriptWindowObjectCleared();
     
    650651    void setCacheLoadControlAttribute();
    651652    void setUrlWithPendingLoads();
     653    void setUrlWithFragment_data();
    652654    void setUrlWithFragment();
    653655    void setUrlToEmpty();
    654656    void setUrlToInvalid();
    655657    void setUrlHistory();
     658    void setUrlSameUrl();
     659    void setUrlThenLoads_data();
     660    void setUrlThenLoads();
    656661
    657662private:
     
    23102315            setError(QNetworkReply::SslHandshakeFailedError, tr("Fake error !")); // force a ssl error
    23112316#endif
    2312         else if (request.url() == QUrl("http://abcdef.abcdef/"))
     2317        else if (request.url().host() == QLatin1String("abcdef.abcdef"))
    23132318            setError(QNetworkReply::HostNotFoundError, tr("Invalid URL"));
    23142319
     
    24122417    QCOMPARE(frame->url(), QUrl("qrc:/fake-ssl-error.html"));
    24132418#endif
     2419}
     2420
     2421void tst_QWebFrame::requestedUrlAfterSetAndLoadFailures()
     2422{
     2423    QWebPage page;
     2424    QWebFrame* frame = page.mainFrame();
     2425
     2426    QSignalSpy spy(frame, SIGNAL(loadFinished(bool)));
     2427
     2428    const QUrl first("http://abcdef.abcdef/");
     2429    frame->setUrl(first);
     2430    ::waitForSignal(frame, SIGNAL(loadFinished(bool)));
     2431    QCOMPARE(frame->url(), first);
     2432    QCOMPARE(frame->requestedUrl(), first);
     2433    QVERIFY(!spy.at(0).first().toBool());
     2434
     2435    const QUrl second("http://abcdef.abcdef/another_page.html");
     2436    QVERIFY(first != second);
     2437
     2438    frame->load(second);
     2439    ::waitForSignal(frame, SIGNAL(loadFinished(bool)));
     2440    QCOMPARE(frame->url(), first);
     2441    QCOMPARE(frame->requestedUrl(), second);
     2442    QVERIFY(!spy.at(1).first().toBool());
    24142443}
    24152444
     
    33243353}
    33253354
     3355void tst_QWebFrame::setUrlWithFragment_data()
     3356{
     3357    QTest::addColumn<QUrl>("previousUrl");
     3358    QTest::newRow("empty") << QUrl();
     3359    QTest::newRow("same URL no fragment") << QUrl("qrc:/test1.html");
     3360    // See comments in setUrlSameUrl about using setUrl() with the same url().
     3361    QTest::newRow("same URL with same fragment") << QUrl("qrc:/test1.html#");
     3362    QTest::newRow("same URL with different fragment") << QUrl("qrc:/test1.html#anotherFragment");
     3363    QTest::newRow("another URL") << QUrl("qrc:/test2.html");
     3364}
     3365
     3366// Based on bug report https://bugs.webkit.org/show_bug.cgi?id=32723
    33263367void tst_QWebFrame::setUrlWithFragment()
    33273368{
    33283369    QSKIP("Bug https://bugs.webkit.org/show_bug.cgi?id=32723", SkipAll);
    3329 
    3330     // Based on bug report https://bugs.webkit.org/show_bug.cgi?id=32723
     3370    QFETCH(QUrl, previousUrl);
     3371
    33313372    QWebPage page;
    3332     QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
    3333 
     3373    QWebFrame* frame = page.mainFrame();
     3374
     3375    if (!previousUrl.isEmpty()) {
     3376        frame->load(previousUrl);
     3377        ::waitForSignal(frame, SIGNAL(loadFinished(bool)));
     3378        QCOMPARE(frame->url(), previousUrl);
     3379    }
     3380
     3381    QSignalSpy spy(frame, SIGNAL(loadFinished(bool)));
    33343382    const QUrl url("qrc:/test1.html#");
    33353383    QVERIFY(!url.fragment().isNull());
    33363384
    3337     page.mainFrame()->setUrl(url);
    3338     ::waitForSignal(&page, SIGNAL(loadFinished(bool)));
     3385    frame->setUrl(url);
     3386    ::waitForSignal(frame, SIGNAL(loadFinished(bool)));
    33393387
    33403388    QCOMPARE(spy.count(), 1);
    3341     QVERIFY(!page.mainFrame()->toPlainText().isEmpty());
    3342     QCOMPARE(page.mainFrame()->requestedUrl(), url);
    3343     QCOMPARE(page.mainFrame()->url(), url);
     3389    QVERIFY(!frame->toPlainText().isEmpty());
     3390    QCOMPARE(frame->requestedUrl(), url);
     3391    QCOMPARE(frame->url(), url);
    33443392}
    33453393
     
    34873535}
    34883536
     3537void tst_QWebFrame::setUrlSameUrl()
     3538{
     3539    const QUrl url1("qrc:/test1.html");
     3540    const QUrl url2("qrc:/test2.html");
     3541
     3542    QWebPage page;
     3543    QWebFrame* frame = page.mainFrame();
     3544    FakeNetworkManager* networkManager = new FakeNetworkManager(&page);
     3545    page.setNetworkAccessManager(networkManager);
     3546
     3547    QSignalSpy spy(frame, SIGNAL(loadFinished(bool)));
     3548
     3549    frame->setUrl(url1);
     3550    waitForSignal(frame, SIGNAL(loadFinished(bool)));
     3551    QVERIFY(frame->url() != url1); // Nota bene: our QNAM redirects url1 to url2
     3552    QCOMPARE(frame->url(), url2);
     3553    QCOMPARE(spy.count(), 1);
     3554
     3555    frame->setUrl(url1);
     3556    waitForSignal(frame, SIGNAL(loadFinished(bool)));
     3557    QVERIFY(frame->url() != url1);
     3558    QCOMPARE(frame->url(), url2);
     3559    QCOMPARE(spy.count(), 2);
     3560
     3561    // Now a case without redirect. The existing behavior we have for setUrl()
     3562    // is more like a "clear(); load()", so the page will be loaded again, even
     3563    // if urlToBeLoaded == url(). This test should be changed if we want to
     3564    // make setUrl() early return in this case.
     3565    frame->setUrl(url2);
     3566    waitForSignal(frame, SIGNAL(loadFinished(bool)));
     3567    QCOMPARE(frame->url(), url2);
     3568    QCOMPARE(spy.count(), 3);
     3569
     3570    frame->setUrl(url1);
     3571    waitForSignal(frame, SIGNAL(loadFinished(bool)));
     3572    QCOMPARE(frame->url(), url2);
     3573    QCOMPARE(spy.count(), 4);
     3574}
     3575
     3576static inline QUrl extractBaseUrl(const QUrl& url)
     3577{
     3578    return url.resolved(QUrl());
     3579}
     3580
     3581void tst_QWebFrame::setUrlThenLoads_data()
     3582{
     3583    QTest::addColumn<QUrl>("url");
     3584    QTest::addColumn<QUrl>("baseUrl");
     3585
     3586    QTest::newRow("resource file") << QUrl("qrc:/test1.html") << extractBaseUrl(QUrl("qrc:/test1.html"));
     3587    QTest::newRow("base specified in HTML") << QUrl("data:text/html,<head><base href=\"http://different.base/\"></head>") << QUrl("http://different.base/");
     3588}
     3589
     3590void tst_QWebFrame::setUrlThenLoads()
     3591{
     3592    QFETCH(QUrl, url);
     3593    QFETCH(QUrl, baseUrl);
     3594    QWebFrame* frame = m_page->mainFrame();
     3595    QSignalSpy urlChangedSpy(frame, SIGNAL(urlChanged(QUrl)));
     3596    QSignalSpy startedSpy(frame, SIGNAL(loadStarted()));
     3597    QSignalSpy finishedSpy(frame, SIGNAL(loadFinished(bool)));
     3598
     3599    frame->setUrl(url);
     3600    QCOMPARE(startedSpy.count(), 1);
     3601    ::waitForSignal(frame, SIGNAL(urlChanged(QUrl)));
     3602    QCOMPARE(urlChangedSpy.count(), 1);
     3603    QVERIFY(finishedSpy.at(0).first().toBool());
     3604    QCOMPARE(frame->url(), url);
     3605    QCOMPARE(frame->requestedUrl(), url);
     3606    QCOMPARE(frame->baseUrl(), baseUrl);
     3607
     3608    const QUrl urlToLoad1("qrc:/test2.html");
     3609    const QUrl urlToLoad2("qrc:/test1.html");
     3610
     3611    // Just after first load. URL didn't changed yet.
     3612    frame->load(urlToLoad1);
     3613    QCOMPARE(startedSpy.count(), 2);
     3614    QCOMPARE(frame->url(), url);
     3615    QCOMPARE(frame->requestedUrl(), urlToLoad1);
     3616    QCOMPARE(frame->baseUrl(), baseUrl);
     3617
     3618    // After first URL changed.
     3619    ::waitForSignal(frame, SIGNAL(urlChanged(QUrl)));
     3620    QCOMPARE(urlChangedSpy.count(), 2);
     3621    QVERIFY(finishedSpy.at(1).first().toBool());
     3622    QCOMPARE(frame->url(), urlToLoad1);
     3623    QCOMPARE(frame->requestedUrl(), urlToLoad1);
     3624    QCOMPARE(frame->baseUrl(), extractBaseUrl(urlToLoad1));
     3625
     3626    // Just after second load. URL didn't changed yet.
     3627    frame->load(urlToLoad2);
     3628    QCOMPARE(startedSpy.count(), 3);
     3629    QCOMPARE(frame->url(), urlToLoad1);
     3630    QCOMPARE(frame->requestedUrl(), urlToLoad2);
     3631    QCOMPARE(frame->baseUrl(), extractBaseUrl(urlToLoad1));
     3632
     3633    // After second URL changed.
     3634    ::waitForSignal(frame, SIGNAL(urlChanged(QUrl)));
     3635    QCOMPARE(urlChangedSpy.count(), 3);
     3636    QVERIFY(finishedSpy.at(2).first().toBool());
     3637    QCOMPARE(frame->url(), urlToLoad2);
     3638    QCOMPARE(frame->requestedUrl(), urlToLoad2);
     3639    QCOMPARE(frame->baseUrl(), extractBaseUrl(urlToLoad2));
     3640}
     3641
    34893642QTEST_MAIN(tst_QWebFrame)
    34903643#include "tst_qwebframe.moc"
Note: See TracChangeset for help on using the changeset viewer.