Permalink
Browse files

Status codes

  • Loading branch information...
1 parent 71ca80d commit 558c58babc60f7213586fe879289e99aef7633ea @jferris jferris committed with halogenandtoast Aug 12, 2011
View
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "capybara-webkit"
- s.version = "0.5.0"
+ s.version = "0.6.0"
s.authors = ["thoughtbot", "Joe Ferris", "Jason Morrison", "Tristan Dunn",
"Joshua Clayton", "Yuichi Tateno", "Aaron Gibralter",
"Vasily Reys", "petrushka", "John Bintz", "Chad Pytel",
@@ -58,7 +58,7 @@ def response_headers
end
def status_code
- raise Capybara::NotSupportedByDriverError
+ browser.status_code
end
def within_frame(frame_id_or_index)
@@ -40,6 +40,10 @@ def source
command("Source")
end
+ def status_code
+ command("Status").to_i
+ end
+
def url
command("Url")
end
@@ -14,8 +14,7 @@
@driver.server_port.should eq(@driver.instance_variable_get(:@rack_server).port)
end
- # Can't support:
# it_should_behave_like "driver with header support"
- # it_should_behave_like "driver with status code support"
+ it_should_behave_like "driver with status code support"
# it_should_behave_like "driver with frame support"
end
View
@@ -13,6 +13,7 @@
#include "Header.h"
#include "Render.h"
#include "Body.h"
+#include "Status.h"
#include <QTcpSocket>
#include <iostream>
View
@@ -0,0 +1,13 @@
+#include "Status.h"
+#include "WebPage.h"
+#include <sstream>
+
+Status::Status(WebPage *page, QObject *parent) : Command(page, parent) {
+}
+
+void Status::start(QStringList &arguments) {
+ Q_UNUSED(arguments);
+ int status = page()->getLastStatus();
+ emit finished(new Response(true, QString::number(status)));
+}
+
View
@@ -0,0 +1,12 @@
+#include "Command.h"
+
+class WebPage;
+
+class Status : public Command {
+ Q_OBJECT
+
+ public:
+ Status(WebPage *page, QObject *parent = 0);
+ virtual void start(QStringList &arguments);
+};
+
View
@@ -10,7 +10,9 @@ WebPage::WebPage(QObject *parent) : QWebPage(parent) {
m_loading = false;
- this->setNetworkAccessManager(new NetworkAccessManager());
+ NetworkAccessManager *manager = new NetworkAccessManager();
+ this->setNetworkAccessManager(manager);
+ connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
connect(this, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
@@ -164,3 +166,11 @@ bool WebPage::extension(Extension extension, const ExtensionOption *option, Exte
QString WebPage::getLastAttachedFileName() {
return currentFrame()->evaluateJavaScript(QString("Capybara.lastAttachedFile")).toString();
}
+
+void WebPage::replyFinished(QNetworkReply *reply) {
+ lastStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+}
+
+int WebPage::getLastStatus() {
+ return lastStatus;
+}
View
@@ -10,6 +10,7 @@ class WebPage : public QWebPage {
QString failureString();
QString userAgentForUrl(const QUrl &url ) const;
void setUserAgent(QString userAgent);
+ int getLastStatus();
bool render(const QString &fileName);
virtual bool extension (Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0);
@@ -20,6 +21,7 @@ class WebPage : public QWebPage {
void loadFinished(bool);
bool isLoading() const;
void frameCreated(QWebFrame *);
+ void replyFinished(QNetworkReply *reply);
protected:
virtual void javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID);
@@ -35,5 +37,6 @@ class WebPage : public QWebPage {
QString getLastAttachedFileName();
void loadJavascript();
void setUserStylesheet();
+ int lastStatus;
};
View
@@ -15,3 +15,4 @@ CHECK_COMMAND(FrameFocus)
CHECK_COMMAND(Header)
CHECK_COMMAND(Render)
CHECK_COMMAND(Body)
+CHECK_COMMAND(Status)
View
@@ -1,8 +1,8 @@
TEMPLATE = app
TARGET = webkit_server
DESTDIR = .
-HEADERS = WebPage.h Server.h Connection.h Command.h Visit.h Find.h Reset.h Node.h JavascriptInvocation.h Url.h Source.h Evaluate.h Execute.h FrameFocus.h Response.h NetworkAccessManager.h Header.h Render.h body.h
-SOURCES = main.cpp WebPage.cpp Server.cpp Connection.cpp Command.cpp Visit.cpp Find.cpp Reset.cpp Node.cpp JavascriptInvocation.cpp Url.cpp Source.cpp Evaluate.cpp Execute.cpp FrameFocus.cpp Response.cpp NetworkAccessManager.cpp Header.cpp Render.cpp body.cpp
+HEADERS = WebPage.h Server.h Connection.h Command.h Visit.h Find.h Reset.h Node.h JavascriptInvocation.h Url.h Source.h Evaluate.h Execute.h FrameFocus.h Response.h NetworkAccessManager.h Header.h Render.h body.h Status.h
+SOURCES = main.cpp WebPage.cpp Server.cpp Connection.cpp Command.cpp Visit.cpp Find.cpp Reset.cpp Node.cpp JavascriptInvocation.cpp Url.cpp Source.cpp Evaluate.cpp Execute.cpp FrameFocus.cpp Response.cpp NetworkAccessManager.cpp Header.cpp Render.cpp body.cpp Status.cpp
RESOURCES = webkit_server.qrc
QT += network webkit
CONFIG += debug

0 comments on commit 558c58b

Please sign in to comment.