forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfingerprinting_spec.js
More file actions
60 lines (55 loc) · 2 KB
/
fingerprinting_spec.js
File metadata and controls
60 lines (55 loc) · 2 KB
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
60
import { expect } from 'chai';
import { config } from 'src/config.js';
import { getDevicePixelRatio } from 'libraries/devicePixelRatio/devicePixelRatio.js';
import { isWebdriverEnabled } from 'libraries/webdriver/webdriver.js';
import { getTimeZone } from 'libraries/timezone/timezone.js';
describe('disableFingerprintingApis', function () {
after(function () {
config.resetConfig();
});
it('when devicepixelratio is disabled, getDevicePixelRatio returns 1 without reading window.devicePixelRatio', function () {
const devicePixelRatioSpy = sinon.spy();
const mockWin = {
get devicePixelRatio() {
devicePixelRatioSpy();
return 2;
}
};
config.setConfig({ disableFingerprintingApis: ['devicepixelratio'] });
const result = getDevicePixelRatio(mockWin);
expect(result).to.equal(1);
sinon.assert.notCalled(devicePixelRatioSpy);
});
it('when webdriver is disabled, isWebdriverEnabled returns false without reading navigator.webdriver', function () {
const webdriverSpy = sinon.spy();
const mockWin = {
navigator: {
get webdriver() {
webdriverSpy();
return true;
}
}
};
config.setConfig({ disableFingerprintingApis: ['webdriver'] });
const result = isWebdriverEnabled(mockWin);
expect(result).to.equal(false);
sinon.assert.notCalled(webdriverSpy);
});
it('when resolvedoptions is disabled, getTimeZone returns safe default without calling Intl.DateTimeFormat', function () {
const resolvedOptionsSpy = sinon.spy();
const dateTimeFormatStub = sinon.stub(Intl, 'DateTimeFormat').returns({
resolvedOptions: function () {
resolvedOptionsSpy();
return { timeZone: 'America/New_York' };
}
});
try {
config.setConfig({ disableFingerprintingApis: ['resolvedoptions'] });
const result = getTimeZone();
expect(result).to.equal('');
sinon.assert.notCalled(resolvedOptionsSpy);
} finally {
dateTimeFormatStub.restore();
}
});
});