docs: document idleDetector permissions (#39214)

doc: document idleDetector permissions

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot]
2023-07-25 11:50:29 +02:00
committed by GitHub
parent 24f2379892
commit 03ed9531d4
3 changed files with 118 additions and 9 deletions

View File

@@ -1304,6 +1304,94 @@ describe('chromium features', () => {
});
});
describe('IdleDetection', () => {
afterEach(closeAllWindows);
afterEach(() => {
session.defaultSession.setPermissionCheckHandler(null);
session.defaultSession.setPermissionRequestHandler(null);
});
it('can grant a permission request', async () => {
session.defaultSession.setPermissionRequestHandler(
(_wc, permission, callback) => {
callback(permission === 'idle-detection');
}
);
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'button.html'));
const permission = await w.webContents.executeJavaScript(`
new Promise((resolve, reject) => {
const button = document.getElementById('button');
button.addEventListener("click", async () => {
const permission = await IdleDetector.requestPermission();
resolve(permission);
});
button.click();
});
`, true);
expect(permission).to.eq('granted');
});
it('can deny a permission request', async () => {
session.defaultSession.setPermissionRequestHandler(
(_wc, permission, callback) => {
callback(permission !== 'idle-detection');
}
);
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'button.html'));
const permission = await w.webContents.executeJavaScript(`
new Promise((resolve, reject) => {
const button = document.getElementById('button');
button.addEventListener("click", async () => {
const permission = await IdleDetector.requestPermission();
resolve(permission);
});
button.click();
});
`, true);
expect(permission).to.eq('denied');
});
it('can allow the IdleDetector to start', async () => {
session.defaultSession.setPermissionCheckHandler((wc, permission) => {
return permission === 'idle-detection';
});
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
const result = await w.webContents.executeJavaScript(`
const detector = new IdleDetector({ threshold: 60000 });
detector.start().then(() => {
return 'success';
}).catch(e => e.message);
`, true);
expect(result).to.eq('success');
});
it('can prevent the IdleDetector from starting', async () => {
session.defaultSession.setPermissionCheckHandler((wc, permission) => {
return permission !== 'idle-detection';
});
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
const result = await w.webContents.executeJavaScript(`
const detector = new IdleDetector({ threshold: 60000 });
detector.start().then(() => {
console.log('success')
}).catch(e => e.message);
`, true);
expect(result).to.eq('Idle detection permission denied');
});
});
describe('navigator.mediaDevices', () => {
afterEach(closeAllWindows);
afterEach(() => {

5
spec/fixtures/pages/button.html vendored Normal file
View File

@@ -0,0 +1,5 @@
<html>
<body>
<button id="button">CLICK</button>
</body>
</html>