Permalink
Browse files

wip: Fix issues with Qt 4.8

  • Loading branch information...
1 parent e677cb9 commit 82b3921264d72c714362b0216cdbe68ec609416f @jferris jferris committed Jul 12, 2012
View
@@ -236,7 +236,7 @@
it 'uses URLs changed by javascript' do
browser.execute_script "window.history.pushState('', '', '/blah')"
- browser.requested_url.should == 'http://example.org/blah'
+ browser.current_url.should == 'http://example.org/blah'
end
it 'is possible to disable proxy again' do
View
@@ -239,7 +239,7 @@ def in_iframe_request?
it "has a blank location after reseting" do
driver.reset!
- driver.current_url.should == ""
+ driver.current_url.should == "about:blank"
end
it "raises an error for an invalid xpath query" do
@@ -395,7 +395,11 @@ def in_iframe_request?
before { driver.visit("/") }
it "collects messages logged to the console" do
- driver.console_messages.first.should include :source, :message => "hello", :line_number => 6
+ url = driver_url(driver, "/")
+ message = driver.console_messages.first
+ message.should include :source => url, :message => "hello"
+ # QtWebKit returns different line numbers depending on the version
+ [5, 6].should include(message[:line_number])
driver.console_messages.length.should eq 3
end
View
@@ -5,65 +5,9 @@
CurrentUrl::CurrentUrl(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
-/*
- * This CurrentUrl command attempts to produce a current_url value consistent
- * with that returned by the Selenium WebDriver Capybara driver.
- *
- * It does not currently return the correct value in the case of an iframe whose
- * source URL results in a redirect because the loading of the iframe does not
- * generate a history item. This is most likely a rare case and is consistent
- * with the current behavior of the capybara-webkit driver.
- *
- * The following two values are *not* affected by Javascript pushState.
- *
- * QWebFrame->url()
- * QWebHistoryItem.originalUrl()
- *
- * The following two values *are* affected by Javascript pushState.
- *
- * QWebFrame->requestedUrl()
- * QWebHistoryItem.url()
- *
- * In the cases that we have access to both the QWebFrame values and the
- * correct history item for that frame, we can compare the values and determine
- * if a redirect occurred and if pushState was used. The table below describes
- * the various combinations of URL values that are possible.
- *
- * O -> originally requested URL
- * R -> URL after redirection
- * P -> URL set by pushState
- * * -> denotes the desired URL value from the frame
- *
- * frame history
- * case url requestedUrl url originalUrl
- * -----------------------------------------------------------------
- * regular load O O* O O
- *
- * redirect w/o R* O R O
- * pushState
- *
- * pushState O P* P O
- * only
- *
- * redirect w/ R P* P O
- * pushState
- *
- * Based on the above information, we only need to check for the case of a
- * redirect w/o pushState, in which case QWebFrame->url() will have the correct
- * current_url value. In all other cases QWebFrame->requestedUrl() is correct.
- */
void CurrentUrl::start() {
- QUrl humanUrl = wasRedirectedAndNotModifiedByJavascript() ?
- page()->currentFrame()->url() : page()->currentFrame()->requestedUrl();
- QByteArray encodedBytes = humanUrl.toEncoded();
- emit finished(new Response(true, encodedBytes));
+ QStringList arguments;
+ QVariant result = page()->invokeCapybaraFunction("currentUrl", arguments);
+ QString url = result.toString();
+ emit finished(new Response(true, url));
}
-
-bool CurrentUrl::wasRegularLoad() {
- return page()->currentFrame()->url() == page()->currentFrame()->requestedUrl();
-}
-
-bool CurrentUrl::wasRedirectedAndNotModifiedByJavascript() {
- return !wasRegularLoad() && page()->currentFrame()->url() == page()->history()->currentItem().url();
-}
-
View
@@ -6,9 +6,5 @@ class CurrentUrl : public SocketCommand {
public:
CurrentUrl(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
-
- private:
- bool wasRegularLoad();
- bool wasRedirectedAndNotModifiedByJavascript();
};
View
@@ -7,7 +7,7 @@ Source::Source(WebPageManager *manager, QStringList &arguments, QObject *parent)
void Source::start() {
QNetworkAccessManager* accessManager = page()->networkAccessManager();
- QNetworkRequest request(page()->currentFrame()->url());
+ QNetworkRequest request(page()->currentFrame()->requestedUrl());
reply = accessManager->get(request);
connect(reply, SIGNAL(finished()), this, SLOT(sourceLoaded()));
@@ -5,23 +5,21 @@
UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkReply *reply, QObject *parent) : QObject(parent) {
m_page = page;
m_reply = reply;
- connect(m_reply, SIGNAL(finished()), this, SLOT(handleUnsupportedContent()));
- disconnect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
}
-void UnsupportedContentHandler::handleUnsupportedContent() {
- this->renderNonHtmlContent();
- this->finish();
+void UnsupportedContentHandler::renderNonHtmlContent() {
+ QByteArray text = m_reply->readAll();
+ m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
+ m_page->networkAccessManagerFinishedReply(m_reply);
+ m_page->loadFinished(true);
this->deleteLater();
}
-void UnsupportedContentHandler::renderNonHtmlContent() {
- QByteArray text = m_reply->readAll();
- m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
+void UnsupportedContentHandler::waitForReplyToFinish() {
+ connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
+ disconnect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
}
-void UnsupportedContentHandler::finish() {
- connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
- m_page->networkAccessManagerFinishedReply(m_reply);
- m_page->loadFinished(true);
+void UnsupportedContentHandler::replyFinished() {
+ connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
}
@@ -1,18 +1,20 @@
#include <QObject>
+
class WebPage;
class QNetworkReply;
+
class UnsupportedContentHandler : public QObject {
Q_OBJECT
public:
UnsupportedContentHandler(WebPage *page, QNetworkReply *reply, QObject *parent = 0);
+ void waitForReplyToFinish();
+ void renderNonHtmlContent();
public slots:
- void handleUnsupportedContent();
+ void replyFinished();
private:
WebPage *m_page;
QNetworkReply *m_reply;
- void renderNonHtmlContent();
- void finish();
};
View
@@ -277,7 +277,10 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
if(!contentMimeType.isNull()) {
triggerAction(QWebPage::Stop);
UnsupportedContentHandler *handler = new UnsupportedContentHandler(this, reply);
- Q_UNUSED(handler);
+ if (reply->isFinished())
+ handler->renderNonHtmlContent();
+ else
+ handler->waitForReplyToFinish();
}
}
View
@@ -11,6 +11,10 @@ Capybara = {
return this.findRelativeTo(document, xpath);
},
+ currentUrl: function () {
+ return window.location.toString();
+ },
+
findWithin: function (index, xpath) {
return this.findRelativeTo(this.nodes[index], xpath);
},

0 comments on commit 82b3921

Please sign in to comment.