Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

test(input): cover gestures restarted before cancellation sampling

yhha7dfbf5319d5
diff --git a/sdk/tests/ui-drag-cancel-wasm.test.ts b/sdk/tests/ui-drag-cancel-wasm.test.ts
index eeac1ad96..a678ec921 100644
--- a/sdk/tests/ui-drag-cancel-wasm.test.ts
+++ b/sdk/tests/ui-drag-cancel-wasm.test.ts
@@ -45,6 +45,15 @@ describe.skipIf(!HAS_WASM)('drag cancellation on real WASM', () => {
try { inputEventCallbacks(input).onPointerUp(0); } finally { off(); }
takePrimaryPointerCancellation(input); await step(100); stopped();
});
+ it('a new press before sampling cancellation starts a fresh drag', async () => {
+ await drag();
+ inputEventCallbacks(input).onInputCancel!();
+ input.noteMouseDown(0); await step(100); await step(120);
+ expect(app.world.get(entity, DragState).isDragging).toBe(true);
+ expect(app.world.get(entity, Transform).position.x).toBeCloseTo(40);
+ input.noteMouseUp(0); await step(120);
+ expect(app.world.get(entity, DragState).isDragging).toBe(false);
+ });
it.each(['inactive', 'disabled'])('%s targets cannot keep dragging', async kind => {
await drag();
if (kind === 'inactive') app.world.insert(entity, Disabled);
diff --git a/sdk/tests/ui-scroll-motion-wasm.test.ts b/sdk/tests/ui-scroll-motion-wasm.test.ts
index f7f9a4553..49a5092ec 100644
--- a/sdk/tests/ui-scroll-motion-wasm.test.ts
+++ b/sdk/tests/ui-scroll-motion-wasm.test.ts
@@ -65,6 +65,15 @@ describe.skipIf(!HAS_WASM)('scroll motion ownership on real WASM', () => {
for (let i = 0; i < 10; i++) await step(100);
expect(scroll.getOffset().y).toBe(80);
});
+ it('a new press before sampling cancellation grabs from the retained offset', async () => {
+ const scroll = container(); plugin.attachScrollContainer(entity, scroll); await drag();
+ inputEventCallbacks(input).onInputCancel!();
+ input.noteMouseDown(0); await step(200); await step(240);
+ expect(scroll.getOffset().y).toBe(120);
+ inputEventCallbacks(input).onInputCancel!();
+ for (let i = 0; i < 10; i++) await step(300);
+ expect(scroll.getOffset().y).toBe(120);
+ });
it.each(['inactive', 'noninteractive'])('a %s captured viewport stops moving', async kind => {
const scroll = container(); plugin.attachScrollContainer(entity, scroll); await drag();
if (kind === 'inactive') app.world.insert(entity, Disabled);
diff --git a/sdk/tests/web-focus-cancellation.test.ts b/sdk/tests/web-focus-cancellation.test.ts
index a4c2e0752..16e6b6751 100644
--- a/sdk/tests/web-focus-cancellation.test.ts
+++ b/sdk/tests/web-focus-cancellation.test.ts
@@ -36,6 +36,35 @@ it('blur cancels a held mouse without a UI click or stale fixed-step edges', ()
document.dispatchEvent(new MouseEvent('mouseup', { button: 0 }));
expect(input.isMouseButtonReleased(0)).toBe(false);
});
+it('a new mouse press before the next frame replaces the cancelled capture', () => {
+ const { canvas, input } = bind(), book = new UiPointerBook();
+ const first = 1 as Entity, next = 2 as Entity;
+ canvas.dispatchEvent(new MouseEvent('mousedown', { button: 0 }));
+ book.step(uiPointersOf(input), () => first, () => true);
+ expect(book.pressedByPointer(-1)).toBe(first);
+ window.dispatchEvent(new Event('blur'));
+ canvas.dispatchEvent(new MouseEvent('mousedown', { button: 0 }));
+ const events = book.step(uiPointersOf(input), () => next, () => true);
+ expect(events.some(e => e.kind === 'click')).toBe(false);
+ expect(book.pressedByPointer(-1)).toBe(next);
+ input.clearFrameState();
+ document.dispatchEvent(new MouseEvent('mouseup', { button: 0 }));
+ expect(book.step(uiPointersOf(input), () => next, () => true)
+ .filter(e => e.kind === 'click').map(e => e.entity)).toEqual([next]);
+});
+it('sampling a replacement touch does not leave cancellation for a later mouse press', () => {
+ const { canvas, input } = bind(), book = new UiPointerBook(), entity = 1 as Entity;
+ touch(canvas, 'touchstart', [1]);
+ window.dispatchEvent(new Event('blur'));
+ touch(canvas, 'touchstart', [2]);
+ book.step(uiPointersOf(input), () => entity, () => true);
+ input.clearFrameState(); touch(canvas, 'touchend', [2]);
+ book.step(uiPointersOf(input), () => entity, () => true);
+ input.clearFrameState();
+ canvas.dispatchEvent(new MouseEvent('mousedown', { button: 0 }));
+ book.step(uiPointersOf(input), () => entity, () => true);
+ expect(book.pressedByPointer(-1)).toBe(entity);
+});
it('blur cancels every touch and allows the next finger to become primary', () => {
const { canvas, input } = bind(), book = new UiPointerBook();
touch(canvas, 'touchstart', [1, 2]); book.step(uiPointersOf(input), () => 1 as Entity, () => true);