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
4 changes: 2 additions & 2 deletions src/browser/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function dragDropElems(elem, toElem) {
await sendMouse({ type: 'up' });
}

export async function dragElemBy(elem, offsetX = 0, offsetY = 0) {
export async function dragElemBy(elem, offsetX = 0, offsetY = 0, completeDrag = true) {
const dragIncrementSize = 10; // To mimic real user dragging
const numSteps = Math.ceil(Math.max(Math.abs(offsetX), Math.abs(offsetY)) / dragIncrementSize);

Expand All @@ -53,7 +53,7 @@ export async function dragElemBy(elem, offsetX = 0, offsetY = 0) {
const dy = Math.sign(offsetY) * Math.min(Math.abs(offsetY), dragIncrementSize * i);
await sendMouse({ type: 'move', position: [position.x + dx, position.y + dy] });
}
await sendMouse({ type: 'up' });
if (completeDrag) await sendMouse({ type: 'up' });
}

export async function focusElem(elem) {
Expand Down
3 changes: 2 additions & 1 deletion src/browser/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export async function reset(opts = {}) {

if (shouldResetMouse) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

web-test-runner has a resetMouse command that ideally we would be using. But it doesn't work in --open mode for Chrome at all, because the reset opens up the context menu. Issue is here, and more info in this comment.

shouldResetMouse = false;
await sendMouse({ type: 'move', position: [0, 0] }).catch(() => {});
await sendMouse({ type: 'move', position: [0, 0] });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell, the catch here was added for manual mode. We have removed that mode, and I didn't see any issues when using open.

await sendMouse({ type: 'up' });
}

if (document.activeElement !== document.body) {
Expand Down
32 changes: 32 additions & 0 deletions test/browser/commands.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ describe('commands', () => {
{ x: 75, y: 75 },
]);
});

it('should complete the drag by default', async() => {
expect(dragStarted).to.be.false;
await dragElemBy(elem, 5, 5);
expect(dragMoveEvents).to.deep.equal([{ x: 105, y: 105 }]);
expect(dragStarted).to.be.false;
});

it('supports dragging but not dropping/completing the drag', async() => {
expect(dragStarted).to.be.false;
await dragElemBy(elem, 5, 5, false);
expect(dragMoveEvents).to.deep.equal([{ x: 105, y: 105 }]);
expect(dragStarted).to.be.true;
});
});

describe('drag & drop', () => {
Expand All @@ -286,10 +300,20 @@ describe('commands', () => {
});

describe('mouseReset', () => {
let mouseUpFired = false;
function onMouseUp() {
mouseUpFired = true;
}

beforeEach(async() => {
elem = await fixture(buttonTemplate);
});

afterEach(() => {
window.removeEventListener('mouseup', onMouseUp);
mouseUpFired = false;
});

[
{ command: 'clickElem', action: (elem) => clickElem(elem) },
{ command: 'clickAt', action: () => clickAt(5, 10) },
Expand All @@ -309,6 +333,14 @@ describe('commands', () => {
expect(mousePos.x).to.equal(0);
expect(mousePos.y).to.equal(0);
});

it(`should release mouse after ${command}`, async() => {
await action(elem);
window.addEventListener('mouseup', onMouseUp, { once: true });

await fixture(buttonTemplate);
expect(mouseUpFired).to.be.true;
});
});
});

Expand Down