feat: correctly identify permissions when using setPermissionRequestHandler (#26172)
* fix: correctly identify clipboard read permission * Update tests for variable clipboard content * chore: add all possible permission conversions * VIDEO_CAPTURE and AUDIO_CAPTURE were already defined * Handle all PermissionTypes * use skewer case for accessibility events to match permissions api https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API
This commit is contained in:
parent
07ee75b745
commit
7f9b21daa0
3 changed files with 97 additions and 1 deletions
|
@ -1503,3 +1503,56 @@ describe('navigator.serial', () => {
|
|||
expect(port).to.equal('[object SerialPort]');
|
||||
});
|
||||
});
|
||||
|
||||
describe('navigator.clipboard', () => {
|
||||
let w: BrowserWindow;
|
||||
before(async () => {
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
enableBlinkFeatures: 'Serial'
|
||||
}
|
||||
});
|
||||
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
|
||||
});
|
||||
|
||||
const readClipboard: any = () => {
|
||||
return w.webContents.executeJavaScript(`
|
||||
navigator.clipboard.read().then(clipboard => clipboard.toString()).catch(err => err.message);
|
||||
`, true);
|
||||
};
|
||||
|
||||
after(closeAllWindows);
|
||||
afterEach(() => {
|
||||
session.defaultSession.setPermissionRequestHandler(null);
|
||||
});
|
||||
|
||||
it('returns clipboard contents when a PermissionRequestHandler is not defined', async () => {
|
||||
const clipboard = await readClipboard();
|
||||
expect(clipboard).to.not.equal('Read permission denied.');
|
||||
});
|
||||
|
||||
it('returns an error when permission denied', async () => {
|
||||
session.defaultSession.setPermissionRequestHandler((wc, permission, callback) => {
|
||||
if (permission === 'clipboard-read') {
|
||||
callback(false);
|
||||
} else {
|
||||
callback(true);
|
||||
}
|
||||
});
|
||||
const clipboard = await readClipboard();
|
||||
expect(clipboard).to.equal('Read permission denied.');
|
||||
});
|
||||
|
||||
it('returns clipboard contents when permission is granted', async () => {
|
||||
session.defaultSession.setPermissionRequestHandler((wc, permission, callback) => {
|
||||
if (permission === 'clipboard-read') {
|
||||
callback(true);
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
});
|
||||
const clipboard = await readClipboard();
|
||||
expect(clipboard).to.not.equal('Read permission denied.');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue