Commit 64d7050f 64d7050f3e9f8de4f4cc9cde1d6f6a8fb808cfd8 by Nicolas Perriault

fixed #387 - Setting viewport isn't quite synchronous

1 parent 63367591
......@@ -66,6 +66,7 @@ Last, all the casper test suites have been upgraded to use the new testing featu
- closed [#392](https://github.com/n1k0/casperjs/issues/392) - `--direct` & `--log-level` options available for the `casperjs` executable
- closed [#350](https://github.com/n1k0/casperjs/issues/350) - Add a Casper.waitForSelectorTextChange() method
- fixed [#387](https://github.com/n1k0/casperjs/issues/387) - Setting viewport isn't quite synchronous
2013-02-08, v1.0.2
------------------
......
......@@ -1645,13 +1645,15 @@ Casper.prototype.userAgent = function userAgent(agent) {
};
/**
* Changes the current viewport size.
* Changes the current viewport size. That operation is asynchronous as the page
* has to reflow its contents accordingly.
*
* @param Number width The viewport width, in pixels
* @param Number height The viewport height, in pixels
* @param Number width The viewport width, in pixels
* @param Number height The viewport height, in pixels
* @param Function then Next step to process (optional)
* @return Casper
*/
Casper.prototype.viewport = function viewport(width, height) {
Casper.prototype.viewport = function viewport(width, height, then) {
"use strict";
this.checkStarted();
if (!utils.isNumber(width) || !utils.isNumber(height) || width <= 0 || height <= 0) {
......@@ -1662,7 +1664,7 @@ Casper.prototype.viewport = function viewport(width, height) {
height: height
};
this.emit('viewport.changed', [width, height]);
return this;
return utils.isFunction(then) ? this.then(then) : this;
};
/**
......
/*global casper*/
/*jshint strict:false*/
var utils = require('utils');
casper.test.begin('viewport() tests', 3, function(test) {
casper.start();
casper.viewport(1337, 999);
......@@ -11,3 +13,22 @@ casper.test.begin('viewport() tests', 3, function(test) {
'Casper.viewport() validates viewport size data');
test.done();
});
casper.test.begin('viewport() asynchronous tests', 2, function(test) {
var screenshotData;
casper.start('tests/site/index.html').viewport(800, 600, function() {
this.setContent(utils.format('<img src="data:image/png;base64,%s">',
this.captureBase64('png')));
});
casper.then(function() {
var imgInfo = this.getElementInfo('img');
test.assertEquals(imgInfo.width, 800, 'Casper.viewport() changes width asynchronously');
test.assertEquals(imgInfo.height, 600, 'Casper.viewport() changes height asynchronously');
});
casper.run(function() {
test.done();
});
});
......