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

Response headers supported.

This commit is contained in:
Matthew Mongeau 2011-08-19 11:57:39 -04:00
parent 62b0d854df
commit 7b3d142729
10 changed files with 48 additions and 4 deletions

View file

@ -54,7 +54,7 @@ class Capybara::Driver::Webkit
end end
def response_headers def response_headers
raise Capybara::NotSupportedByDriverError browser.response_headers
end end
def status_code def status_code

View file

@ -44,6 +44,10 @@ class Capybara::Driver::Webkit
command("Status").to_i command("Status").to_i
end end
def response_headers
Hash[command("Headers").split("\n").map { |header| header.split(": ") }]
end
def url def url
command("Url") command("Url")
end end

View file

@ -14,7 +14,7 @@ describe Capybara::Driver::Webkit do
@driver.server_port.should eq(@driver.instance_variable_get(:@rack_server).port) @driver.server_port.should eq(@driver.instance_variable_get(:@rack_server).port)
end end
# it_should_behave_like "driver with header 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" # it_should_behave_like "driver with frame support"
end end

View file

@ -14,6 +14,7 @@
#include "Render.h" #include "Render.h"
#include "Body.h" #include "Body.h"
#include "Status.h" #include "Status.h"
#include "Headers.h"
#include <QTcpSocket> #include <QTcpSocket>
#include <iostream> #include <iostream>

11
src/Headers.cpp Normal file
View file

@ -0,0 +1,11 @@
#include "Headers.h"
#include "WebPage.h"
Headers::Headers(WebPage *page, QObject *parent) : Command(page, parent) {
}
void Headers::start(QStringList &arguments) {
Q_UNUSED(arguments);
emit finished(new Response(true, page()->pageHeaders()));
}

12
src/Headers.h Normal file
View file

@ -0,0 +1,12 @@
#include "Command.h"
class WebPage;
class Headers : public Command {
Q_OBJECT
public:
Headers(WebPage *page, QObject *parent = 0);
virtual void start(QStringList &arguments);
};

View file

@ -168,9 +168,22 @@ QString WebPage::getLastAttachedFileName() {
} }
void WebPage::replyFinished(QNetworkReply *reply) { void WebPage::replyFinished(QNetworkReply *reply) {
QStringList headers;
lastStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); lastStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QList<QByteArray> list = reply->rawHeaderList();
int length = list.size();
for(int i = 0; i < length; i++) {
headers << list.at(i)+": "+reply->rawHeader(list.at(i));
}
m_pageHeaders = headers.join("\n");
} }
int WebPage::getLastStatus() { int WebPage::getLastStatus() {
return lastStatus; return lastStatus;
} }
QString WebPage::pageHeaders() {
return m_pageHeaders;
}

View file

@ -20,6 +20,7 @@ class WebPage : public QWebPage {
void loadStarted(); void loadStarted();
void loadFinished(bool); void loadFinished(bool);
bool isLoading() const; bool isLoading() const;
QString pageHeaders();
void frameCreated(QWebFrame *); void frameCreated(QWebFrame *);
void replyFinished(QNetworkReply *reply); void replyFinished(QNetworkReply *reply);
@ -38,5 +39,6 @@ class WebPage : public QWebPage {
void loadJavascript(); void loadJavascript();
void setUserStylesheet(); void setUserStylesheet();
int lastStatus; int lastStatus;
QString m_pageHeaders;
}; };

View file

@ -16,3 +16,4 @@ CHECK_COMMAND(Header)
CHECK_COMMAND(Render) CHECK_COMMAND(Render)
CHECK_COMMAND(Body) CHECK_COMMAND(Body)
CHECK_COMMAND(Status) CHECK_COMMAND(Status)
CHECK_COMMAND(Headers)

View file

@ -1,8 +1,8 @@
TEMPLATE = app TEMPLATE = app
TARGET = webkit_server TARGET = webkit_server
DESTDIR = . 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 Status.h 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 Headers.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 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 Headers.cpp
RESOURCES = webkit_server.qrc RESOURCES = webkit_server.qrc
QT += network webkit QT += network webkit
CONFIG += console CONFIG += console