Repository navigation
test(interaction-harness): name a double tap the page read as two taps #10916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file touch.taps.test.ts | ||
| * @input touch.ts's tap-interval rule (`tapIntervalFault`, a play's | ||
| * `boundaries.tapIntervalMs`) | ||
| * @output Unit cases: a second touch-down received after the tap interval | ||
| * closed is a fault only where the page drew a frame in between. A main | ||
| * thread held across the close leaves the pairing to the component. Neither are taps the script spaces past the | ||
| * interval, nor a lift that leaves a finger down, nor a play without the | ||
| * page's times. | ||
| * @position Node unit tests beside the harness's browser self-tests. | ||
| * | ||
| * SYNC: When modified, update touch.ts (tapIntervalFault). | ||
| */ | ||
|
|
||
| import {describe, expect, it} from 'vitest'; | ||
| import {toTouchEvents, type TouchScript} from './scripts'; | ||
| import {tapIntervalFault} from './touch'; | ||
|
|
||
| const at = {x: 100, y: 200}; | ||
| const doubleTap: TouchScript = [ | ||
| {t: 0, fingers: [{id: 0, ...at}]}, | ||
| {t: 50, fingers: []}, | ||
| {t: 170, fingers: [{id: 0, ...at}]}, | ||
| {t: 220, fingers: []}, | ||
| ]; | ||
| // A frame every 16 ms from 0 to 800 ms. | ||
| const everyFrame = Array.from({length: 51}, (_, i) => i * 16); | ||
|
|
||
| describe('tapIntervalFault', () => { | ||
| it('names a second touch-down that arrived after the interval closed, with the frame between', () => { | ||
| const steps = toTouchEvents(doubleTap); | ||
| // The page sees the scripted stamps; the touch-down arrives at 525 ms. | ||
| const page = { | ||
| stamps: [0, 50, 170, 220], | ||
| receivedAt: [5, 60, 525, 540], | ||
| frames: everyFrame, | ||
| }; | ||
| // The interval closes at 400 ms; the page draws from 416 to 512 ms. | ||
| expect(tapIntervalFault(steps, page, 350)).toEqual({ | ||
| step: 2, | ||
| gapMs: 475, | ||
| scriptedGapMs: 120, | ||
| tapIntervalMs: 350, | ||
| frameAfterCloseMs: 16, | ||
| framesAfterClose: 7, | ||
| }); | ||
| }); | ||
|
|
||
| it('leaves the pairing to the component when the main thread was held across the close', () => { | ||
| const steps = toTouchEvents(doubleTap); | ||
| // No frame from 384 ms until after the touch-down arrived at 525 ms. | ||
| const page = { | ||
| stamps: [0, 50, 170, 220], | ||
| receivedAt: [5, 60, 525, 540], | ||
| frames: everyFrame.filter(time => time <= 384 || time >= 528), | ||
| }; | ||
| expect(tapIntervalFault(steps, page, 350)).toBeNull(); | ||
| }); | ||
|
|
||
| it('finds none when the touch-down arrives before the interval closes', () => { | ||
| const steps = toTouchEvents(doubleTap); | ||
| const page = { | ||
| stamps: [0, 50, 170, 220], | ||
| receivedAt: [5, 60, 380, 400], | ||
| frames: everyFrame, | ||
| }; | ||
| expect(tapIntervalFault(steps, page, 350)).toBeNull(); | ||
| }); | ||
|
|
||
| it('reads arrival stamps where the page stamps touches on arrival', () => { | ||
| const steps = toTouchEvents(doubleTap); | ||
| const stamps = [0, 50, 470, 520]; | ||
| expect( | ||
| tapIntervalFault( | ||
| steps, | ||
| {stamps, receivedAt: stamps, frames: everyFrame}, | ||
| 350, | ||
| )?.gapMs, | ||
| ).toBe(420); | ||
| }); | ||
|
|
||
| it('leaves taps the script spaces past the interval to the script', () => { | ||
| const apart: TouchScript = [ | ||
| {t: 0, fingers: [{id: 0, ...at}]}, | ||
| {t: 50, fingers: []}, | ||
| {t: 600, fingers: [{id: 0, ...at}]}, | ||
| {t: 650, fingers: []}, | ||
| ]; | ||
| const page = { | ||
| stamps: [0, 50, 600, 650], | ||
| receivedAt: [5, 60, 700, 720], | ||
| frames: everyFrame, | ||
| }; | ||
| expect(tapIntervalFault(toTouchEvents(apart), page, 350)).toBeNull(); | ||
| }); | ||
|
|
||
| it('ends a tap only where its last finger lifts', () => { | ||
| // The first finger lifts and lands again while the second stays down: | ||
| // one touch, so the late landing is no second tap. | ||
| const second = {id: 1, x: 150, y: 200}; | ||
| const overlapping: TouchScript = [ | ||
| {t: 0, fingers: [{id: 0, ...at}]}, | ||
| {t: 50, fingers: [{id: 0, ...at}, second]}, | ||
| {t: 100, fingers: [second]}, | ||
| {t: 150, fingers: [second, {id: 0, ...at}]}, | ||
| {t: 200, fingers: []}, | ||
| ]; | ||
| const page = { | ||
| stamps: [0, 50, 100, 150, 200], | ||
| receivedAt: [5, 55, 105, 700, 720], | ||
| frames: everyFrame, | ||
| }; | ||
| expect(tapIntervalFault(toTouchEvents(overlapping), page, 350)).toBeNull(); | ||
| }); | ||
|
|
||
| it("proves nothing without the page's times", () => { | ||
| expect(tapIntervalFault(toTouchEvents(doubleTap), null, 350)).toBeNull(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.