зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1319237 - Make GeckoDriver#setWindowSize synchronous; r=automatedtester,maja_zf
Return from the Set Window Size command only after the window resize DOM event has occurred. MozReview-Commit-ID: 7ygZuNJZzq2 --HG-- extra : rebase_source : 3922d86de4eaa854795506b4ff5176ffdd4af98f
This commit is contained in:
Родитель
83dd4e584b
Коммит
3cfd9442a2
|
@ -2419,17 +2419,44 @@ GeckoDriver.prototype.getWindowSize = function (cmd, resp) {
|
||||||
/**
|
/**
|
||||||
* Set the size of the browser window currently in focus.
|
* Set the size of the browser window currently in focus.
|
||||||
*
|
*
|
||||||
* Not supported on B2G. The supplied width and height values refer to
|
* The supplied width and height values refer to the window outerWidth
|
||||||
* the window outerWidth and outerHeight values, which include scroll
|
* and outerHeight values, which include browser chrome and OS-level
|
||||||
* bars, title bars, etc.
|
* window borders.
|
||||||
|
*
|
||||||
|
* @param {number} width
|
||||||
|
* Requested window outer width.
|
||||||
|
* @param {number} height
|
||||||
|
* Requested window outer height.
|
||||||
|
*
|
||||||
|
* @return {Map.<string, number>}
|
||||||
|
* New outerWidth/outerHeight dimensions.
|
||||||
*/
|
*/
|
||||||
GeckoDriver.prototype.setWindowSize = function (cmd, resp) {
|
GeckoDriver.prototype.setWindowSize = function* (cmd, resp) {
|
||||||
assert.firefox()
|
assert.firefox()
|
||||||
|
|
||||||
let {width, height} = cmd.parameters;
|
const {width, height} = cmd.parameters;
|
||||||
let win = this.getCurrentWindow();
|
const win = this.getCurrentWindow();
|
||||||
win.resizeTo(width, height);
|
|
||||||
this.getWindowSize(cmd, resp);
|
yield new Promise(resolve => {
|
||||||
|
// When the DOM resize event claims that it fires _after_ the document
|
||||||
|
// view has been resized, it is lying.
|
||||||
|
//
|
||||||
|
// Because resize events fire at a high rate, DOM modifications
|
||||||
|
// such as updates to outerWidth/outerHeight are not guaranteed to
|
||||||
|
// have processed. To overcome this... abomination... of the web
|
||||||
|
// platform, we throttle the event using setTimeout. If everything
|
||||||
|
// was well in this world we would use requestAnimationFrame, but
|
||||||
|
// it does not seem to like our particular flavour of XUL.
|
||||||
|
const fps15 = 66;
|
||||||
|
const synchronousResize = () => win.setTimeout(resolve, fps15);
|
||||||
|
win.addEventListener("resize", synchronousResize, {once: true});
|
||||||
|
win.resizeTo(width, height);
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
width: win.outerWidth,
|
||||||
|
height: win.outerHeight,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Загрузка…
Ссылка в новой задаче