mirror of
https://github.com/thoughtbot/capybara-webkit
synced 2023-03-27 23:22:28 -04:00
Treat fewer responses as fatal failures
* Relies on errorExtension instead of loadFinished * Ignores errors from canceled requests
This commit is contained in:
parent
09425000f7
commit
d8020ce3a4
4 changed files with 19 additions and 15 deletions
|
@ -10,23 +10,18 @@ UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkRepl
|
|||
}
|
||||
|
||||
void UnsupportedContentHandler::handleUnsupportedContent() {
|
||||
QVariant contentMimeType = m_reply->header(QNetworkRequest::ContentTypeHeader);
|
||||
if(contentMimeType.isNull()) {
|
||||
this->finish(false);
|
||||
} else {
|
||||
this->loadUnsupportedContent();
|
||||
this->finish(true);
|
||||
}
|
||||
this->renderNonHtmlContent();
|
||||
this->finish();
|
||||
this->deleteLater();
|
||||
}
|
||||
|
||||
void UnsupportedContentHandler::loadUnsupportedContent() {
|
||||
void UnsupportedContentHandler::renderNonHtmlContent() {
|
||||
QByteArray text = m_reply->readAll();
|
||||
m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
|
||||
}
|
||||
|
||||
void UnsupportedContentHandler::finish(bool success) {
|
||||
void UnsupportedContentHandler::finish() {
|
||||
connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
|
||||
m_page->networkAccessManagerFinishedReply(m_reply);
|
||||
m_page->loadFinished(success);
|
||||
m_page->loadFinished(true);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,6 @@ class UnsupportedContentHandler : public QObject {
|
|||
private:
|
||||
WebPage *m_page;
|
||||
QNetworkReply *m_reply;
|
||||
void loadUnsupportedContent();
|
||||
void finish(bool success);
|
||||
void renderNonHtmlContent();
|
||||
void finish();
|
||||
};
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
|
||||
m_loading = false;
|
||||
m_failed = false;
|
||||
m_manager = manager;
|
||||
m_uuid = QUuid::createUuid().toString();
|
||||
m_lastStatus = 0;
|
||||
|
@ -162,8 +163,10 @@ void WebPage::loadStarted() {
|
|||
}
|
||||
|
||||
void WebPage::loadFinished(bool success) {
|
||||
Q_UNUSED(success);
|
||||
m_loading = false;
|
||||
emit pageFinished(success);
|
||||
emit pageFinished(!m_failed);
|
||||
m_failed = false;
|
||||
}
|
||||
|
||||
bool WebPage::isLoading() const {
|
||||
|
@ -221,6 +224,7 @@ bool WebPage::extension(Extension extension, const ExtensionOption *option, Exte
|
|||
else if (extension == QWebPage::ErrorPageExtension) {
|
||||
ErrorPageExtensionOption *errorOption = (ErrorPageExtensionOption*) option;
|
||||
m_errorPageMessage = " because of error loading " + errorOption->url.toString() + ": " + errorOption->errorString;
|
||||
m_failed = true;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
@ -248,8 +252,12 @@ QString WebPage::pageHeaders() {
|
|||
}
|
||||
|
||||
void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
|
||||
UnsupportedContentHandler *handler = new UnsupportedContentHandler(this, reply);
|
||||
Q_UNUSED(handler);
|
||||
QVariant contentMimeType = reply->header(QNetworkRequest::ContentTypeHeader);
|
||||
if(!contentMimeType.isNull()) {
|
||||
triggerAction(QWebPage::Stop);
|
||||
UnsupportedContentHandler *handler = new UnsupportedContentHandler(this, reply);
|
||||
Q_UNUSED(handler);
|
||||
}
|
||||
}
|
||||
|
||||
bool WebPage::supportsExtension(Extension extension) const {
|
||||
|
|
|
@ -57,6 +57,7 @@ class WebPage : public QWebPage {
|
|||
QString m_capybaraJavascript;
|
||||
QString m_userAgent;
|
||||
bool m_loading;
|
||||
bool m_failed;
|
||||
QString getLastAttachedFileName();
|
||||
void loadJavascript();
|
||||
void setUserStylesheet();
|
||||
|
|
Loading…
Reference in a new issue