electron/spec/fixtures/api/cookie-app/main.js

43 lines
980 B
JavaScript
Raw Normal View History

2020-03-20 20:28:31 +00:00
const { app, session } = require('electron');
app.whenReady().then(async function () {
2020-03-20 20:28:31 +00:00
const url = 'http://foo.bar';
const persistentSession = session.fromPartition('persist:ence-test');
const name = 'test';
const value = 'true';
const set = () => persistentSession.cookies.set({
url,
name,
value,
expirationDate: Date.now() + 60000
2020-03-20 20:28:31 +00:00
});
const get = () => persistentSession.cookies.get({
url
2020-03-20 20:28:31 +00:00
});
const maybeRemove = async (pred) => {
if (pred()) {
2020-03-20 20:28:31 +00:00
await persistentSession.cookies.remove(url, name);
}
2020-03-20 20:28:31 +00:00
};
try {
2020-03-20 20:28:31 +00:00
await maybeRemove(() => process.env.PHASE === 'one');
const one = await get();
await set();
const two = await get();
await maybeRemove(() => process.env.PHASE === 'two');
const three = await get();
2020-03-20 20:28:31 +00:00
process.stdout.write(`${one.length}${two.length}${three.length}`);
} catch (e) {
2020-03-20 20:28:31 +00:00
process.stdout.write('ERROR');
} finally {
2020-03-20 20:28:31 +00:00
process.stdout.end();
2020-03-20 20:28:31 +00:00
app.quit();
}
2020-03-20 20:28:31 +00:00
});