test: add tests for Storage Access API (#41719)
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:
parent
ba1e7fcaa7
commit
5655b68c37
2 changed files with 136 additions and 0 deletions
|
@ -1383,6 +1383,138 @@ describe('chromium features', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Storage Access API', () => {
|
||||
afterEach(closeAllWindows);
|
||||
afterEach(() => {
|
||||
session.defaultSession.setPermissionCheckHandler(null);
|
||||
session.defaultSession.setPermissionRequestHandler(null);
|
||||
});
|
||||
|
||||
it('can determine if a permission is granted for "storage-access"', async () => {
|
||||
session.defaultSession.setPermissionCheckHandler(
|
||||
(_wc, permission) => permission === 'storage-access'
|
||||
);
|
||||
|
||||
const w = new BrowserWindow({ show: false });
|
||||
await w.loadFile(path.join(fixturesPath, 'pages', 'a.html'));
|
||||
|
||||
const permission = await w.webContents.executeJavaScript(`
|
||||
navigator.permissions.query({ name: 'storage-access' })
|
||||
.then(permission => permission.state).catch(err => err.message);
|
||||
`, true);
|
||||
|
||||
expect(permission).to.eq('granted');
|
||||
});
|
||||
|
||||
it('can determine if a permission is denied for "storage-access"', async () => {
|
||||
session.defaultSession.setPermissionCheckHandler(
|
||||
(_wc, permission) => permission !== 'storage-access'
|
||||
);
|
||||
|
||||
const w = new BrowserWindow({ show: false });
|
||||
await w.loadFile(path.join(fixturesPath, 'pages', 'a.html'));
|
||||
|
||||
const permission = await w.webContents.executeJavaScript(`
|
||||
navigator.permissions.query({ name: 'storage-access' })
|
||||
.then(permission => permission.state).catch(err => err.message);
|
||||
`, true);
|
||||
|
||||
expect(permission).to.eq('denied');
|
||||
});
|
||||
|
||||
it('can determine if a permission is granted for "top-level-storage-access"', async () => {
|
||||
session.defaultSession.setPermissionCheckHandler(
|
||||
(_wc, permission) => permission === 'top-level-storage-access'
|
||||
);
|
||||
|
||||
const w = new BrowserWindow({ show: false });
|
||||
await w.loadFile(path.join(fixturesPath, 'pages', 'a.html'));
|
||||
|
||||
const permission = await w.webContents.executeJavaScript(`
|
||||
navigator.permissions.query({
|
||||
name: 'top-level-storage-access',
|
||||
requestedOrigin: "https://www.example.com",
|
||||
}).then(permission => permission.state).catch(err => err.message);
|
||||
`, true);
|
||||
|
||||
expect(permission).to.eq('granted');
|
||||
});
|
||||
|
||||
it('can determine if a permission is denied for "top-level-storage-access"', async () => {
|
||||
session.defaultSession.setPermissionCheckHandler(
|
||||
(_wc, permission) => permission !== 'top-level-storage-access'
|
||||
);
|
||||
|
||||
const w = new BrowserWindow({ show: false });
|
||||
await w.loadFile(path.join(fixturesPath, 'pages', 'a.html'));
|
||||
|
||||
const permission = await w.webContents.executeJavaScript(`
|
||||
navigator.permissions.query({
|
||||
name: 'top-level-storage-access',
|
||||
requestedOrigin: "https://www.example.com",
|
||||
}).then(permission => permission.state).catch(err => err.message);
|
||||
`, true);
|
||||
|
||||
expect(permission).to.eq('denied');
|
||||
});
|
||||
|
||||
it('can grant a permission request for "top-level-storage-access"', async () => {
|
||||
session.defaultSession.setPermissionRequestHandler(
|
||||
(_wc, permission, callback) => {
|
||||
callback(permission === 'top-level-storage-access');
|
||||
}
|
||||
);
|
||||
|
||||
const w = new BrowserWindow({ show: false });
|
||||
await w.loadFile(path.join(fixturesPath, 'pages', 'button.html'));
|
||||
|
||||
// requestStorageAccessFor returns a Promise that fulfills with undefined
|
||||
// if the access to third-party cookies was granted and rejects if access was denied.
|
||||
const permission = await w.webContents.executeJavaScript(`
|
||||
new Promise((resolve, reject) => {
|
||||
const button = document.getElementById('button');
|
||||
button.addEventListener("click", () => {
|
||||
document.requestStorageAccessFor('https://myfakesite').then(
|
||||
(res) => { resolve('granted') },
|
||||
(err) => { resolve('denied') },
|
||||
);
|
||||
});
|
||||
button.click();
|
||||
});
|
||||
`, true);
|
||||
|
||||
expect(permission).to.eq('granted');
|
||||
});
|
||||
|
||||
it('can deny a permission request for "top-level-storage-access"', async () => {
|
||||
session.defaultSession.setPermissionRequestHandler(
|
||||
(_wc, permission, callback) => {
|
||||
callback(permission !== 'top-level-storage-access');
|
||||
}
|
||||
);
|
||||
|
||||
const w = new BrowserWindow({ show: false });
|
||||
await w.loadFile(path.join(fixturesPath, 'pages', 'button.html'));
|
||||
|
||||
// requestStorageAccessFor returns a Promise that fulfills with undefined
|
||||
// if the access to third-party cookies was granted and rejects if access was denied.
|
||||
const permission = await w.webContents.executeJavaScript(`
|
||||
new Promise((resolve, reject) => {
|
||||
const button = document.getElementById('button');
|
||||
button.addEventListener("click", () => {
|
||||
document.requestStorageAccessFor('https://myfakesite').then(
|
||||
(res) => { resolve('granted') },
|
||||
(err) => { resolve('denied') },
|
||||
);
|
||||
});
|
||||
button.click();
|
||||
});
|
||||
`, true);
|
||||
|
||||
expect(permission).to.eq('denied');
|
||||
});
|
||||
});
|
||||
|
||||
describe('IdleDetection', () => {
|
||||
afterEach(closeAllWindows);
|
||||
afterEach(() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue