Merge branch 'MDL-54920-master' of https://github.com/sammarshallou/moodle

This commit is contained in:
Andrew Nicols 2016-06-21 14:15:41 +08:00
commit bc341d4f08
2 changed files with 26 additions and 4 deletions

View File

@ -619,9 +619,10 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext {
* - large: 2560x1600
*
* @param string $windowsize size of window.
* @param bool $viewport If true, changes viewport rather than window size
* @throws ExpectationException
*/
protected function resize_window($windowsize) {
protected function resize_window($windowsize, $viewport = false) {
// Non JS don't support resize window.
if (!$this->running_javascript()) {
return;
@ -649,6 +650,25 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext {
$width = (int) $size[0];
$height = (int) $size[1];
}
if ($viewport) {
// When setting viewport size, we set it so that the document width will be exactly
// as specified, assuming that there is a vertical scrollbar. (In cases where there is
// no scrollbar it will be slightly wider. We presume this is rare and predictable.)
// The window inner height will be as specified, which means the available viewport will
// actually be smaller if there is a horizontal scrollbar. We assume that horizontal
// scrollbars are rare so this doesn't matter.
$offset = $this->getSession()->getDriver()->evaluateScript(
'return (function() { var before = document.body.style.overflowY;' .
'document.body.style.overflowY = "scroll";' .
'var result = {};' .
'result.x = window.outerWidth - document.body.offsetWidth;' .
'result.y = window.outerHeight - window.innerHeight;' .
'document.body.style.overflowY = before;' .
'return result; })();');
$width += $offset['x'];
$height += $offset['y'];
}
$this->getSession()->getDriver()->resizeWindow($width, $height);
}

View File

@ -1057,13 +1057,15 @@ class behat_general extends behat_base {
* Change browser window size small: 640x480, medium: 1024x768, large: 2560x1600, custom: widthxheight
*
* Example: I change window size to "small" or I change window size to "1024x768"
* or I change viewport size to "800x600". The viewport option is useful to guarantee that the
* browser window has same viewport size even when you run Behat on multiple operating systems.
*
* @throws ExpectationException
* @Then /^I change window size to "(small|medium|large|\d+x\d+)"$/
* @Then /^I change (window|viewport) size to "(small|medium|large|\d+x\d+)"$/
* @param string $windowsize size of the window (small|medium|large|wxh).
*/
public function i_change_window_size_to($windowsize) {
$this->resize_window($windowsize);
public function i_change_window_size_to($windowviewport, $windowsize) {
$this->resize_window($windowsize, $windowviewport === 'viewport');
}
/**