1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

Use old method to find current URL in Qt < 4.8.0

This commit is contained in:
Matthew Horan 2012-10-22 20:40:49 -04:00
parent ecfa7836d9
commit f95e4ebe0b
3 changed files with 23 additions and 0 deletions

View file

@ -6,8 +6,24 @@ CurrentUrl::CurrentUrl(WebPageManager *manager, QStringList &arguments, QObject
}
void CurrentUrl::start() {
#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
QStringList arguments;
QVariant result = page()->invokeCapybaraFunction("currentUrl", arguments);
QString url = result.toString();
emit finished(new Response(true, url));
#else
QUrl humanUrl = wasRedirectedAndNotModifiedByJavascript() ?
page()->currentFrame()->url() : page()->currentFrame()->requestedUrl();
QByteArray encodedBytes = humanUrl.toEncoded();
emit finished(new Response(true, encodedBytes));
}
bool CurrentUrl::wasRegularLoad() {
return page()->currentFrame()->url() == page()->currentFrame()->requestedUrl();
}
bool CurrentUrl::wasRedirectedAndNotModifiedByJavascript() {
return !wasRegularLoad() && page()->currentFrame()->url() == page()->history()->currentItem().url();
#endif
}

View file

@ -6,5 +6,11 @@ class CurrentUrl : public SocketCommand {
public:
CurrentUrl(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0)
private:
bool wasRegularLoad();
bool wasRedirectedAndNotModifiedByJavascript();
#endif
};

View file

@ -100,6 +100,7 @@ void WebPageManager::reset() {
m_pages.first()->deleteLater();
m_pages.clear();
createPage(this)->setFocus();
currentPage()->currentFrame()->setUrl(QUrl("about:blank"));
}
NetworkCookieJar *WebPageManager::cookieJar() {