@whotracksme/reporting 5.1.28 → 5.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/package.json +1 -1
- package/reporting/example/index.js +2 -12
- package/reporting/example/manifests/chromium.json +1 -0
- package/reporting/snapshots/0001/events.log.br +0 -0
- package/reporting/snapshots/0001/snapshot.json +4173 -0
- package/reporting/snapshots/0002/events.log.br +0 -0
- package/reporting/snapshots/0002/snapshot.json +2539 -0
- package/reporting/snapshots/0003/events.log.br +0 -0
- package/reporting/snapshots/0003/snapshot.json +855 -0
- package/reporting/snapshots/0004/events.log.br +0 -0
- package/reporting/snapshots/0004/snapshot.json +802 -0
- package/reporting/src/hash-detector.js +1 -1
- package/reporting/src/index.js +1 -2
- package/reporting/src/request/config.js +9 -4
- package/reporting/src/request/{hash.js → hash/index.js} +3 -3
- package/reporting/src/request/index.js +447 -496
- package/reporting/src/{webrequest-pipeline → request}/page-store.js +65 -75
- package/reporting/src/request/qs-whitelist2.js +0 -2
- package/reporting/src/request/steps/cookie-context.js +6 -5
- package/reporting/src/request/steps/oauth-detector.js +3 -24
- package/reporting/src/request/steps/page-logger.js +3 -4
- package/reporting/src/request/steps/token-checker/token-domain.js +1 -1
- package/reporting/src/request/steps/token-examiner.js +3 -4
- package/reporting/src/request/steps/token-telemetry/cached-entry-pipeline.js +55 -75
- package/reporting/src/request/steps/token-telemetry/index.js +86 -115
- package/reporting/src/request/steps/token-telemetry/key-pipeline.js +3 -2
- package/reporting/src/request/steps/token-telemetry/token-pipeline.js +3 -2
- package/reporting/src/request/utils/temp-set.js +2 -4
- package/reporting/src/request/{time.js → utils/time.js} +0 -5
- package/reporting/src/request/utils/tlds.js +1 -11
- package/reporting/src/request/{utils.js → utils/utils.js} +9 -0
- package/reporting/src/{webrequest-pipeline/webrequest-context.js → request/utils/webrequest.js} +84 -4
- package/reporting/src/utils/url.js +0 -25
- package/reporting/test/helpers/scenarios.js +76 -17
- package/reporting/test/index.js +3 -8
- package/reporting/test/request/database.test.js +96 -0
- package/reporting/test/request/{hash.spec.js → hash/index.spec.js} +2 -2
- package/reporting/test/request/index.spec.js +24 -46
- package/reporting/test/{request-reporter.test.js → request/index.test.js} +102 -46
- package/reporting/test/{webrequest-pipeline → request}/page-store.test.js +1 -1
- package/reporting/test/request/steps/oauth-detector.spec.js +15 -25
- package/reporting/test/request/{utils.spec.js → utils/utils.spec.js} +2 -2
- package/reporting/test/setup.unit.js +1 -0
- package/reporting/test/utils/url.spec.js +1 -26
- package/reporting/src/request/page-telemetry.js +0 -42
- package/reporting/src/request/steps/subdomain-check.js +0 -34
- package/reporting/src/request/utils/subject.js +0 -37
- package/reporting/src/request-reporter.js +0 -111
- package/reporting/src/utils/pacemaker.js +0 -279
- package/reporting/src/webrequest-pipeline/cname-uncloak.js +0 -110
- package/reporting/src/webrequest-pipeline/index.js +0 -286
- package/reporting/src/webrequest-pipeline/logger.js +0 -14
- package/reporting/src/webrequest-pipeline/pipeline.js +0 -249
- package/reporting/src/webrequest-pipeline/utils/webrequest.js +0 -119
- package/reporting/test/utils/pacemaker.spec.js +0 -222
- package/reporting/test/webrequest-pipeline/index.test.js +0 -160
- package/reporting/test/webrequest-pipeline/pipeline.spec.js +0 -251
- /package/reporting/src/request/{resources → hash}/prob.js +0 -0
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WhoTracks.Me
|
|
3
|
-
* https://whotracks.me/
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2017-present Ghostery GmbH. All rights reserved.
|
|
6
|
-
*
|
|
7
|
-
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
8
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
9
|
-
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import logger from '../logger.js';
|
|
13
|
-
|
|
14
|
-
export const VALID_RESPONSE_PROPERTIES = {
|
|
15
|
-
onBeforeRequest: ['cancel', 'redirectUrl'],
|
|
16
|
-
onBeforeSendHeaders: ['cancel', 'requestHeaders'],
|
|
17
|
-
onHeadersReceived: ['cancel', 'redirectUrl', 'responseHeaders'],
|
|
18
|
-
onAuthRequired: ['cancel'],
|
|
19
|
-
onBeforeRedirect: [],
|
|
20
|
-
onCompleted: [],
|
|
21
|
-
onErrorOccurred: [],
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
function getOptionArray(options) {
|
|
25
|
-
if (!options) {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
// get subset of options which are defined
|
|
29
|
-
const optionsSubset = [
|
|
30
|
-
// firefox and chrome disagree on how to name these
|
|
31
|
-
options.REQUEST_HEADERS || options.REQUESTHEADERS,
|
|
32
|
-
options.RESPONSE_HEADERS || options.RESPONSEHEADERS,
|
|
33
|
-
// extra headers: Chrome 72:
|
|
34
|
-
// https://groups.google.com/a/chromium.org/forum/#!topic/chromium-extensions/vYIaeezZwfQ
|
|
35
|
-
options.EXTRA_HEADERS,
|
|
36
|
-
// request body disabled to avoid the overhead when not needed
|
|
37
|
-
// options.REQUEST_BODY,
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
chrome?.runtime?.getManifest()?.permissions.includes('webRequestBlocking')
|
|
42
|
-
) {
|
|
43
|
-
optionsSubset.push(options.BLOCKING);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return optionsSubset.filter((o) => !!o);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const urls = ['http://*/*', 'https://*/*'];
|
|
50
|
-
|
|
51
|
-
export default class WebRequestListenersManager {
|
|
52
|
-
constructor() {
|
|
53
|
-
this.HANDLERS = {};
|
|
54
|
-
// build allowed extraInfo options from <Step>Options objects.
|
|
55
|
-
const EXTRA_INFO_SPEC = {
|
|
56
|
-
onBeforeRequest: getOptionArray(chrome.webRequest.OnBeforeRequestOptions),
|
|
57
|
-
onBeforeSendHeaders: getOptionArray(
|
|
58
|
-
chrome.webRequest.OnBeforeSendHeadersOptions,
|
|
59
|
-
),
|
|
60
|
-
onHeadersReceived: getOptionArray(
|
|
61
|
-
chrome.webRequest.OnHeadersReceivedOptions,
|
|
62
|
-
),
|
|
63
|
-
onAuthRequired: getOptionArray(chrome.webRequest.OnAuthRequiredOptions),
|
|
64
|
-
onBeforeRedirect: getOptionArray(
|
|
65
|
-
chrome.webRequest.OnBeforeRedirectOptions,
|
|
66
|
-
),
|
|
67
|
-
onCompleted: getOptionArray(chrome.webRequest.OnCompletedOptions),
|
|
68
|
-
onErrorOccurred: undefined,
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
for (const event of Object.keys(EXTRA_INFO_SPEC)) {
|
|
72
|
-
// It might be that the platform does not support all listeners:
|
|
73
|
-
if (chrome.webRequest[event] === undefined) {
|
|
74
|
-
logger.warn(`chrome.webRequest.${event} is not supported`);
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Get allowed options for this event (e.g.: 'blocking', 'requestHeaders',
|
|
79
|
-
// etc.)
|
|
80
|
-
const extraInfoSpec = EXTRA_INFO_SPEC[event];
|
|
81
|
-
|
|
82
|
-
let firstCall = true;
|
|
83
|
-
const callback = (...args) => {
|
|
84
|
-
if (!this.HANDLERS[event]) {
|
|
85
|
-
if (firstCall) {
|
|
86
|
-
firstCall = false;
|
|
87
|
-
logger.info(
|
|
88
|
-
`webRequest.${event} called without listener being assigned`,
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
return this.HANDLERS[event](...args);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
if (extraInfoSpec === undefined) {
|
|
97
|
-
chrome.webRequest[event].addListener(callback, { urls });
|
|
98
|
-
} else {
|
|
99
|
-
chrome.webRequest[event].addListener(callback, { urls }, extraInfoSpec);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
addListener(event, listener) {
|
|
105
|
-
if (this.HANDLERS[event]) {
|
|
106
|
-
throw new Error(
|
|
107
|
-
`webRequest.${event} expects only one listener as this all WebRequestPipeline should need`,
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
this.HANDLERS[event] = listener;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
removeListener(event, listener) {
|
|
114
|
-
if (this.HANDLERS[event] !== listener) {
|
|
115
|
-
throw new Error(`webRequest.${event} trying to remove wrong listener`);
|
|
116
|
-
}
|
|
117
|
-
this.HANDLERS[event] = null;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WhoTracks.Me
|
|
3
|
-
* https://whotracks.me/
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2017-present Ghostery GmbH. All rights reserved.
|
|
6
|
-
*
|
|
7
|
-
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
8
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
9
|
-
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import * as chai from 'chai';
|
|
13
|
-
import sinon from 'sinon';
|
|
14
|
-
|
|
15
|
-
import { Pacemaker } from '../../src/utils/pacemaker';
|
|
16
|
-
|
|
17
|
-
const expect = chai.expect;
|
|
18
|
-
|
|
19
|
-
describe('core/services/pacemaker', function () {
|
|
20
|
-
describe('#pacemaker', () => {
|
|
21
|
-
let clock;
|
|
22
|
-
let pacemaker;
|
|
23
|
-
|
|
24
|
-
beforeEach(function () {
|
|
25
|
-
clock = sinon.useFakeTimers();
|
|
26
|
-
pacemaker = new Pacemaker();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
afterEach(function () {
|
|
30
|
-
pacemaker.stop();
|
|
31
|
-
clock.restore();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('no timer when no task registered', () => {
|
|
35
|
-
expect(pacemaker.freq).to.be.null;
|
|
36
|
-
expect(pacemaker.timer).to.be.null;
|
|
37
|
-
expect(pacemaker.tasks.size).to.equal(0);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('adds one task', async () => {
|
|
41
|
-
const spy = sinon.spy(function callback() {});
|
|
42
|
-
pacemaker.register(spy, { timeout: 10 });
|
|
43
|
-
|
|
44
|
-
// Check state of pacemaker
|
|
45
|
-
expect(pacemaker.freq).to.equal(10);
|
|
46
|
-
expect(pacemaker.timer).not.to.be.null;
|
|
47
|
-
expect(pacemaker.tasks.size).to.equal(1);
|
|
48
|
-
expect(spy).not.to.have.been.called;
|
|
49
|
-
|
|
50
|
-
// Check state of task
|
|
51
|
-
const task = pacemaker.tasks.values().next().value;
|
|
52
|
-
expect(task.args).to.have.length(0);
|
|
53
|
-
expect(task.name).to.equal('callback');
|
|
54
|
-
expect(task.timeout).to.equal(10);
|
|
55
|
-
expect(task.once).to.be.false;
|
|
56
|
-
|
|
57
|
-
// Make sure spy was not called after tick
|
|
58
|
-
expect(spy).not.to.have.been.called;
|
|
59
|
-
|
|
60
|
-
// Run all timers and expect task to have been called
|
|
61
|
-
clock.next();
|
|
62
|
-
expect(spy).to.have.been.called;
|
|
63
|
-
|
|
64
|
-
// Run again and task should be called twice
|
|
65
|
-
clock.next();
|
|
66
|
-
expect(spy).to.have.been.calledTwice;
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('adds two tasks + a timeout', async () => {
|
|
70
|
-
const tickSpy = sinon.spy(pacemaker, '_tick');
|
|
71
|
-
const adjustSpy = sinon.spy(pacemaker, '_adjustFrequency');
|
|
72
|
-
|
|
73
|
-
const spy1 = sinon.spy(function callback1() {});
|
|
74
|
-
pacemaker.register(spy1, { timeout: 20 });
|
|
75
|
-
expect(tickSpy).not.to.have.been.called;
|
|
76
|
-
expect(adjustSpy).to.have.been.calledOnce;
|
|
77
|
-
|
|
78
|
-
const spy2 = sinon.spy(function callback2() {});
|
|
79
|
-
pacemaker.register(spy2, { timeout: 10 });
|
|
80
|
-
expect(tickSpy).not.to.have.been.called;
|
|
81
|
-
expect(adjustSpy).to.have.been.calledTwice;
|
|
82
|
-
|
|
83
|
-
const spy3 = sinon.spy(function callback3() {});
|
|
84
|
-
const timeout = pacemaker.setTimeout(spy3, 30);
|
|
85
|
-
expect(tickSpy).not.to.have.been.called;
|
|
86
|
-
expect(adjustSpy).to.have.been.calledThrice;
|
|
87
|
-
|
|
88
|
-
// None of the tasks was triggered at this point
|
|
89
|
-
expect(spy1).not.to.have.been.called;
|
|
90
|
-
expect(spy2).not.to.have.been.called;
|
|
91
|
-
expect(spy3).not.to.have.been.called;
|
|
92
|
-
|
|
93
|
-
// Tick should call task2 but none of the others
|
|
94
|
-
clock.next();
|
|
95
|
-
expect(spy1).not.to.have.been.called; // tick=10 -> not triggered
|
|
96
|
-
expect(spy2).to.have.been.calledOnce; // tick=10 -> triggered
|
|
97
|
-
expect(spy3).not.to.have.been.called; // tick=10 -> not triggered
|
|
98
|
-
|
|
99
|
-
// Tick should call task1 + task2 but not task3 (yet)
|
|
100
|
-
clock.next();
|
|
101
|
-
expect(spy1).to.have.been.calledOnce; // tick=20 -> triggered
|
|
102
|
-
expect(spy2).to.have.been.calledTwice; // tick=20 -> triggered
|
|
103
|
-
expect(spy3).not.to.have.been.called; // tick=20 -> not triggered
|
|
104
|
-
|
|
105
|
-
// Tick should call task1 + task2 + task3
|
|
106
|
-
clock.next();
|
|
107
|
-
expect(spy1).to.have.been.calledOnce; // tick=30 -> not triggered
|
|
108
|
-
expect(spy2).to.have.been.calledThrice; // tick=30 -> triggered
|
|
109
|
-
expect(spy3).to.have.been.calledOnce; // tick=30 -> triggered
|
|
110
|
-
|
|
111
|
-
// At this point the setTimeout should have been removed
|
|
112
|
-
expect(pacemaker.tasks).not.to.include(timeout);
|
|
113
|
-
expect(pacemaker.tasks.size).to.equal(2);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('stops when no task', async () => {
|
|
117
|
-
// Initialize pacemaker with one setTimeout
|
|
118
|
-
const spy = sinon.spy(function callback() {});
|
|
119
|
-
pacemaker.setTimeout(spy, 30);
|
|
120
|
-
expect(pacemaker.tasks.size).to.equal(1);
|
|
121
|
-
|
|
122
|
-
// Call timeout
|
|
123
|
-
clock.next();
|
|
124
|
-
expect(spy).to.have.been.calledOnce;
|
|
125
|
-
|
|
126
|
-
// Make sure pacemaker stopped
|
|
127
|
-
expect(pacemaker.timer).to.be.null;
|
|
128
|
-
expect(pacemaker.freq).to.be.null;
|
|
129
|
-
expect(pacemaker.tasks.size).to.equal(0);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('adjusts frequency', async () => {
|
|
133
|
-
const tickSpy = sinon.spy(pacemaker, '_tick');
|
|
134
|
-
const adjustSpy = sinon.spy(pacemaker, '_adjustFrequency');
|
|
135
|
-
|
|
136
|
-
// Initial state, no freq and no timer
|
|
137
|
-
expect(pacemaker.freq).to.be.null;
|
|
138
|
-
expect(pacemaker.timer).to.be.null;
|
|
139
|
-
|
|
140
|
-
// Add one task with timeout 0
|
|
141
|
-
pacemaker.setTimeout(function callback() {}, 0);
|
|
142
|
-
expect(pacemaker.freq).to.equal(0);
|
|
143
|
-
expect(pacemaker.timer).not.to.be.null;
|
|
144
|
-
expect(adjustSpy).to.have.been.calledOnce;
|
|
145
|
-
expect(tickSpy).not.to.have.been.called;
|
|
146
|
-
|
|
147
|
-
// Trigger task
|
|
148
|
-
clock.next();
|
|
149
|
-
expect(tickSpy).to.have.been.calledOnce;
|
|
150
|
-
|
|
151
|
-
// Expect pacemaker to have stopped
|
|
152
|
-
expect(pacemaker.timer).to.be.null;
|
|
153
|
-
expect(pacemaker.freq).to.be.null;
|
|
154
|
-
expect(pacemaker.tasks.size).to.equal(0);
|
|
155
|
-
|
|
156
|
-
// Make sure freq is adjusted properly
|
|
157
|
-
const t1 = pacemaker.setTimeout(function callback() {}, 30);
|
|
158
|
-
expect(pacemaker.freq).to.equal(30);
|
|
159
|
-
|
|
160
|
-
const t2 = pacemaker.register(function callback() {}, { timeout: 29 });
|
|
161
|
-
expect(pacemaker.freq).to.equal(29);
|
|
162
|
-
|
|
163
|
-
const t3 = pacemaker.register(function callback() {}, { timeout: 31 });
|
|
164
|
-
expect(pacemaker.freq).to.equal(29);
|
|
165
|
-
|
|
166
|
-
const t4 = pacemaker.register(function callback() {}, { timeout: 32 });
|
|
167
|
-
expect(pacemaker.freq).to.equal(29);
|
|
168
|
-
|
|
169
|
-
t4.stop();
|
|
170
|
-
expect(pacemaker.freq).to.equal(29);
|
|
171
|
-
|
|
172
|
-
t2.stop();
|
|
173
|
-
expect(pacemaker.freq).to.equal(30);
|
|
174
|
-
|
|
175
|
-
t1.stop();
|
|
176
|
-
expect(pacemaker.freq).to.equal(31);
|
|
177
|
-
|
|
178
|
-
t3.stop();
|
|
179
|
-
expect(pacemaker.freq).to.be.null;
|
|
180
|
-
expect(pacemaker.timer).to.be.null;
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('adds instant task', async () => {
|
|
184
|
-
clock.tick(1);
|
|
185
|
-
const spy = sinon.spy(function callback() {});
|
|
186
|
-
pacemaker.register(spy, { timeout: 5, startImmediately: true });
|
|
187
|
-
|
|
188
|
-
// Trigger first on next tick (start immediately)
|
|
189
|
-
clock.next();
|
|
190
|
-
expect(spy).to.have.been.calledOnce;
|
|
191
|
-
expect(pacemaker.tasks.values().next().value.last).to.equal(1);
|
|
192
|
-
|
|
193
|
-
// Trigger next after `timeout` milliseconds
|
|
194
|
-
clock.next();
|
|
195
|
-
expect(spy).to.have.been.calledTwice;
|
|
196
|
-
expect(pacemaker.tasks.values().next().value.last).to.equal(6);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('throwing task does not stop pacemaker', () => {
|
|
200
|
-
const spy = sinon.spy(function callback() {
|
|
201
|
-
throw new Error('boom');
|
|
202
|
-
});
|
|
203
|
-
const task = pacemaker.register(spy, { timeout: 1 });
|
|
204
|
-
|
|
205
|
-
expect(spy).not.to.have.been.called;
|
|
206
|
-
|
|
207
|
-
clock.next();
|
|
208
|
-
expect(spy).to.have.been.calledOnce;
|
|
209
|
-
expect(spy).to.have.thrown;
|
|
210
|
-
|
|
211
|
-
clock.next();
|
|
212
|
-
expect(spy).to.have.been.calledTwice;
|
|
213
|
-
expect(spy).to.have.thrown;
|
|
214
|
-
|
|
215
|
-
clock.next();
|
|
216
|
-
expect(spy).to.have.been.calledThrice;
|
|
217
|
-
expect(spy).to.have.thrown;
|
|
218
|
-
|
|
219
|
-
task.stop();
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
});
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WhoTracks.Me
|
|
3
|
-
* https://ghostery.com/whotracksme
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2017-present Ghostery GmbH. All rights reserved.
|
|
6
|
-
*
|
|
7
|
-
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
8
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
9
|
-
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import chrome from 'sinon-chrome';
|
|
13
|
-
import { expect } from 'chai';
|
|
14
|
-
|
|
15
|
-
import { playScenario } from '../helpers/scenarios.js';
|
|
16
|
-
|
|
17
|
-
import WebRequestPipeline from '../../src/webrequest-pipeline/index.js';
|
|
18
|
-
|
|
19
|
-
describe('WebRequestPipeline', function () {
|
|
20
|
-
before(function () {
|
|
21
|
-
chrome.storage.session = chrome.storage.local;
|
|
22
|
-
globalThis.chrome = chrome;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
beforeEach(function () {
|
|
26
|
-
chrome.flush();
|
|
27
|
-
chrome.storage.session.get.yields({});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
after(function () {
|
|
31
|
-
chrome.flush();
|
|
32
|
-
delete globalThis.chrome;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
context('PageStore', function () {
|
|
36
|
-
it('starts empty', function () {
|
|
37
|
-
const pipeline = new WebRequestPipeline();
|
|
38
|
-
pipeline.init();
|
|
39
|
-
expect(pipeline.pageStore.checkIfEmpty()).to.be.true;
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
context('on webRequest.onBeforeRequest', function () {
|
|
43
|
-
it('creates a page', function () {
|
|
44
|
-
const pipeline = new WebRequestPipeline();
|
|
45
|
-
pipeline.init();
|
|
46
|
-
pipeline.addPipelineStep('onBeforeRequest', {
|
|
47
|
-
name: 'test',
|
|
48
|
-
spec: 'annotate',
|
|
49
|
-
fn: () => {},
|
|
50
|
-
});
|
|
51
|
-
const details = {
|
|
52
|
-
tabId: 1,
|
|
53
|
-
frameId: 0,
|
|
54
|
-
url: 'https://example.com',
|
|
55
|
-
type: 'main_frame',
|
|
56
|
-
};
|
|
57
|
-
chrome.webRequest.onBeforeRequest.dispatch(details);
|
|
58
|
-
const tab = pipeline.pageStore.getPageForRequest(details);
|
|
59
|
-
expect(tab).to.deep.include({
|
|
60
|
-
url: details.url,
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
context('with pre-recorded events', function () {
|
|
66
|
-
let pipeline;
|
|
67
|
-
|
|
68
|
-
beforeEach(function () {
|
|
69
|
-
pipeline = new WebRequestPipeline();
|
|
70
|
-
pipeline.init();
|
|
71
|
-
[
|
|
72
|
-
'onBeforeRequest',
|
|
73
|
-
'onBeforeSendHeaders',
|
|
74
|
-
'onHeadersReceived',
|
|
75
|
-
'onAuthRequired',
|
|
76
|
-
'onBeforeRedirect',
|
|
77
|
-
'onCompleted',
|
|
78
|
-
'onErrorOccurred',
|
|
79
|
-
].forEach((step) => {
|
|
80
|
-
pipeline.addPipelineStep(step, {
|
|
81
|
-
name: 'test',
|
|
82
|
-
spec: 'annotate',
|
|
83
|
-
fn: () => {},
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
afterEach(function () {
|
|
89
|
-
pipeline.unload();
|
|
90
|
-
pipeline = undefined;
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
context('0001-quick-close', function () {
|
|
94
|
-
it('runs without a crash', async function () {
|
|
95
|
-
const { seenTabIds } = await playScenario(chrome, {
|
|
96
|
-
scenarioName: '0001-quick-close',
|
|
97
|
-
scenarioRelease: '2024-09-27',
|
|
98
|
-
});
|
|
99
|
-
expect(pipeline.pageStore.checkIfEmpty()).to.be.false;
|
|
100
|
-
expect(seenTabIds).to.have.property('size', 1);
|
|
101
|
-
const tabId = seenTabIds.values().next().value;
|
|
102
|
-
const tab = pipeline.pageStore.getPageForRequest({
|
|
103
|
-
tabId,
|
|
104
|
-
frameId: 0,
|
|
105
|
-
});
|
|
106
|
-
expect(tab).to.deep.include({
|
|
107
|
-
url: 'https://ghosterysearch.com/',
|
|
108
|
-
});
|
|
109
|
-
expect(tab.previous).to.deep.include({
|
|
110
|
-
url: 'about:blank',
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
context('0002-quick-navigation', function () {
|
|
116
|
-
it('runs without a crash', async function () {
|
|
117
|
-
const { seenTabIds } = await playScenario(chrome, {
|
|
118
|
-
scenarioName: '0002-quick-navigation',
|
|
119
|
-
scenarioRelease: '2024-09-27',
|
|
120
|
-
});
|
|
121
|
-
expect(pipeline.pageStore.checkIfEmpty()).to.be.false;
|
|
122
|
-
expect(seenTabIds).to.have.property('size', 1);
|
|
123
|
-
const tabId = seenTabIds.values().next().value;
|
|
124
|
-
const tab = pipeline.pageStore.getPageForRequest({
|
|
125
|
-
tabId,
|
|
126
|
-
frameId: 0,
|
|
127
|
-
});
|
|
128
|
-
expect(tab).to.deep.include({
|
|
129
|
-
url: 'https://www.facebook.com/login/?next=https%3A%2F%2Fwww.facebook.com%2F',
|
|
130
|
-
});
|
|
131
|
-
expect(tab.previous).to.deep.include({
|
|
132
|
-
url: 'https://ghosterysearch.com/',
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
context('0003-prefetch', function () {
|
|
138
|
-
it('runs without a crash', async function () {
|
|
139
|
-
const { seenTabIds } = await playScenario(chrome, {
|
|
140
|
-
scenarioName: '0003-prefetch',
|
|
141
|
-
scenarioRelease: '2024-09-27',
|
|
142
|
-
});
|
|
143
|
-
expect(pipeline.pageStore.checkIfEmpty()).to.be.false;
|
|
144
|
-
expect(seenTabIds).to.have.property('size', 1);
|
|
145
|
-
const tabId = seenTabIds.values().next().value;
|
|
146
|
-
const tab = pipeline.pageStore.getPageForRequest({
|
|
147
|
-
tabId,
|
|
148
|
-
frameId: 0,
|
|
149
|
-
});
|
|
150
|
-
expect(tab).to.deep.include({
|
|
151
|
-
url: 'http://localhost:8080/',
|
|
152
|
-
});
|
|
153
|
-
expect(tab.previous).to.deep.include({
|
|
154
|
-
url: 'about:blank',
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
});
|