Skip to content

Commit 2aa63a8

Browse files
Add min supported version and integration testing (#1772)
* Condition Blocks to support minSupportedVersion * PoC adding integration test cases * Use new define props and also pass version to setup * Correct string verison * Remove window prefix to simplify * Add platform to extension mock --------- Co-authored-by: Shane Osbourne <[email protected]>
1 parent db1a0a6 commit 2aa63a8

File tree

9 files changed

+348
-12
lines changed

9 files changed

+348
-12
lines changed

injected/integration-test/page-objects/results-collector.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import { windowsGlobalPolyfills } from '../shared.mjs';
1515
import { processConfig } from '../../src/utils.js';
1616
import { gotoAndWait } from '../helpers/harness.js';
1717

18+
/**
19+
* @typedef {import('../../src/utils.js').Platform} Platform
20+
*/
21+
1822
/**
1923
* This is designed to allow you to execute Playwright tests using the various
2024
* artifacts we produce. For example, on the `apple` target this can be used to ensure
@@ -59,18 +63,19 @@ export class ResultsCollector {
5963
/**
6064
* @param {string} htmlPath
6165
* @param {string} configPath
66+
* @param {Partial<Platform>} [platform]
6267
*/
63-
async load(htmlPath, configPath) {
68+
async load(htmlPath, configPath, platform) {
6469
/**
6570
* For now, take a separate path for the extension since it's setup
6671
* is quite different to browsers. We hide this setup step from consumers,
6772
* allowing all platforms to call '.load(html, config)' and not care
6873
* about the details.
6974
*/
7075
if (this.platform.name === 'extension') {
71-
return await this._loadExtension(htmlPath, configPath);
76+
return await this._loadExtension(htmlPath, configPath, platform);
7277
}
73-
await this.setup({ config: configPath });
78+
await this.setup({ config: configPath, platform });
7479
await this.page.goto(htmlPath);
7580
}
7681

@@ -104,14 +109,16 @@ export class ResultsCollector {
104109
/**
105110
* @param {string} htmlPath
106111
* @param {string} configPath
112+
* @param {Partial<Platform>} [platform]
107113
* @private
108114
*/
109-
async _loadExtension(htmlPath, configPath) {
115+
async _loadExtension(htmlPath, configPath, platform) {
110116
const config = JSON.parse(readFileSync(configPath, 'utf8'));
111117
/** @type {import('../../src/utils.js').UserPreferences} */
112118
const userPreferences = {
113119
platform: {
114120
name: this.platform.name,
121+
...platform,
115122
},
116123
sessionKey: 'test',
117124
};
@@ -129,10 +136,11 @@ export class ResultsCollector {
129136
* @param {object} params
130137
* @param {Record<string, any> | string} params.config
131138
* @param {string} [params.locale]
139+
* @param {Partial<Platform>} [params.platform]
132140
* @return {Promise<void>}
133141
*/
134142
async setup(params) {
135-
let { config, locale } = params;
143+
let { config, locale, platform } = params;
136144

137145
if (typeof config === 'string') {
138146
config = JSON.parse(readFileSync(config, 'utf8'));
@@ -188,7 +196,7 @@ export class ResultsCollector {
188196
$CONTENT_SCOPE$: config,
189197
$USER_UNPROTECTED_DOMAINS$: [],
190198
$USER_PREFERENCES$: {
191-
platform: { name: this.platform.name },
199+
platform: { name: this.platform.name, ...platform },
192200
debug: true,
193201
messageCallback: 'messageCallback',
194202
messageSecret: 'duckduckgo-android-messaging-secret',

injected/integration-test/pages.spec.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,25 @@ import { testContextForExtension } from './helpers/harness.js';
77
import { ResultsCollector } from './page-objects/results-collector.js';
88

99
const test = testContextForExtension(base);
10+
/**
11+
* @typedef {import('../../injected/src/utils.js').Platform} Platform
12+
*/
1013

1114
test.describe('Test integration pages', () => {
1215
/**
1316
* @param {import("@playwright/test").Page} page
1417
* @param {import("@playwright/test").TestInfo} testInfo
1518
* @param {string} html
1619
* @param {string} config
20+
* @param {Partial<Platform>} [platform]
1721
*/
18-
async function testPage(page, testInfo, html, config) {
19-
const collector = ResultsCollector.create(page, testInfo.project.use);
20-
await collector.load(html, config);
22+
async function testPage(page, testInfo, html, config, platform = {}) {
23+
const collector = ResultsCollector.create(page, testInfo?.project?.use);
24+
await collector.load(html, config, platform);
2125
const results = await collector.results();
2226
for (const key in results) {
2327
for (const result of results[key]) {
24-
await test.step(`${key}:\n ${result.name}`, () => {
28+
await test.step(`${key}: ${result.name}`, () => {
2529
expect(result.result).toEqual(result.expected);
2630
});
2731
}
@@ -97,4 +101,24 @@ test.describe('Test integration pages', () => {
97101
`./integration-test/test-pages/webcompat/config/modify-cookies.json`,
98102
);
99103
});
104+
105+
test('minSupportedVersion (string)', async ({ page }, testInfo) => {
106+
await testPage(
107+
page,
108+
testInfo,
109+
'/infra/pages/min-supported-version-string.html',
110+
'./integration-test/test-pages/infra/config/min-supported-version-string.json',
111+
{ version: '1.5.0' },
112+
);
113+
});
114+
115+
test('minSupportedVersion (int)', async ({ page }, testInfo) => {
116+
await testPage(
117+
page,
118+
testInfo,
119+
'/infra/pages/min-supported-version-int.html',
120+
'./integration-test/test-pages/infra/config/min-supported-version-int.json',
121+
{ version: 99 },
122+
);
123+
});
100124
});
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"readme": "Test minSupportedVersion (int) with apiManipulation and conditionalPatching.",
3+
"version": 1,
4+
"features": {
5+
"apiManipulation": {
6+
"state": "enabled",
7+
"exceptions": [],
8+
"settings": {
9+
"apiChanges": {
10+
},
11+
"conditionalChanges": [
12+
{
13+
"condition": {
14+
"minSupportedVersion": 98
15+
},
16+
"patchSettings": [
17+
{
18+
"op": "add",
19+
"path": "/apiChanges/versionIntTestBelow",
20+
"value": {
21+
"type": "descriptor",
22+
"getterValue": {
23+
"type": "boolean",
24+
"value": true
25+
},
26+
"define": true
27+
}
28+
}
29+
]
30+
},
31+
{
32+
"condition": {
33+
"minSupportedVersion": 99
34+
},
35+
"patchSettings": [
36+
{
37+
"op": "add",
38+
"path": "/apiChanges/versionIntTestSame",
39+
"value": {
40+
"type": "descriptor",
41+
"getterValue": {
42+
"type": "boolean",
43+
"value": true
44+
},
45+
"define": true
46+
}
47+
}
48+
]
49+
},
50+
{
51+
"condition": {
52+
"minSupportedVersion": 100
53+
},
54+
"patchSettings": [
55+
{
56+
"op": "add",
57+
"path": "/apiChanges/versionIntTestAbove",
58+
"value": {
59+
"type": "descriptor",
60+
"getterValue": {
61+
"type": "boolean",
62+
"value": true
63+
},
64+
"define": true
65+
}
66+
}
67+
]
68+
}
69+
]
70+
}
71+
}
72+
},
73+
"unprotectedTemporary": []
74+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"readme": "Test minSupportedVersion (string) with apiManipulation and conditionalPatching.",
3+
"version": 1,
4+
"features": {
5+
"apiManipulation": {
6+
"state": "enabled",
7+
"exceptions": [],
8+
"settings": {
9+
"apiChanges": {},
10+
"conditionalChanges": [
11+
{
12+
"condition": {
13+
"minSupportedVersion": "1.0.0"
14+
},
15+
"patchSettings": [
16+
{
17+
"op": "add",
18+
"path": "/apiChanges/versionStringTestBelow",
19+
"value": {
20+
"type": "descriptor",
21+
"getterValue": {
22+
"type": "boolean",
23+
"value": true
24+
},
25+
"define": true
26+
}
27+
}
28+
]
29+
},
30+
{
31+
"condition": {
32+
"minSupportedVersion": "1.5.0"
33+
},
34+
"patchSettings": [
35+
{
36+
"op": "add",
37+
"path": "/apiChanges/versionStringTestSame",
38+
"value": {
39+
"type": "descriptor",
40+
"getterValue": {
41+
"type": "boolean",
42+
"value": true
43+
},
44+
"define": true
45+
}
46+
}
47+
]
48+
},
49+
{
50+
"condition": {
51+
"minSupportedVersion": "2.0.0"
52+
},
53+
"patchSettings": [
54+
{
55+
"op": "add",
56+
"path": "/apiChanges/versionStringTestAbove",
57+
"value": {
58+
"type": "descriptor",
59+
"getterValue": {
60+
"type": "boolean",
61+
"value": true
62+
},
63+
"define": true
64+
}
65+
}
66+
]
67+
}
68+
]
69+
}
70+
}
71+
},
72+
"unprotectedTemporary": []
73+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
<title>Min Supported Version (Int)</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+
<p>This page verifies minSupportedVersion (int) conditional patching. Load with 99 as the version number.</p>
13+
<script>
14+
test('minSupportedVersion (int)', async () => {
15+
const results = [];
16+
results.push({
17+
name: "versionIntTestBelow should always be true",
18+
result: window.versionIntTestBelow,
19+
expected: true
20+
});
21+
results.push({
22+
name: "versionIntTestSame should always be true",
23+
result: window.versionIntTestSame,
24+
expected: true
25+
});
26+
results.push({
27+
name: "versionIntTestAbove should be undefined",
28+
result: window.versionIntTestAbove,
29+
expected: undefined
30+
});
31+
return results;
32+
});
33+
renderResults();
34+
</script>
35+
</body>
36+
</html>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
<title>Min Supported Version (String)</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+
<p>This page verifies minSupportedVersion (string) conditional patching. Load with 1.5.0 as the version number.</p>
13+
<script>
14+
test('minSupportedVersion (string)', async () => {
15+
const results = [];
16+
results.push({
17+
name: "versionStringTestBelow should always be true",
18+
result: window.versionStringTestBelow,
19+
expected: true
20+
});
21+
results.push({
22+
name: "versionStringTestSame should always be true",
23+
result: window.versionStringTestSame,
24+
expected: true
25+
});
26+
results.push({
27+
name: "versionStringTestAbove should be undefined",
28+
result: window.versionStringTestAbove,
29+
expected: undefined
30+
});
31+
return results;
32+
});
33+
renderResults();
34+
</script>
35+
</body>
36+
</html>

0 commit comments

Comments
 (0)