Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support for localStorage

  • Loading branch information...
commit e1e8351131a467ffc35b5996d7696cf600b7d419 1 parent fc5cba3
@chrisfarber authored
View
15 lib/capybara/driver/webkit/browser.rb
@@ -108,6 +108,15 @@ def render(path, width, height)
command "Render", path, width, height
end
+ def set_attribute(attr, value = true)
+ value = value ? "true" : "false"
+ command("SetAttribute", normalize_attr(attr), value)
+ end
+
+ def reset_attribute(attr)
+ command("SetAttribute", normalize_attr(attr), "reset")
+ end
+
def set_cookie(cookie)
command "SetCookie", cookie
end
@@ -242,5 +251,11 @@ def default_proxy_options
:pass => ""
}
end
+
+ def normalize_attr(attr)
+ attr.to_s.split(/_/).reject { |s| s.empty? }.map do |s|
+ s[0,1].upcase + s[1..-1]
+ end.join
+ end
end
end
View
1  src/CommandFactory.cpp
@@ -21,6 +21,7 @@
#include "ConsoleMessages.h"
#include "RequestedUrl.h"
#include "CurrentUrl.h"
+#include "SetAttribute.h"
CommandFactory::CommandFactory(WebPage *page, QObject *parent) : QObject(parent) {
m_page = page;
View
1  src/Reset.cpp
@@ -16,6 +16,7 @@ void Reset::start(QStringList &arguments) {
page()->setUserAgent(NULL);
page()->resetResponseHeaders();
page()->resetConsoleMessages();
+ page()->resetSettings();
resetHistory();
emit finished(new Response(true));
}
View
40 src/SetAttribute.cpp
@@ -0,0 +1,40 @@
+#include "SetAttribute.h"
+#include "WebPage.h"
+#include <QWebSettings>
+#include <iostream>
+
+static QMap<QString, QWebSettings::WebAttribute> getAttributesByName()
+{
+ QMap<QString, QWebSettings::WebAttribute> map;
+ map.insert("LocalStorageEnabled", QWebSettings::LocalStorageEnabled);
+ map.insert("LocalStorageDatabaseEnabled", QWebSettings::LocalStorageDatabaseEnabled);
+ return map;
+}
+
+const QMap<QString, QWebSettings::WebAttribute> attributes_by_name = getAttributesByName();
+
+SetAttribute::SetAttribute(WebPage *page, QObject *parent)
+ : Command(page, parent)
+{
+}
+
+void SetAttribute::start(QStringList &arguments)
+{
+ if (!attributes_by_name.contains(arguments[0])) {
+ // not found
+ emit finished(new Response(false, QString("No such attribute: " + arguments[0])));
+ return;
+ }
+
+ QWebSettings::WebAttribute attr = attributes_by_name[arguments[0]];
+
+ if (arguments[1] != "reset") {
+ page()->settings()->setAttribute(attr, arguments[1] != "false");
+ }
+ else {
+ page()->settings()->resetAttribute(attr);
+ }
+
+ emit finished(new Response(true));
+}
+
View
17 src/SetAttribute.h
@@ -0,0 +1,17 @@
+#include "Command.h"
+#include <QMap>
+#include <QString>
+#include <QWebSettings>
+
+extern const QMap<QString, QWebSettings::WebAttribute> attributes_by_name;
+
+class WebPage;
+
+class SetAttribute : public Command {
+ Q_OBJECT;
+
+ public:
+ SetAttribute(WebPage *page, QObject *parent = 0);
+ virtual void start(QStringList &arguments);
+};
+
View
6 src/WebPage.cpp
@@ -3,6 +3,7 @@
#include "NetworkAccessManager.h"
#include "NetworkCookieJar.h"
#include "UnsupportedContentHandler.h"
+#include "SetAttribute.h"
#include <QResource>
#include <iostream>
@@ -213,6 +214,11 @@ bool WebPage::ignoreSslErrors() {
return m_ignoreSslErrors;
}
+void WebPage::resetSettings() {
+ foreach (QWebSettings::WebAttribute attr, attributes_by_name) {
+ settings()->resetAttribute(attr);
+ }
+}
int WebPage::getLastStatus() {
return m_lastStatus;
View
1  src/WebPage.h
@@ -31,6 +31,7 @@ class WebPage : public QWebPage {
void replyFinished(QNetworkReply *reply);
void ignoreSslErrors(QNetworkReply *reply, const QList<QSslError> &);
void handleUnsupportedContent(QNetworkReply *reply);
+ void resetSettings();
signals:
void pageFinished(bool);
View
1  src/find_command.h
@@ -25,3 +25,4 @@ CHECK_COMMAND(SetProxy)
CHECK_COMMAND(ConsoleMessages)
CHECK_COMMAND(RequestedUrl)
CHECK_COMMAND(CurrentUrl)
+CHECK_COMMAND(SetAttribute)
View
2  src/webkit_server.pro
@@ -34,6 +34,7 @@ HEADERS = \
CommandParser.h \
CommandFactory.h \
SetProxy.h \
+ SetAttribute.h \
SOURCES = \
CurrentUrl.cpp \
@@ -69,6 +70,7 @@ SOURCES = \
CommandParser.cpp \
CommandFactory.cpp \
SetProxy.cpp \
+ SetAttribute.cpp \
RESOURCES = webkit_server.qrc
QT += network webkit
Please sign in to comment.
Something went wrong with that request. Please try again.