Permalink
Browse files

Restore viewport dimensions after rendering screenshots

Fixes #388.
  • Loading branch information...
1 parent 495e291 commit eb7104cb850bad7ba571d3d50cd95e9e65585ddf @mhoran mhoran committed Jan 13, 2013
Showing with 28 additions and 8 deletions.
  1. +24 −4 spec/driver_rendering_spec.rb
  2. +1 −2 src/Render.cpp
  3. +2 −1 src/WebPage.cpp
  4. +1 −1 src/WebPage.h
View
28 spec/driver_rendering_spec.rb
@@ -43,7 +43,7 @@ def render(options)
end
it "height should be at least 10px" do
- @image[:height].should >= 10
+ @image[:height].should be >= 10
end
end
@@ -55,19 +55,39 @@ def render(options)
end
it "height should match the height given" do
- @image[:height].should > 10
+ @image[:height].should == 400
+ end
+
+ it "should reset window dimensions to their default value" do
+ driver.evaluate_script('window.innerWidth').should == 1680
+ driver.evaluate_script('window.innerHeight').should == 1050
end
end
context "with dimensions set smaller than the document's default" do
before { render(:width => 50, :height => 10) }
it "width should be greater than the width given" do
- @image[:width].should > 50
+ @image[:width].should be > 50
end
it "height should be greater than the height given" do
- @image[:height].should > 10
+ @image[:height].should be > 10
+ end
+
+ it "should restore viewport dimensions after rendering" do
+ driver.evaluate_script('window.innerWidth').should == 1680
+ driver.evaluate_script('window.innerHeight').should == 1050
+ end
+ end
+
+ context "with a custom viewport size" do
+ before { driver.resize_window(800, 600) }
+
+ it "should restore viewport dimensions after rendering" do
+ render({})
+ driver.evaluate_script('window.innerWidth').should == 800
+ driver.evaluate_script('window.innerHeight').should == 600
end
end
end
View
3 src/Render.cpp
@@ -11,9 +11,8 @@ void Render::start() {
int height = arguments()[2].toInt();
QSize size(width, height);
- page()->setViewportSize(size);
- bool result = page()->render( imagePath );
+ bool result = page()->render( imagePath, size );
emitFinished(result);
}
View
3 src/WebPage.cpp
@@ -193,12 +193,13 @@ QString WebPage::failureString() {
return message + m_errorPageMessage;
}
-bool WebPage::render(const QString &fileName) {
+bool WebPage::render(const QString &fileName, const QSize &minimumSize) {
QFileInfo fileInfo(fileName);
QDir dir;
dir.mkpath(fileInfo.absolutePath());
QSize viewportSize = this->viewportSize();
+ this->setViewportSize(minimumSize);
QSize pageSize = this->mainFrame()->contentsSize();
if (pageSize.isEmpty()) {
return false;
View
2 src/WebPage.h
@@ -20,7 +20,7 @@ class WebPage : public QWebPage {
void setPromptText(QString action);
int getLastStatus();
void setCustomNetworkAccessManager();
- bool render(const QString &fileName);
+ bool render(const QString &fileName, const QSize &minimumSize);
virtual bool extension (Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0);
void setSkipImageLoading(bool skip);
QVariantList consoleMessages();

0 comments on commit eb7104c

Please sign in to comment.