Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #163 from gemini-testing/fix/noscroll-visible
Browse files Browse the repository at this point in the history
Do not scroll to the capture area when it's completely visible
  • Loading branch information
scf2k committed May 7, 2015
2 parents 2a97cb3 + 1d40d37 commit d737699
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
15 changes: 12 additions & 3 deletions lib/browser/client-scripts/gemini.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,21 @@ function prepareScreenshotUnsafe(selectors, opts) {
return rect;
}

window.scrollTo(rect.left, rect.top);

var viewportHeight = window.innerHeight || document.documentElement.clientHeight,
viewportWidth = window.innerWidth || document.documentElement.clientWidth,
documentHeight = document.documentElement.scrollHeight,
documentWidth = document.documentElement.scrollWidth,
coverage;
coverage,
viewPort = new Rect({
left: util.getScrollLeft(),
top: util.getScrollTop(),
width: viewportWidth,
height: viewportHeight
});

if (!viewPort.rectInside(rect)) {
window.scrollTo(rect.left, rect.top);
}

if (opts.coverage) {
coverage = require('./gemini.coverage').collectCoverage(rect);
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/client-scripts/rect.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Rect.prototype = {
},

rectInside: function(rect) {
return util.every(this._keyPoints(), function(point) {
return util.every(rect._keyPoints(), function(point) {
return this.pointInside(point[0], point[1]);
}, this);
},
Expand Down
67 changes: 67 additions & 0 deletions test/rect.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';

var assert = require('chai').assert,
Rect = require('../lib/browser/client-scripts/rect').Rect;

describe('Rect', function() {
describe('constructor', function() {
it('should create instance using width/height properties', function() {
assert.doesNotThrow(function() {
return new Rect({
top: 10,
left: 20,
width: 100,
height: 100
});
});
});

it('should create instance using bottom/right properties', function() {
assert.doesNotThrow(function() {
return new Rect({
top: 10,
left: 20,
bottom: 100,
right: 100
});
});
});

it('should fail when there are no bottom/right or width/height properties', function() {
assert.throws(function() {
return new Rect({top: 10, left: 20});
});
});
});

describe('rectInside', function() {
var rect = new Rect({
top: 10,
left: 20,
width: 100,
height: 100
});

it('should return true when rect is inside', function() {
assert.isTrue(rect.rectInside(
new Rect({
top: rect.top + 10,
left: rect.left + 10,
width: rect.width - 50,
height: rect.height - 50
})
));
});

it('should return false when rect is not inside', function() {
assert.isFalse(rect.rectInside(
new Rect({
top: rect.top - 5,
left: rect.left - 5,
width: rect.width,
height: rect.width
})
));
});
});
});

0 comments on commit d737699

Please sign in to comment.