2018-11-21 03:43:07 +00:00
|
|
|
/**
|
2024-01-03 10:11:33 +00:00
|
|
|
* @license
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2018-11-21 03:43:07 +00:00
|
|
|
*/
|
|
|
|
|
2020-06-23 05:18:46 +00:00
|
|
|
import expect from 'expect';
|
2023-02-15 23:09:31 +00:00
|
|
|
|
2023-07-03 12:01:29 +00:00
|
|
|
import {getTestState, setupTestBrowserHooks} from './mocha-utils.js';
|
2020-04-09 05:56:25 +00:00
|
|
|
|
2023-10-06 09:08:44 +00:00
|
|
|
declare const allEvents: Array<{type: string}>;
|
|
|
|
|
|
|
|
describe('Touchscreen', () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
setupTestBrowserHooks();
|
|
|
|
|
2023-10-06 09:08:44 +00:00
|
|
|
describe('Touchscreen.prototype.tap', () => {
|
|
|
|
it('should work', async () => {
|
|
|
|
const {page, server, isHeadless} = await getTestState();
|
|
|
|
await page.goto(server.PREFIX + '/input/touchscreen.html');
|
2023-02-03 10:59:21 +00:00
|
|
|
|
2023-10-06 09:08:44 +00:00
|
|
|
await page.tap('button');
|
|
|
|
expect(
|
|
|
|
(
|
|
|
|
await page.evaluate(() => {
|
|
|
|
return allEvents;
|
|
|
|
})
|
|
|
|
).filter(({type}) => {
|
|
|
|
return type !== 'pointermove' || isHeadless;
|
|
|
|
})
|
|
|
|
).toMatchObject([
|
|
|
|
{height: 1, type: 'pointerdown', width: 1, x: 5, y: 5},
|
|
|
|
{touches: [[5, 5, 0.5, 0.5]], type: 'touchstart'},
|
|
|
|
{height: 1, type: 'pointerup', width: 1, x: 5, y: 5},
|
|
|
|
{touches: [[5, 5, 0.5, 0.5]], type: 'touchend'},
|
|
|
|
{height: 1, type: 'click', width: 1, x: 5, y: 5},
|
|
|
|
]);
|
|
|
|
});
|
2018-11-21 03:43:07 +00:00
|
|
|
});
|
2023-02-03 10:59:21 +00:00
|
|
|
|
2023-10-06 09:08:44 +00:00
|
|
|
describe('Touchscreen.prototype.touchMove', () => {
|
|
|
|
it('should work', async () => {
|
|
|
|
const {page, server, isHeadless} = await getTestState();
|
|
|
|
await page.goto(server.PREFIX + '/input/touchscreen.html');
|
|
|
|
|
|
|
|
await page.touchscreen.touchStart(0, 0);
|
|
|
|
await page.touchscreen.touchMove(10, 10);
|
|
|
|
await page.touchscreen.touchMove(15.5, 15);
|
|
|
|
await page.touchscreen.touchMove(20, 20.4);
|
|
|
|
await page.touchscreen.touchMove(40, 30);
|
|
|
|
await page.touchscreen.touchEnd();
|
|
|
|
expect(
|
|
|
|
(
|
|
|
|
await page.evaluate(() => {
|
|
|
|
return allEvents;
|
|
|
|
})
|
|
|
|
).filter(({type}) => {
|
|
|
|
return type !== 'pointermove' || isHeadless;
|
|
|
|
})
|
|
|
|
).toMatchObject(
|
|
|
|
[
|
|
|
|
{type: 'pointerdown', x: 0, y: 0, width: 1, height: 1},
|
|
|
|
{type: 'touchstart', touches: [[0, 0, 0.5, 0.5]]},
|
|
|
|
{type: 'pointermove', x: 10, y: 10, width: 1, height: 1},
|
|
|
|
{type: 'touchmove', touches: [[10, 10, 0.5, 0.5]]},
|
|
|
|
{type: 'pointermove', x: 16, y: 15, width: 1, height: 1},
|
|
|
|
{type: 'touchmove', touches: [[16, 15, 0.5, 0.5]]},
|
|
|
|
{type: 'pointermove', x: 20, y: 20, width: 1, height: 1},
|
|
|
|
{type: 'touchmove', touches: [[20, 20, 0.5, 0.5]]},
|
|
|
|
{type: 'pointermove', x: 40, y: 30, width: 1, height: 1},
|
|
|
|
{type: 'touchmove', touches: [[40, 30, 0.5, 0.5]]},
|
|
|
|
{type: 'pointerup', x: 40, y: 30, width: 1, height: 1},
|
|
|
|
{type: 'touchend', touches: [[40, 30, 0.5, 0.5]]},
|
|
|
|
].filter(({type}) => {
|
|
|
|
return type !== 'pointermove' || isHeadless;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2023-02-03 10:59:21 +00:00
|
|
|
});
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|