Permalink
Browse files

Merge pull request #428 from budnik/zoom-factor

add page.zoomFactor=
  • Loading branch information...
2 parents 06e68b4 + d508264 commit 02f63aa8fead20108d2d83be07761cf5fda31abc @route route committed Dec 15, 2013
View
@@ -2,6 +2,8 @@
#### Features ####
+* Added ability to set zoom_factor(Dmytro Budnyk)
+
#### Bug fixes ####
### 1.5.0 ###
@@ -175,6 +175,10 @@ def render_base64(format, options = {})
command 'render_base64', format.to_s, !!options[:full], options[:selector]
end
+ def set_zoom_factor(zoom_factor)
+ command 'set_zoom_factor', zoom_factor
+ end
+
def set_paper_size(size)
command 'set_paper_size', size
end
@@ -293,6 +293,10 @@ class Poltergeist.Browser
@page.setPaperSize(size)
this.sendResponse(true)
+ set_zoom_factor: (zoom_factor) ->
+ @page.setZoomFactor(zoom_factor)
+ this.sendResponse(true)
+
resize: (width, height) ->
@page.setViewportSize(width: width, height: height)
this.sendResponse(true)
@@ -391,6 +391,11 @@ Poltergeist.Browser = (function() {
return this.sendResponse(true);
};
+ Browser.prototype.set_zoom_factor = function(zoom_factor) {
+ this.page.setZoomFactor(zoom_factor);
+ return this.sendResponse(true);
+ };
+
Browser.prototype.resize = function(width, height) {
this.page.setViewportSize({
width: width,
@@ -207,6 +207,10 @@ Poltergeist.WebPage = (function() {
return this["native"].viewportSize = size;
};
+ WebPage.prototype.setZoomFactor = function(zoom_factor) {
+ return this["native"].zoomFactor = zoom_factor;
+ };
+
WebPage.prototype.setPaperSize = function(size) {
return this["native"].paperSize = size;
};
@@ -139,6 +139,9 @@ class Poltergeist.WebPage
setViewportSize: (size) ->
@native.viewportSize = size
+ setZoomFactor: (zoom_factor) ->
+ @native.zoomFactor = zoom_factor
+
setPaperSize: (size) ->
@native.paperSize = size
@@ -165,6 +165,10 @@ def paper_size=(size = {})
browser.set_paper_size(size)
end
+ def zoom_factor=(zoom_factor)
+ browser.set_zoom_factor(zoom_factor)
+ end
+
def resize(width, height)
browser.resize(width, height)
end
@@ -188,6 +188,36 @@ def create_screenshot(file, *args)
expect(File.exist?(file)).to be_true
end
+
+ shared_examples 'when #zoom_factor= is set' do
+ let(:format) {:xbm}
+ it 'changes image dimensions' do
+ @session.visit('/poltergeist/zoom_test')
+
+ black_pixels_count = ->(file) {
+ File.read(file).to_s[/{.*}/m][1...-1].split(/\W/).map{|n| n.hex.to_s(2).count('1')}.reduce(:+)
+ }
+ @driver.save_screenshot(file)
+ before = black_pixels_count[file]
+
+ @driver.zoom_factor = zoom_factor
+ @driver.save_screenshot(file)
+ after = black_pixels_count[file]
+
+ expect(after.to_f/before.to_f).to eq(zoom_factor**2)
+ end
+ end
+
+ context 'zoom in' do
+ let(:zoom_factor) { 2 }
+ include_examples 'when #zoom_factor= is set'
+ end
+
+ context 'zoom out' do
+ let(:zoom_factor) { 0.5 }
+ include_examples 'when #zoom_factor= is set'
+ end
+
context 'when #paper_size= is set' do
let(:format) { :pdf }
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+ <body style="padding: 0; margin: 0; background-color: white">
+ <div style="width: 512px; height: 384px; background-color: black"></div>
+ </body>
+</html>

0 comments on commit 02f63aa

Please sign in to comment.