From afe5c470792699421af8116f9ca32bd799f6c428 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Mon, 31 Oct 2011 22:14:24 +0000 Subject: [PATCH] Default the viewport size to 1024x768 --- lib/capybara/poltergeist/client/compiled/main.js | 2 +- lib/capybara/poltergeist/client/compiled/web_page.js | 4 ++++ lib/capybara/poltergeist/client/web_page.coffee | 4 +++- spec/integration/session_spec.rb | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/capybara/poltergeist/client/compiled/main.js b/lib/capybara/poltergeist/client/compiled/main.js index 35d0088..0bbe4df 100644 --- a/lib/capybara/poltergeist/client/compiled/main.js +++ b/lib/capybara/poltergeist/client/compiled/main.js @@ -35,4 +35,4 @@ phantom.injectJs('web_page.js'); phantom.injectJs('node.js'); phantom.injectJs('connection.js'); phantom.injectJs('browser.js'); -new Poltergeist(phantom.args[0]); +new Poltergeist(phantom.args[0]); \ No newline at end of file diff --git a/lib/capybara/poltergeist/client/compiled/web_page.js b/lib/capybara/poltergeist/client/compiled/web_page.js index 2bae736..6ab4b1f 100644 --- a/lib/capybara/poltergeist/client/compiled/web_page.js +++ b/lib/capybara/poltergeist/client/compiled/web_page.js @@ -9,6 +9,10 @@ Poltergeist.WebPage = (function() { this["native"] = require('webpage').create(); this.nodes = {}; this._source = ""; + this["native"].viewportSize = { + width: 1024, + height: 768 + }; _ref = WebPage.CALLBACKS; for (_i = 0, _len = _ref.length; _i < _len; _i++) { callback = _ref[_i]; diff --git a/lib/capybara/poltergeist/client/web_page.coffee b/lib/capybara/poltergeist/client/web_page.coffee index 6157a5f..14a3884 100644 --- a/lib/capybara/poltergeist/client/web_page.coffee +++ b/lib/capybara/poltergeist/client/web_page.coffee @@ -9,6 +9,8 @@ class Poltergeist.WebPage @nodes = {} @_source = "" + @native.viewportSize = { width: 1024, height: 768 } + for callback in WebPage.CALLBACKS this.bindCallback(callback) @@ -27,7 +29,7 @@ class Poltergeist.WebPage onInitializedNative: -> @_source = null this.injectAgent() - this.setScrollPosition({ left: 0, top: 0}) + this.setScrollPosition({ left: 0, top: 0 }) injectAgent: -> if this.evaluate(-> typeof __poltergeist) == "undefined" diff --git a/spec/integration/session_spec.rb b/spec/integration/session_spec.rb index a8cb197..01bd766 100644 --- a/spec/integration/session_spec.rb +++ b/spec/integration/session_spec.rb @@ -45,6 +45,11 @@ describe Capybara::Session do @session.should have_content("Hello") other_session.should have_content("Hello") end + + it 'should have a viewport size of 1024x768 by default' do + @session.visit('/') + @session.evaluate_script('[window.innerWidth, window.innerHeight]').should == [1024, 768] + end end end end