Skip to content

Commit d766cc4

Browse files
committed
chore: adding suppoprt for ignoreSessionCookies configuration option
1 parent 71bd4f2 commit d766cc4

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

app.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class ArcInit {
9898
ipc.on('popup-app-menu-opened', this._popupMenuOpened.bind(this));
9999
ipc.on('popup-app-menu-closed', this._popupMenuClosed.bind(this));
100100
ipc.on('system-theme-changed', this._systemThemeChangeHandler.bind(this));
101+
document.body.addEventListener('settings-changed', this._settingsHandler.bind(this));
101102
}
102103
/**
103104
* Requests initial state information from the main process for current
@@ -134,7 +135,9 @@ class ArcInit {
134135
this.reportFatalError(e);
135136
throw e;
136137
}
137-
138+
if (typeof cnf.ignoreSessionCookies === 'boolean') {
139+
this.cookieBridge.ignoreSessionCookies = cnf.ignoreSessionCookies;
140+
}
138141
await this.initApp(cnf);
139142
await this.upgradeApp(cnf);
140143
await this.processInitialPath();
@@ -532,6 +535,21 @@ class ArcInit {
532535
console.error(e);
533536
}
534537
}
538+
539+
/**
540+
* A handler for settings change event.
541+
* Performs actions that are important when a confic object has changed.
542+
*
543+
* @param {CustomEvent} e An event dispatched by preferences proxy.
544+
*/
545+
_settingsHandler(e) {
546+
const { name, value } = e.detail;
547+
switch (name) {
548+
case 'ignoreSessionCookies':
549+
this.cookieBridge.ignoreSessionCookies = value;
550+
break;
551+
}
552+
}
535553
}
536554

537555
const initScript = new ArcInit();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"@advanced-rest-client/electron-drive": "^0.4.0",
8484
"@advanced-rest-client/electron-oauth2": "^2.1.2",
8585
"@advanced-rest-client/electron-request": "^2.2.4",
86-
"@advanced-rest-client/electron-session-state": "^2.0.0",
86+
"@advanced-rest-client/electron-session-state": "^2.1.0",
8787
"amf-client-js": "^4.0.3",
8888
"camelcase": "^5.3.1",
8989
"codemirror": "^5.50.0",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const { assert } = require('chai');
2+
const fs = require('fs-extra');
3+
const path = require('path');
4+
const bootstrap = require('../test-bootstrap.js');
5+
6+
describe('Session cookies', function() {
7+
let app;
8+
before(async () => {
9+
await fs.outputJson(bootstrap.settingsFilePath, {
10+
ignoreSessionCookies: true
11+
});
12+
app = await bootstrap.runAppDeffered(2000);
13+
});
14+
15+
after(async () => {
16+
if (app && app.isRunning()) {
17+
await app.stop();
18+
}
19+
const basePath = path.join('test', 'playground');
20+
await fs.remove(basePath);
21+
});
22+
23+
it('sets ignoreSessionCookies on CookieBridge when init', async () => {
24+
const result = await app.client.execute(async () => {
25+
/* global initScript */
26+
return initScript.cookieBridge.ignoreSessionCookies;
27+
});
28+
assert.isTrue(result.value);
29+
});
30+
31+
it('updates ignoreSessionCookies on CookieBridge instance', async () => {
32+
const result = await app.client.execute(async () => {
33+
document.body.dispatchEvent(new CustomEvent('settings-changed', {
34+
bubbles: true,
35+
detail: {
36+
name: 'ignoreSessionCookies',
37+
value: false,
38+
}
39+
}));
40+
return initScript.cookieBridge.ignoreSessionCookies;
41+
});
42+
assert.isFalse(result.value);
43+
});
44+
45+
it('ignores other setting change events', async () => {
46+
const result = await app.client.execute(async () => {
47+
document.body.dispatchEvent(new CustomEvent('settings-changed', {
48+
bubbles: true,
49+
detail: {
50+
name: 'a',
51+
value: 'b',
52+
}
53+
}));
54+
return initScript.cookieBridge.ignoreSessionCookies;
55+
});
56+
assert.isFalse(result.value);
57+
});
58+
});

0 commit comments

Comments
 (0)