Modified: trunk/Source/WebKit/qt/ChangeLog (91668 => 91669)
--- trunk/Source/WebKit/qt/ChangeLog 2011-07-25 15:10:43 UTC (rev 91668)
+++ trunk/Source/WebKit/qt/ChangeLog 2011-07-25 15:51:16 UTC (rev 91669)
@@ -1,3 +1,21 @@
+2011-07-25 Caio Marcelo de Oliveira Filho <[email protected]>
+
+ [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 <[email protected]>
[Qt] Improve documentation of QWebView::setPage()
Modified: trunk/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp (91668 => 91669)
--- trunk/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp 2011-07-25 15:10:43 UTC (rev 91668)
+++ trunk/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp 2011-07-25 15:51:16 UTC (rev 91669)
@@ -659,6 +659,7 @@
void setUrlSameUrl();
void setUrlThenLoads_data();
void setUrlThenLoads();
+ void loadFinishedAfterNotFoundError();
private:
QString evalJS(const QString&s) {
@@ -2302,6 +2303,8 @@
Q_OBJECT
public:
+ static const QUrl urlFor404ErrorWithoutContents;
+
FakeReply(const QNetworkRequest& request, QObject* parent = 0)
: QNetworkReply(parent)
{
@@ -2321,6 +2324,10 @@
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);
@@ -2352,6 +2359,8 @@
}
};
+const QUrl FakeReply::urlFor404ErrorWithoutContents = QUrl("http://this.will/return-http-404-error-without-contents.html");
+
class FakeNetworkManager : public QNetworkAccessManager {
Q_OBJECT
@@ -2363,17 +2372,17 @@
{
QString url = ""
if (op == QNetworkAccessManager::GetOperation) {
- if (url == "qrc:/test1.html" || url == "http://abcdef.abcdef/")
- return new FakeReply(request, this);
#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
- }
+ if (url == "qrc:/test1.html" || url == "http://abcdef.abcdef/" || request.url() == FakeReply::urlFor404ErrorWithoutContents)
+ return new FakeReply(request, this);
+ }
return QNetworkAccessManager::createRequest(op, request, outgoingData);
}
@@ -3679,5 +3688,20 @@
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"
Modified: trunk/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp (91668 => 91669)
--- trunk/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp 2011-07-25 15:10:43 UTC (rev 91668)
+++ trunk/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp 2011-07-25 15:51:16 UTC (rev 91669)
@@ -134,6 +134,7 @@
void errorPageExtension();
void errorPageExtensionInIFrames();
void errorPageExtensionInFrameset();
+ void errorPageExtensionLoadFinished();
void userAgentApplicationName();
void viewModes();
@@ -2576,6 +2577,35 @@
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: