#54725: test: wait for the page to be focused before clipboard and paste specs
Description of Change
Make the clipboard, paste and pointer-lock specs wait until the page itself reports focus.
These specs either waited for the webContents 'focus' event or didn't wait at all before calling paste().
That event comes from the browser process, and the page can still report document.hasFocus() === false right after it.
In that window, navigator.clipboard rejects with "Document is not focused." and paste() can be dropped.
Downstream CI hits this on 42-x-y, 43-x-y and 44-x-y: expected 'Document is not focused.' to include 'Read permission denied.' in the clipboard permission spec, and "File System API … denies permission when trying to create a writable file handle".
This change:
- Adds a
focusWebContents()helper tospec/lib/spec-helpers.ts.
It focuses the contents, waits for'focus', and then waits until the page reportsdocument.hasFocus(), requesting focus again while it waits. - Replaces the six copies of the
isFocused()/once('focus')/focus()block with it:navigator.clipboard.readand.write,paste execCommand, pointer lock, user activation, and the File System Access permission scopepasteHandle. - Calls it before each
paste()in the File System API specs, which previously calledfocus()andpaste()with no wait. - In the done-style File System specs, passes any failure while preparing the paste to
done()instead of letting it escape the'did-finish-load'listener.
The other 'focus' waits in api-web-contents.spec.ts test the event itself, so they stay as they are.
Only test code changes.
Validation
Ran on a local Linux testing build of main under Xvfb:
e test --files spec/chromium.spec.ts -g "File System API|File System Access permission scope|navigator.clipboard|paste execCommand|pointer lock permission request|user activation": 28 passed, and 4 of 4 runs passed.script/lint.js --jsandtsc -p tsconfig.spec.jsonpass.
The failures this targets come from downstream CI timing and haven't been reproduced locally.
🤖 Generated with Claude Code
Checklist
- I have built and tested this change
- I have filled out the PR description
- I have reviewed and verified the changes
-
npm testpasses - tests are changed or added
- PR release notes describe the change in a way relevant to app developers, and are capitalized, punctuated, and past tense.
Release Notes
Notes: none
Backports
Semver Impact
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron