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 ...@@ -66,6 +66,7 @@ Last, all the casper test suites have been upgraded to use the new testing featu
66 66
67 - closed [#392](https://github.com/n1k0/casperjs/issues/392) - `--direct` & `--log-level` options available for the `casperjs` executable 67 - closed [#392](https://github.com/n1k0/casperjs/issues/392) - `--direct` & `--log-level` options available for the `casperjs` executable
68 - closed [#350](https://github.com/n1k0/casperjs/issues/350) - Add a Casper.waitForSelectorTextChange() method 68 - closed [#350](https://github.com/n1k0/casperjs/issues/350) - Add a Casper.waitForSelectorTextChange() method
69 - fixed [#387](https://github.com/n1k0/casperjs/issues/387) - Setting viewport isn't quite synchronous
69 70
70 2013-02-08, v1.0.2 71 2013-02-08, v1.0.2
71 ------------------ 72 ------------------
......
...@@ -1645,13 +1645,15 @@ Casper.prototype.userAgent = function userAgent(agent) { ...@@ -1645,13 +1645,15 @@ Casper.prototype.userAgent = function userAgent(agent) {
1645 }; 1645 };
1646 1646
1647 /** 1647 /**
1648 * Changes the current viewport size. 1648 * Changes the current viewport size. That operation is asynchronous as the page
1649 * has to reflow its contents accordingly.
1649 * 1650 *
1650 * @param Number width The viewport width, in pixels 1651 * @param Number width The viewport width, in pixels
1651 * @param Number height The viewport height, in pixels 1652 * @param Number height The viewport height, in pixels
1653 * @param Function then Next step to process (optional)
1652 * @return Casper 1654 * @return Casper
1653 */ 1655 */
1654 Casper.prototype.viewport = function viewport(width, height) { 1656 Casper.prototype.viewport = function viewport(width, height, then) {
1655 "use strict"; 1657 "use strict";
1656 this.checkStarted(); 1658 this.checkStarted();
1657 if (!utils.isNumber(width) || !utils.isNumber(height) || width <= 0 || height <= 0) { 1659 if (!utils.isNumber(width) || !utils.isNumber(height) || width <= 0 || height <= 0) {
...@@ -1662,7 +1664,7 @@ Casper.prototype.viewport = function viewport(width, height) { ...@@ -1662,7 +1664,7 @@ Casper.prototype.viewport = function viewport(width, height) {
1662 height: height 1664 height: height
1663 }; 1665 };
1664 this.emit('viewport.changed', [width, height]); 1666 this.emit('viewport.changed', [width, height]);
1665 return this; 1667 return utils.isFunction(then) ? this.then(then) : this;
1666 }; 1668 };
1667 1669
1668 /** 1670 /**
......
1 /*global casper*/ 1 /*global casper*/
2 /*jshint strict:false*/ 2 /*jshint strict:false*/
3 var utils = require('utils');
4
3 casper.test.begin('viewport() tests', 3, function(test) { 5 casper.test.begin('viewport() tests', 3, function(test) {
4 casper.start(); 6 casper.start();
5 casper.viewport(1337, 999); 7 casper.viewport(1337, 999);
...@@ -11,3 +13,22 @@ casper.test.begin('viewport() tests', 3, function(test) { ...@@ -11,3 +13,22 @@ casper.test.begin('viewport() tests', 3, function(test) {
11 'Casper.viewport() validates viewport size data'); 13 'Casper.viewport() validates viewport size data');
12 test.done(); 14 test.done();
13 }); 15 });
16
17 casper.test.begin('viewport() asynchronous tests', 2, function(test) {
18 var screenshotData;
19
20 casper.start('tests/site/index.html').viewport(800, 600, function() {
21 this.setContent(utils.format('<img src="data:image/png;base64,%s">',
22 this.captureBase64('png')));
23 });
24
25 casper.then(function() {
26 var imgInfo = this.getElementInfo('img');
27 test.assertEquals(imgInfo.width, 800, 'Casper.viewport() changes width asynchronously');
28 test.assertEquals(imgInfo.height, 600, 'Casper.viewport() changes height asynchronously');
29 });
30
31 casper.run(function() {
32 test.done();
33 });
34 });
......