Skip to content

Experiment enabling #1696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 46 additions & 24 deletions injected/entry-points/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
}

function generateConfig() {
function generateArgs() {
const topLevelUrl = getTopLevelURL();
return {
debug: false,
Expand All @@ -38,18 +38,47 @@
domain: topLevelUrl.hostname,
url: topLevelUrl.href,
isBroken: false,
allowlisted: false,
enabledFeatures: [
'fingerprintingCanvas',
'fingerprintingScreenSize',
'navigatorInterface',
'cookie',
'webCompat',
'apiManipulation',
'duckPlayer',
'duckPlayerNative',
],
allowlisted: false
},
bundledConfig: {
features: {
fingerprintingCanvas: {
state: 'enabled',
settings: {},
exceptions: [],
},
fingerprintingScreenSize: {
state: 'enabled',
settings: {},
exceptions: [],
},
navigatorInterface: {
state: 'enabled',
settings: {},
exceptions: [],
},
cookie: {
state: 'enabled',
settings: {},
exceptions: [],
},
webCompat: {
state: 'enabled',
settings: {},
exceptions: [],
},
apiManipulation: {
state: 'enabled',
settings: {},
exceptions: [],
},
duckPlayerNative: {
state: 'enabled',
settings: {},
exceptions: [],
},
}
}
};
}

Expand Down Expand Up @@ -87,10 +116,10 @@

async function initCode() {
const topLevelUrl = getTopLevelURL();
const processedConfig = generateConfig();
const processedArgs = generateArgs();

// mock Messaging and allow for tests to intercept them
globalThis.cssMessaging = processedConfig.messagingConfig = new TestTransportConfig({
globalThis.cssMessaging = processedArgs.messagingConfig = new TestTransportConfig({
notify() {
// noop
},
Expand All @@ -104,20 +133,13 @@
},
});

load({
// @ts-expect-error Types of property 'name' are incompatible.
platform: processedConfig.platform,
site: processedConfig.site,
bundledConfig: processedConfig.bundledConfig,
messagingConfig: processedConfig.messagingConfig,
currentCohorts: processedConfig.currentCohorts,
});
load(processedArgs);

Check failure on line 136 in injected/entry-points/integration.js

View workflow job for this annotation

GitHub Actions / unit (ubuntu-latest)

Argument of type '{ debug: boolean; sessionKey: string; platform: { name: string; }; currentCohorts: { feature: string; subfeature: string; cohort: string; }[]; site: { domain: string; url: string; isBroken: boolean; allowlisted: boolean; }; bundledConfig: { ...; }; }' is not assignable to parameter of type 'LoadArgs'.

Check failure on line 136 in injected/entry-points/integration.js

View workflow job for this annotation

GitHub Actions / snapshots

Argument of type '{ debug: boolean; sessionKey: string; platform: { name: string; }; currentCohorts: { feature: string; subfeature: string; cohort: string; }[]; site: { domain: string; url: string; isBroken: boolean; allowlisted: boolean; }; bundledConfig: { ...; }; }' is not assignable to parameter of type 'LoadArgs'.

// mark this phase as loaded
setStatus('loaded');

if (!topLevelUrl.searchParams.has('wait-for-init-args')) {
await init(processedConfig);
await init(processedArgs);
setStatus('initialized');
return;
}
Expand All @@ -127,7 +149,7 @@
'content-scope-init-args',
async (evt) => {
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
const merged = mergeDeep(processedConfig, evt.detail);
const merged = mergeDeep(processedArgs, evt.detail);
// init features
await init(merged);

Expand Down
9 changes: 9 additions & 0 deletions injected/integration-test/pages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ test.describe('Test integration pages', () => {
);
});

test('Test infra with experiments enabling', async ({ page }, testInfo) => {
await testPage(
page,
testInfo,
'/infra/pages/conditional-matching-experiments-enable.html',
'./integration-test/test-pages/infra/config/conditional-matching-experiments-enable.json',
);
});

test('Test infra fallback', async ({ page }, testInfo) => {
await page.addInitScript(() => {
// This ensures that our fallback code applies and so we simulate other platforms than Chromium.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"features": {
"contentScopeExperiments": {
"exceptions": [],
"state": "enabled",
"features": {
"bloops": {
"state": "enabled",
"rollout": {},
"cohorts": [
{
"name": "control",
"weight": 1
},
{
"name": "treatment",
"weight": 1
}
]
},
"test": {
"state": "enabled",
"rollout": {},
"cohorts": [
{
"name": "control",
"weight": 1
},
{
"name": "treatment",
"weight": 1
}
]
}
}
},
"apiManipulation": {
"state": "disabled",
"settings": {
"apiChanges": {
"Navigator.prototype.hardwareConcurrency": {
"type": "descriptor",
"getterValue": {
"type": "number",
"value": 400
}
}
},
"conditionalChanges": [
{
"condition": {
"experiment": {
"experimentName": "bloops",
"cohort": "treatment"
}
},
"state": "enabled"
},
{
"condition": {
"experiment": {
"experimentName": "bloops",
"cohort": "control"
}
},
"state": "enabled"
}
]
}
},
"exceptions": []
}
}
1 change: 1 addition & 0 deletions injected/integration-test/test-pages/infra/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ul>
<li><a href="./pages/conditional-matching.html">Conditional matching</a> - <a href="./config/conditional-matching.json">Config</a></li>
<li><a href="./pages/conditional-matching-experiments.html">Conditional matching experiments</a> - <a href="./config/conditional-matching-experiments.json">Config</a></li>
<li><a href="./pages/conditional-matching-experiments-enable.html">Conditional matching experiment enable feature</a> - <a href="./config/conditional-matching-experiments-enable.json">Config</a></li>
</ul>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Conditional Matching experiments</title>
<link rel="stylesheet" href="../../shared/style.css">
</head>
<body>
<script src="../../shared/utils.js"></script>
<p><a href="../index.html">[Infra]</a></p>

<p>This page verifies that features can be enabled when in an experiment. Ensure you're sending the following cohorts:
<code>
currentCohorts: [
{
"feature": "contentScopeExperiments",
"subfeature": "bloops",
"cohort": "control",
},
{
"feature": "contentScopeExperiments",
"subfeature": "test",
"cohort": "treatment",
},
],
</code>
</p>

<script>
test('Conditional matching experiments enabling', async () => {
const res = navigator.hardwareConcurrency;
const results = [
{
name: "APIs changing, expecting to always match",
result: res,
expected: 400,
}
];
return results;
});

// eslint-disable-next-line no-undef
renderResults();
</script>
</body>
</html>
Loading
Loading