Skip to content

Commit 5683d86

Browse files
Add test case
1 parent c8e9cb6 commit 5683d86

File tree

6 files changed

+156
-1
lines changed

6 files changed

+156
-1
lines changed

injected/entry-points/integration.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ function generateConfig() {
2222
platform: {
2323
name: 'extension',
2424
},
25+
currentCohorts: [
26+
{
27+
feature: 'ContentScopeExperiments',
28+
subfeature: 'bloops',
29+
cohort: 'control',
30+
},
31+
{
32+
feature: 'ContentScopeExperiments',
33+
subfeature: 'test',
34+
cohort: 'treatment',
35+
},
36+
],
2537
site: {
2638
domain: topLevelUrl.hostname,
2739
url: topLevelUrl.href,
@@ -97,6 +109,7 @@ async function initCode() {
97109
site: processedConfig.site,
98110
bundledConfig: processedConfig.bundledConfig,
99111
messagingConfig: processedConfig.messagingConfig,
112+
currentCohorts: processedConfig.currentCohorts,
100113
});
101114

102115
// mark this phase as loaded

injected/integration-test/pages.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ test.describe('Test integration pages', () => {
3737
);
3838
});
3939

40+
test('Test infra with experiments', async ({ page }, testInfo) => {
41+
await testPage(
42+
page,
43+
testInfo,
44+
'/infra/pages/conditional-matching-experiments.html',
45+
'./integration-test/test-pages/infra/config/conditional-matching-experiments.json',
46+
);
47+
});
48+
4049
test('Test infra fallback', async ({ page }, testInfo) => {
4150
await page.addInitScript(() => {
4251
// This ensures that our fallback code applies and so we simulate other platforms than Chromium.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"features": {
3+
"contentScopeExperiments": {
4+
"exceptions": [],
5+
"state": "enabled",
6+
"features": {
7+
"bloops": {
8+
"state": "enabled",
9+
"rollout": {},
10+
"cohorts": [
11+
{
12+
"name": "control",
13+
"weight": 1
14+
},
15+
{
16+
"name": "treatment",
17+
"weight": 1
18+
}
19+
]
20+
},
21+
"test": {
22+
"state": "enabled",
23+
"rollout": {},
24+
"cohorts": [
25+
{
26+
"name": "control",
27+
"weight": 1
28+
},
29+
{
30+
"name": "treatment",
31+
"weight": 1
32+
}
33+
]
34+
}
35+
}
36+
},
37+
"apiManipulation": {
38+
"state": "enabled",
39+
"settings": {
40+
"apiChanges": {
41+
"Navigator.prototype.hardwareConcurrency": {
42+
"type": "descriptor",
43+
"getterValue": {
44+
"type": "number",
45+
"value": 100
46+
}
47+
}
48+
}
49+
},
50+
"conditionalChanges": [
51+
{
52+
"condition": {
53+
"experiment": {
54+
"experimentName": "bloops",
55+
"cohort": "treatment"
56+
}
57+
},
58+
"patchSettings": [
59+
{
60+
"op": "replace",
61+
"path": "/apiChanges/Navigator.prototype.hardwareConcurrency/getterValue/value",
62+
"value": 200
63+
}
64+
]
65+
},
66+
{
67+
"condition": {
68+
"experiment": {
69+
"experimentName": "bloops",
70+
"cohort": "control"
71+
}
72+
},
73+
"patchSettings": [
74+
{
75+
"op": "replace",
76+
"path": "/apiChanges/Navigator.prototype.hardwareConcurrency/getterValue/value",
77+
"value": 300
78+
}
79+
]
80+
}
81+
]
82+
},
83+
"exceptions": []
84+
}
85+
}

injected/integration-test/test-pages/infra/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<p><a href="../../index.html">[Home]</a></p>
1111
<ul>
1212
<li><a href="./pages/conditional-matching.html">Conditional matching</a> - <a href="./config/conditional-matching.json">Config</a></li>
13+
<li><a href="./pages/conditional-matching-experiments.html">Conditional matching experiments</a> - <a href="./config/conditional-matching-experiments.json">Config</a></li>
1314
</ul>
1415
</body>
1516
</html>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
<title>Conditional Matching experiments</title>
7+
<link rel="stylesheet" href="../../shared/style.css">
8+
</head>
9+
<body>
10+
<script src="../../shared/utils.js"></script>
11+
<p><a href="../index.html">[Infra]</a></p>
12+
13+
<p>This page verifies that APIs get modified when in an experiment. Ensure you're sending the following cohorts:
14+
<code>
15+
currentCohorts: [
16+
{
17+
"feature": "ContentScopeExperiments",
18+
"subfeature": "bloops",
19+
"cohort": "control",
20+
},
21+
{
22+
"feature": "ContentScopeExperiments",
23+
"subfeature": "test",
24+
"cohort": "treatment",
25+
},
26+
],
27+
</code>
28+
</p>
29+
30+
<script>
31+
test('Conditional matching experiments', async () => {
32+
const res = navigator.hardwareConcurrency;
33+
const results = [
34+
{
35+
name: "APIs changing, expecting to always match",
36+
result: res,
37+
expected: res === 200 || res === 300, // Either is valid here, but 100 is the default which would mean the experiment is not running
38+
}
39+
];
40+
return results;
41+
});
42+
43+
// eslint-disable-next-line no-undef
44+
renderResults();
45+
</script>
46+
</body>
47+
</html>

injected/src/config-feature.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export default class ConfigFeature {
190190
if (!currentCohorts) return false;
191191
return currentCohorts.some((cohort) => {
192192
return (
193-
cohort.feature === "ContentScopeExperiments" &&
193+
cohort.feature === 'ContentScopeExperiments' &&
194194
cohort.subfeature === experiment.experimentName &&
195195
cohort.cohort === experiment.cohort
196196
);

0 commit comments

Comments
 (0)