diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index 9dc5ff9..0ae0625 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -786,6 +786,36 @@ describe Capybara::Driver::Webkit do end end + context "custom font app" do + before(:all) do + @app = lambda do |env| + body = <<-HTML + + + + + +

Hello

+ + + HTML + [200, + { 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s }, + [body]] + end + end + + it "ignores custom fonts" do + font_family = subject.evaluate_script(<<-SCRIPT) + var element = document.getElementById("text"); + element.ownerDocument.defaultView.getComputedStyle(element, null).getPropertyValue("font-family"); + SCRIPT + font_family.should == "Arial" + end + end + context "with socket debugger" do let(:socket_debugger_class){ Capybara::Driver::Webkit::SocketDebugger } let(:browser_with_debugger){ diff --git a/src/WebPage.cpp b/src/WebPage.cpp index e14d3b4..8789c3e 100644 --- a/src/WebPage.cpp +++ b/src/WebPage.cpp @@ -6,6 +6,7 @@ WebPage::WebPage(QObject *parent) : QWebPage(parent) { loadJavascript(); + setUserStylesheet(); m_loading = false; @@ -30,6 +31,12 @@ void WebPage::loadJavascript() { } } +void WebPage::setUserStylesheet() { + QString data = QString("* { font-family: 'Arial' ! important; }").toUtf8().toBase64(); + QUrl url = QUrl(QString("data:text/css;charset=utf-8;base64,") + data); + settings()->setUserStyleSheetUrl(url); +} + QString WebPage::userAgentForUrl(const QUrl &url ) const { if (!m_userAgent.isEmpty()) { return m_userAgent; diff --git a/src/WebPage.h b/src/WebPage.h index ff3b775..a1c737b 100644 --- a/src/WebPage.h +++ b/src/WebPage.h @@ -34,5 +34,6 @@ class WebPage : public QWebPage { bool m_loading; QString getLastAttachedFileName(); void loadJavascript(); + void setUserStylesheet(); };