Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ClientFunction, Selector } from 'testcafe';
import url from '../../../helpers/getPageUrl';
import { createWidget } from '../../../helpers/createWidget';
import { appendElementTo } from '../../../helpers/domUtils';

const WHEEL_STEP_PX = 100;
const WHEEL_STEP_COUNT = 3;

fixture.disablePageReloads`ScrollView_mouseWheel`
.page(url(__dirname, '../../container.html'));

const getScrollPositions = ClientFunction(() => ({
scrollViewTop: (window as any).widget.scrollTop(),
pageTop: window.scrollY,
}));

test('Scrolling a ScrollView by mouse wheel leaves the page in place (T1337899)', async (t) => {
const devTools = await t.getCurrentCDPSession();
const box = await Selector('#scrollView').boundingClientRect;
const x = Math.round(box.left + box.width / 2);
const y = Math.round(box.top + box.height / 2);

await t.hover('#scrollView');

for (let i = 0; i < WHEEL_STEP_COUNT; i += 1) {
await devTools.Input.dispatchMouseEvent({
type: 'mouseWheel', x, y, deltaX: 0, deltaY: WHEEL_STEP_PX,
});
}

await t
.expect(getScrollPositions())
.eql({
scrollViewTop: WHEEL_STEP_PX * WHEEL_STEP_COUNT,
pageTop: 0,
});
}).before(async () => {
await appendElementTo('#container', 'div', 'scrollView');
await appendElementTo('#scrollView', 'div', 'scrollViewContent', { height: '2000px' });
await appendElementTo('#otherContainer', 'div', 'pageContent', { height: '3000px' });

return createWidget('dxScrollView', {
height: 400,
useNative: false,
}, '#scrollView');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import { ClientFunction, Selector } from 'testcafe';
import url from '../../../helpers/getPageUrl';
import { createWidget } from '../../../helpers/createWidget';
import { appendElementTo } from '../../../helpers/domUtils';

type EmulatedTouchType = 'mousePressed' | 'mouseMoved' | 'mouseReleased';

const PAGE_URL = url(__dirname, '../../container.html');
const GESTURE_THRESHOLD_PX = 10;
const FIRST_MOVE_BELOW_GESTURE_THRESHOLD_PX = 9;
const NEXT_MOVE_PX = 15;
const NEXT_MOVE_COUNT = 10;
const FINGER_TRAVEL_PX = FIRST_MOVE_BELOW_GESTURE_THRESHOLD_PX + NEXT_MOVE_PX * NEXT_MOVE_COUNT;
const FINGER_OFFSET_FROM_EDGE_PX = 40;
const UP = -1;
const DOWN = 1;
const ONLY_FIRST_MOVE_CANCELABLE = [true, ...Array<boolean>(NEXT_MOVE_COUNT).fill(false)];

fixture`ScrollView_touchSwipe`
.page(PAGE_URL);

const waitForTwoFrames = ClientFunction(() => new Promise<void>((resolve) => {
requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
}));

const touch = async (
devTools: CDPSession,
type: EmulatedTouchType,
x: number,
y: number,
): Promise<void> => {
await devTools.Input.emulateTouchFromMouseEvent({
type, x, y, button: 'left', clickCount: 1,
});
await waitForTwoFrames();
};

const collectBrowserErrors = async (devTools: CDPSession): Promise<string[]> => {
const browserErrors: string[] = [];

devTools.Log.on('entryAdded', ({ entry }) => {
if (entry.level === 'error') {
browserErrors.push(entry.text);
}
});
await devTools.Log.enable();

return browserErrors;
};

const openPageWithTouchSupport = async (t: TestController): Promise<void> => {
const devTools = await t.getCurrentCDPSession();

await devTools.Emulation.setTouchEmulationEnabled({ enabled: true, maxTouchPoints: 1 });
await t.navigateTo(PAGE_URL);
await appendElementTo('#container', 'div', 'scrollView');
await appendElementTo('#scrollView', 'div', 'scrollViewContent', { height: '2000px' });
};

const restoreMouseInput = async (t: TestController): Promise<void> => {
const devTools = await t.getCurrentCDPSession();

await devTools.Log.disable();
await devTools.Emulation.setEmitTouchEventsForMouse({ enabled: false });
await devTools.Emulation.setTouchEmulationEnabled({ enabled: false });
await t.navigateTo(PAGE_URL);
};

const recordTouchMoveCancelable = ClientFunction(() => {
(window as any).touchMoveCancelable = [];
window.addEventListener('touchmove', (event) => {
(window as any).touchMoveCancelable.push(event.cancelable);
}, { passive: true });
});

const getTouchMoveCancelable = ClientFunction(() => (window as any).touchMoveCancelable);

const getTouchMoveCount = ClientFunction(() => (window as any).touchMoveCancelable.length);

const getScrollTop = ClientFunction(() => (window as any).widget.scrollTop());

const getPullDownCount = ClientFunction(() => (window as any).pullDownCount);

const pressFinger = async (
devTools: CDPSession,
direction: number,
): Promise<{ x: number; y: number }> => {
const box = await Selector('#scrollView').boundingClientRect;

await devTools.Emulation.setEmitTouchEventsForMouse({ enabled: true, configuration: 'mobile' });

const x = Math.round(box.left + box.width / 2);
const y = Math.round(direction === UP
? box.bottom - FINGER_OFFSET_FROM_EDGE_PX
: box.top + FINGER_OFFSET_FROM_EDGE_PX);

await touch(devTools, 'mousePressed', x, y);

return { x, y };
};

const moveFingerTo = async (
t: TestController,
devTools: CDPSession,
x: number,
y: number,
touchMoveCount: number,
): Promise<void> => {
await touch(devTools, 'mouseMoved', x, y);
await t.expect(getTouchMoveCount()).eql(touchMoveCount);
};

const moveFinger = async (
t: TestController,
devTools: CDPSession,
x: number,
startY: number,
direction: number,
): Promise<number> => {
let y = startY + direction * FIRST_MOVE_BELOW_GESTURE_THRESHOLD_PX;
let touchMoveCount = 1;

await moveFingerTo(t, devTools, x, y, touchMoveCount);

for (let i = 0; i < NEXT_MOVE_COUNT; i += 1) {
y += direction * NEXT_MOVE_PX;
touchMoveCount += 1;
await moveFingerTo(t, devTools, x, y, touchMoveCount);
}

return y;
};

test('Swiping a ScrollView by touch does not cancel touchmove events that the browser made uncancelable (T1337899)', async (t) => {
const devTools = await t.getCurrentCDPSession();
const browserErrors = await collectBrowserErrors(devTools);

await recordTouchMoveCancelable();

const { x, y: startY } = await pressFinger(devTools, UP);
const endY = await moveFinger(t, devTools, x, startY, UP);
const scrollTopUnderFinger = await getScrollTop();

await touch(devTools, 'mouseReleased', x, endY);

await t
.expect(await getTouchMoveCancelable())
.eql(ONLY_FIRST_MOVE_CANCELABLE)
.expect(scrollTopUnderFinger)
.eql(FINGER_TRAVEL_PX - GESTURE_THRESHOLD_PX)
.expect(browserErrors)
.eql([]);
}).before(async (t) => {
await openPageWithTouchSupport(t);

return createWidget('dxScrollView', {
height: 400,
useNative: false,
}, '#scrollView');
}).after(restoreMouseInput);

test('Pulling a native ScrollView down to refresh by touch does not cancel touchmove events that the browser made uncancelable (T1337899)', async (t) => {
const devTools = await t.getCurrentCDPSession();
const browserErrors = await collectBrowserErrors(devTools);

await recordTouchMoveCancelable();

const { x, y: startY } = await pressFinger(devTools, DOWN);
const endY = await moveFinger(t, devTools, x, startY, DOWN);

await touch(devTools, 'mouseReleased', x, endY);

await t
.expect(await getTouchMoveCancelable())
.eql(ONLY_FIRST_MOVE_CANCELABLE)
.expect(getPullDownCount())
.eql(1)
.expect(browserErrors)
.eql([]);
}).before(async (t) => {
await openPageWithTouchSupport(t);

return createWidget('dxScrollView', () => ({
height: 400,
useNative: true,
refreshStrategy: 'swipeDown',
onPullDown: ({ component }) => {
(window as any).pullDownCount = ((window as any).pullDownCount ?? 0) + 1;
component.release();
},
}), '#scrollView');
}).after(restoreMouseInput);
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ class SwipeDownNativeScrollViewStrategy<
}

if (this._state === STATE_PULLED) {
e.preventDefault();
if (e.cancelable ?? true) {
e.preventDefault();
}
this._movePullDown();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,10 @@ export class SimulatedStrategy<
return;
}
this._saveActive();
e.preventDefault?.();

if (e.cancelable ?? true) {
e.preventDefault?.();
}

this._adjustDistance(e, e.delta);
this._eventForUserAction = e;
Expand Down
Loading