Skip to content

Commit 29eb2ac

Browse files
Change lifecycle of C-S-S in reference tests (#3015)
* Change lifecycle of C-S-S in reference tests * Use 8.13.0 with fix
1 parent 8895f5b commit 29eb2ac

File tree

7 files changed

+40
-24
lines changed

7 files changed

+40
-24
lines changed

package-lock.json

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
},
6666
"dependencies": {
6767
"@duckduckgo/autofill": "github:duckduckgo/duckduckgo-autofill#17.0.1",
68-
"@duckduckgo/content-scope-scripts": "github:duckduckgo/content-scope-scripts#7.18.0",
68+
"@duckduckgo/content-scope-scripts": "github:duckduckgo/content-scope-scripts#8.13.0",
6969
"@duckduckgo/ddg2dnr": "file:packages/ddg2dnr",
7070
"@duckduckgo/jsbloom": "^1.0.2",
7171
"@duckduckgo/privacy-dashboard": "github:duckduckgo/privacy-dashboard#8.4.0",

unit-test/background/reference-tests/gpc-tests.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const tdsStorage = require('../../../shared/js/background/storage/tds').default;
44
const Site = require('../../../shared/js/background/classes/site').default;
55
const GPC = require('../../../shared/js/background/GPC');
66
const GpcContentScript = require('@duckduckgo/content-scope-scripts/injected/src/features/gpc').default;
7-
const gpcContentScript = new GpcContentScript('gpc');
87
const constants = require('../../../shared/data/constants');
98
const settings = require('../../../shared/js/background/settings');
109

@@ -45,11 +44,16 @@ for (const setName of Object.keys(testSets)) {
4544
});
4645
} else if ('expectGPCAPI' in test) {
4746
it(`${test.name}`, () => {
47+
const importConfig = {
48+
trackerLookup: [],
49+
injectName: 'extensionTest',
50+
};
4851
const args = {
4952
site: new Site(test.siteURL),
5053
globalPrivacyControlValue: test.gpcUserSettingOn,
5154
platform: constants.platform,
5255
};
56+
const gpcContentScript = new GpcContentScript('gpc', importConfig, args);
5357
const isEnabled = !contentScriptUtils.isFeatureBroken(args, 'gpc');
5458

5559
expect(isEnabled).toEqual(test.expectGPCAPI);

unit-test/background/reference-tests/referrer-trimming-tests.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const tdsStorage = require('../../../shared/js/background/storage/tds').default;
55
const tabManager = require('../../../shared/js/background/tab-manager');
66
const { getArgumentsObject } = require('../../../shared/js/background/helpers/arguments-object');
77
const JsReferrerProtection = require('@duckduckgo/content-scope-scripts/injected/src/features/referrer').default;
8-
const jsReferrerProtection = new JsReferrerProtection('jsReferrer');
98
const { isFeatureBroken } = require('@duckduckgo/content-scope-scripts/injected/src/utils');
109

1110
const limitReferrerData = require('../../../shared/js/background/events/referrer-trimming');
@@ -95,8 +94,12 @@ for (const setName of Object.keys(testSets)) {
9594
globalThis.Document = FakeDocument;
9695
spyOnProperty(document, 'referrer', 'get').and.returnValue(test.referrerValue);
9796
spyOnProperty(document, 'URL', 'get').and.returnValue(test.frameURL || test.siteURL);
98-
9997
const args = getArgumentsObject(1, { url: test.siteURL, frameId: 0 }, test.siteURL, 'abc123');
98+
const importConfig = {
99+
trackerLookup: [],
100+
injectName: 'extensionTest',
101+
};
102+
const jsReferrerProtection = new JsReferrerProtection('jsReferrer', importConfig, args);
100103
if (!isFeatureBroken(args, 'referrer')) {
101104
jsReferrerProtection.callInit(args);
102105
}

unit-test/node/reference-tests/3p-cookies-tests.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ const { getArgumentsObject } = require('../../../shared/js/background/helpers/ar
1313

1414
const jsdom = require('jsdom');
1515

16-
const TrackingJsCookieProtection = require('@duckduckgo/content-scope-scripts/injected/src/features/cookie').default;
17-
const trackingJsCookieProtection = new TrackingJsCookieProtection('cookie');
18-
1916
const trackingConfigReference = require('@duckduckgo/privacy-reference-tests/block-third-party-tracking-cookies/config_reference.json');
2017
const trackingBlocklistReference = require('@duckduckgo/privacy-reference-tests/block-third-party-tracking-cookies/tracker_radar_reference.json');
2118
const trackingTestSets = require('@duckduckgo/privacy-reference-tests/block-third-party-tracking-cookies/tests.json');
@@ -25,7 +22,7 @@ const { JSDOM } = jsdom;
2522

2623
const orgGlobalThis = globalThis;
2724

28-
function runTestSuite(suiteType, testSet, jsCookieProtection, configReference, blocklistReference) {
25+
function runTestSuite(suiteType, testSet, configReference, blocklistReference) {
2926
describe(`Third party ${suiteType} cookies blocking tests / ${testSet.name} /`, () => {
3027
beforeAll(() => {
3128
tdsStorageStub.stub({ config: configReference, tds: blocklistReference });
@@ -108,10 +105,16 @@ function runTestSuite(suiteType, testSet, jsCookieProtection, configReference, b
108105

109106
// protection only works in an iframe
110107
const jsdomWindow = dom.window.frames[0].window;
111-
108+
const utils = require('@duckduckgo/content-scope-scripts/injected/src/utils');
109+
utils.setGlobal(jsdomWindow);
110+
const TrackingJsCookieProtection = require('@duckduckgo/content-scope-scripts/injected/src/features/cookie').default;
112111
// eslint-disable-next-line no-global-assign
113112
globalThis = jsdomWindow;
114-
113+
const importConfig = {
114+
trackerLookup: [],
115+
injectName: 'extensionTest',
116+
};
117+
const jsCookieProtection = new TrackingJsCookieProtection('cookie', importConfig, args);
115118
jsCookieProtection.callLoad({
116119
platform: constants.platform,
117120
});
@@ -135,5 +138,5 @@ function runTestSuite(suiteType, testSet, jsCookieProtection, configReference, b
135138
for (const setName of Object.keys(trackingTestSets)) {
136139
const testSet = trackingTestSets[setName];
137140

138-
runTestSuite('tracking', testSet, trackingJsCookieProtection, trackingConfigReference, trackingBlocklistReference);
141+
runTestSuite('tracking', testSet, trackingConfigReference, trackingBlocklistReference);
139142
}

unit-test/node/reference-tests/expire-1p-tracking-cookies.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ for (const setName of Object.keys(testSets)) {
6767
utils.setGlobal(jsdomWindow);
6868

6969
const JsCookieProtection = require('@duckduckgo/content-scope-scripts/injected/src/features/cookie').default;
70-
const jsCookieProtection = new JsCookieProtection('cookie');
70+
const importConfig = {
71+
trackerLookup: [],
72+
injectName: 'extensionTest',
73+
};
74+
const jsCookieProtection = new JsCookieProtection('cookie', importConfig, args);
7175

7276
jsCookieProtection.callLoad({
7377
platform: constants.platform,

unit-test/node/reference-tests/fingerprinting-protection-tests.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ const tabManager = require('../../../shared/js/background/tab-manager');
88
const { getArgumentsObject } = require('../../../shared/js/background/helpers/arguments-object');
99

1010
const BatteryProtection = require('@duckduckgo/content-scope-scripts/injected/src/features/fingerprinting-battery').default;
11-
const batteryProtection = new BatteryProtection('fingerprintingBattery');
1211
const HardwareProtection = require('@duckduckgo/content-scope-scripts/injected/src/features/fingerprinting-hardware').default;
13-
const hardwareProtection = new HardwareProtection('fingerprintingHardware');
1412
const ScreenProtection = require('@duckduckgo/content-scope-scripts/injected/src/features/fingerprinting-screen-size').default;
15-
const screenProtection = new ScreenProtection('fingerprintingScreenSize');
1613
const TempStorageProtection = require('@duckduckgo/content-scope-scripts/injected/src/features/fingerprinting-temporary-storage').default;
17-
const tempStorageProtection = new TempStorageProtection('fingerprintingTemporaryStorage');
1814
const { isFeatureBroken } = require('@duckduckgo/content-scope-scripts/injected/src/utils');
1915

2016
const configReference = require('@duckduckgo/privacy-reference-tests/fingerprinting-protections/config_reference.json');
@@ -69,6 +65,14 @@ for (const setName of Object.keys(testSets)) {
6965

7066
// eslint-disable-next-line no-global-assign
7167
globalThis = dom.window;
68+
const importConfig = {
69+
trackerLookup: [],
70+
injectName: 'extensionTest',
71+
};
72+
const batteryProtection = new BatteryProtection('fingerprintingBattery', importConfig, args);
73+
const hardwareProtection = new HardwareProtection('fingerprintingHardware', importConfig, args);
74+
const screenProtection = new ScreenProtection('fingerprintingScreenSize', importConfig, args);
75+
const tempStorageProtection = new TempStorageProtection('fingerprintingTemporaryStorage', importConfig, args);
7276

7377
// init protections
7478
if (!isFeatureBroken(args, 'fingerprintingBattery')) {

0 commit comments

Comments
 (0)