1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
'use strict'
const expect = require('chai').expect,
tu = require('./testing_utils'),
incognito = require('../incognito');
describe('incognito.js', function() {
beforeEach(function() {
tu.stubber([
['chrome.windows.onCreated.addListener', tu.Mock()],
['chrome.windows.onRemoved.addListener', tu.Mock()],
['chrome.windows.getAll', tu.Mock()],
]);
});
describe('onIncognitoDestruction', function() {
beforeEach(function() {
incognito.state.incognito_session_exists = false;
this.callbackCalled = false;
this.callback = () => this.callbackCalled = true;
this.instance = incognito.onIncognitoDestruction(this.callback);
})
it('no incognito session by default', function() {
expect(incognito.state.incognito_session_exists).to.be.false;
})
it('with no incognito, callback not called', async function() {
incognito.state.incognito_session_exists = false;
await this.instance.detect_incognito_destruction();
expect(this.callbackCalled).to.be.false;
});
it('with incognitos still open, callback not called', async function() {
incognito.state.incognito_session_exists = true;
chrome.windows.getAll = func => func([{incognito: true}]);
await this.instance.detect_incognito_destruction();
expect(this.callbackCalled, 'not called').to.be.false;
});
it('callback called when last incognito closed', async function() {
incognito.state.incognito_session_exists = true;
chrome.windows.getAll = func => func([]);
await this.instance.detect_incognito_destruction();
expect(incognito.state.incognito_session_exists, 'constant changed').to.be.false;
expect(this.callbackCalled).to.be.true;
});
it('detects when an incognito window is created', function() {
this.instance.detect_incognito_creation({incognito: true});
expect(incognito.state.incognito_session_exists, 'constant changed').to.be.true;
})
});
});
|