-
-
Notifications
You must be signed in to change notification settings - Fork 767
test: mobile e2e instance and the test-layer ladder #3029
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
Open
Open
Changes from all commits
Commits
Show all changes
2 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * Asserts that the android instance's touch emulation is still in effect. | ||
| * | ||
| * The emulation itself is configured per instance in vite.config.browser.ts | ||
| * (the playwright provider's contextOptions) — this cannot re-create it, only | ||
| * detect its loss. Loss has one known cause: Playwright's element-screenshot | ||
| * path for **iframe elements** (what `screenshotFull` captures for export | ||
| * previews) rewrites the device-metrics override and permanently drops the | ||
| * context's touch emulation — `navigator.maxTouchPoints` becomes 0 for every | ||
| * later test file. The android instance therefore keeps such suites out of | ||
| * its include; touch-dependent tests call this in `beforeEach` so that if the | ||
| * include ever regresses, the run fails naming the cause instead of silently | ||
| * testing a desktop context that merely claims to be mobile. | ||
| */ | ||
| export function ensureTouchEmulation() { | ||
| if ( | ||
| navigator.maxTouchPoints === 0 || | ||
| !window.matchMedia("(pointer: coarse)").matches | ||
| ) { | ||
| throw new Error( | ||
| "Touch emulation has been dropped for this browser context. A " + | ||
| "previously run test file took an iframe-element screenshot " + | ||
| "(screenshotFull), which permanently disables the context's touch " + | ||
| "emulation — keep such suites out of the android instance's include " + | ||
| "in vite.config.browser.ts.", | ||
| ); | ||
| } | ||
| } | ||
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,69 @@ | ||
| import type { BrowserCommand } from "vite-plus/test/node"; | ||
|
|
||
| /** | ||
| * One step of an emulated IME session. `setComposition` updates the active | ||
| * composition (starting one if none is active); `commit` finalizes it with | ||
| * the given text — pass different text than the last composition update to | ||
| * emulate an autocorrect-style replacement. | ||
| */ | ||
| export type ImeStep = | ||
| | { | ||
| type: "setComposition"; | ||
| text: string; | ||
| selectionStart?: number; | ||
| selectionEnd?: number; | ||
| /** | ||
| * With `replacementEnd`, the composition replaces this range of | ||
| * already-committed text instead of inserting at the caret — the shape | ||
| * of retroactive autocorrect (e.g. Gboard fixing the previous word when | ||
| * space is typed). Offsets are in the focused editable's text. | ||
| */ | ||
| replacementStart?: number; | ||
| replacementEnd?: number; | ||
| } | ||
| | { type: "commit"; text: string }; | ||
|
|
||
| /** | ||
| * Browser-side signature of the {@link imeComposition} command (Vitest strips | ||
| * the Node-only context parameter — see positionalMouse.ts for the pattern). | ||
| */ | ||
| export type ImeCompositionCommand = (steps: ImeStep[]) => Promise<void>; | ||
|
|
||
| /** | ||
| * Drives Chromium's real IME composition pipeline over CDP | ||
| * (`Input.imeSetComposition` / `Input.insertText`): the browser produces the | ||
| * genuine `compositionstart/update/end` + `beforeinput: | ||
| * insertCompositionText` sequence with actual DOM mutation, targeting the | ||
| * focused element — the same events a mobile IME (Gboard, Samsung Keyboard) | ||
| * generates, which no synthetic `CompositionEvent` dispatch can reproduce | ||
| * (those are untrusted and never touch the DOM). Chromium-only. | ||
| */ | ||
| export const imeComposition: BrowserCommand<[steps: ImeStep[]]> = async ( | ||
| ctx, | ||
| steps, | ||
| ) => { | ||
| const cdp = await ctx.context.newCDPSession(ctx.page); | ||
| try { | ||
| for (const step of steps) { | ||
| if (step.type === "setComposition") { | ||
| await cdp.send("Input.imeSetComposition", { | ||
| text: step.text, | ||
| selectionStart: step.selectionStart ?? step.text.length, | ||
| selectionEnd: step.selectionEnd ?? step.text.length, | ||
| ...(step.replacementEnd !== undefined | ||
| ? { | ||
| replacementStart: step.replacementStart ?? 0, | ||
| replacementEnd: step.replacementEnd, | ||
| } | ||
| : {}), | ||
| }); | ||
| } else { | ||
| await cdp.send("Input.insertText", { text: step.text }); | ||
| } | ||
| } | ||
| } finally { | ||
| await cdp.detach().catch(() => { | ||
| // Session already gone (e.g. page navigated) — nothing to clean up. | ||
| }); | ||
| } | ||
| }; |
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
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.