Skip to content

Commit

Permalink
TestCafe should round off dimension's values for scrolling calculation (
Browse files Browse the repository at this point in the history
  • Loading branch information
helen-dikareva authored and AndreyBelym committed Dec 15, 2017
1 parent eade44d commit 1518f32
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/client/core/utils/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function getClientDimensions (target) {
var elementWidth = isHtmlElement ? target.clientWidth : elementRect.width;
var isCompatMode = target.ownerDocument.compatMode === 'BackCompat';

if (isHtmlElement && body && (typeof isIFrameWithoutSrc === 'boolean' && isIFrameWithoutSrc || isCompatMode) ) {
if (isHtmlElement && body && (typeof isIFrameWithoutSrc === 'boolean' && isIFrameWithoutSrc || isCompatMode)) {
elementHeight = body.clientHeight;
elementWidth = body.clientWidth;
}
Expand Down Expand Up @@ -124,11 +124,11 @@ export function getClientDimensions (target) {
}
}

var rightScrollbarWidth = isHtmlElement || styleUtils.getInnerWidth(target) === target.clientWidth ?
0 : domUtils.getScrollbarSize();
const hasRightScrollbar = !isHtmlElement && styleUtils.getInnerWidth(target) !== target.clientWidth;
const rightScrollbarWidth = hasRightScrollbar ? domUtils.getScrollbarSize() : 0;

var bottomScrollbarHeight = isHtmlElement || styleUtils.getInnerHeight(target) === target.clientHeight ?
0 : domUtils.getScrollbarSize();
const hasBottomScrollbar = !isHtmlElement && styleUtils.getInnerHeight(target) !== target.clientHeight;
const bottomScrollbarHeight = hasBottomScrollbar ? domUtils.getScrollbarSize() : 0;

return {
width: elementWidth,
Expand Down Expand Up @@ -188,8 +188,7 @@ export function getEventAbsoluteCoordinates (ev) {
}

export function getEventPageCoordinates (ev) {
var curCoordObject = /^touch/.test(ev.type) && ev.targetTouches ?
ev.targetTouches[0] || ev.changedTouches[0] : ev;
var curCoordObject = /^touch/.test(ev.type) && ev.targetTouches ? ev.targetTouches[0] || ev.changedTouches[0] : ev;

var bothPageCoordinatesAreZero = curCoordObject.pageX === 0 && curCoordObject.pageY === 0;
var notBothClientCoordinatesAreZero = curCoordObject.clientX !== 0 || curCoordObject.clientY !== 0;
Expand Down Expand Up @@ -299,10 +298,15 @@ export function getElementClientRectangle (el) {

export function calcRelativePosition (dimensions, toDimensions) {
return {
left: dimensions.left - (toDimensions.left + toDimensions.border.left),
right: toDimensions.right - toDimensions.border.right - toDimensions.scrollbar.right - dimensions.right,
top: dimensions.top - (toDimensions.top + toDimensions.border.top),
bottom: toDimensions.bottom - toDimensions.border.bottom - toDimensions.scrollbar.bottom - dimensions.bottom
left: Math.ceil(dimensions.left - (toDimensions.left + toDimensions.border.left)),

right: Math.floor(toDimensions.right - toDimensions.border.right - toDimensions.scrollbar.right -
dimensions.right),

top: Math.ceil(dimensions.top - (toDimensions.top + toDimensions.border.top)),

bottom: Math.floor(toDimensions.bottom - toDimensions.border.bottom - toDimensions.scrollbar.bottom -
dimensions.bottom)
};
}

Expand Down
62 changes: 62 additions & 0 deletions test/client/fixtures/automation/regression-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var nativeMethods = hammerhead.nativeMethods;

var testCafeCore = window.getTestCafeModule('testCafeCore');
var eventUtils = testCafeCore.get('./utils/event');
var positionUtils = testCafeCore.get('./utils/position');
var textSelection = testCafeCore.get('./utils/text-selection');
var parseKeySequence = testCafeCore.get('./utils/parse-key-sequence');

Expand Down Expand Up @@ -1052,4 +1053,65 @@ $(document).ready(function () {
});
});
}

test('Scrolling works wrong in specific scenario in IE (gh-2002)', function () {
var mockParentDimension = {
top: 0,
bottom: 782,
height: 782,
left: 0,
right: 1423,
width: 1423,

border: {
top: 0,
right: 0,
bottom: 0,
left: 0
},

scroll: {
left: 0,
top: 255
},

scrollbar: {
bottom: 0,
right: 0
}
};

var mockChildDimension = {
top: 3.91999983787566,
bottom: 777.91999983787566,
height: 774,
left: 571.5,
right: 991.5,
width: 420,

border: {
top: 2,
right: 2,
bottom: 2,
left: 2
},

scroll: {
left: 0,
top: 0
},

scrollbar: {
bottom: 0,
right: 0
}
};

deepEqual(positionUtils.calcRelativePosition(mockChildDimension, mockParentDimension), {
top: 4,
right: 431,
bottom: 4,
left: 572
});
});
});

0 comments on commit 1518f32

Please sign in to comment.