Skip to content

Commit ebd07ae

Browse files
Test case
1 parent 8f5c3f3 commit ebd07ae

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

injected/integration-test/test-pages/infra/config/conditional-matching.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
"type": "number",
1111
"value": 222
1212
}
13+
},
14+
"Navigator.prototype.deviceMemory": {
15+
"type": "descriptor",
16+
"getterValue": {
17+
"type": "number",
18+
"value": 1111
19+
}
1320
}
1421
},
1522
"conditionalChanges": [
@@ -24,6 +31,34 @@
2431
"value": 333
2532
}
2633
]
34+
},
35+
{
36+
"condition": {
37+
"context": {
38+
"top": true
39+
}
40+
},
41+
"patchSettings": [
42+
{
43+
"op": "replace",
44+
"path": "/apiChanges/Navigator.prototype.deviceMemory/getterValue/value",
45+
"value": 43339
46+
}
47+
]
48+
},
49+
{
50+
"condition": {
51+
"context": {
52+
"frame": true
53+
}
54+
},
55+
"patchSettings": [
56+
{
57+
"op": "replace",
58+
"path": "/apiChanges/Navigator.prototype.deviceMemory/getterValue/value",
59+
"value": 43338
60+
}
61+
]
2762
}
2863
]
2964
}

injected/integration-test/test-pages/infra/pages/conditional-matching.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,46 @@
5656
return results;
5757
});
5858

59+
test('Conditional frame matching', async () => {
60+
const results = [];
61+
const frame = document.createElement('iframe');
62+
const scriptTag = 'script';
63+
frame.srcdoc = `
64+
<!DOCTYPE html>
65+
<html>
66+
<body>
67+
<${scriptTag}>
68+
window.addEventListener('message', (event) => {
69+
if (event.data === 'getDeviceMemory') {
70+
event.source.postMessage(navigator.deviceMemory, event.origin);
71+
}
72+
});
73+
</${scriptTag}>
74+
</body>
75+
</html>
76+
`;
77+
document.body.appendChild(frame);
78+
await new Promise(resolve => frame.onload = resolve);
79+
const deviceMemoryPromise = new Promise(resolve => {
80+
window.addEventListener('message', (event) => {
81+
resolve(event.data);
82+
}, { once: true });
83+
frame.contentWindow.postMessage('getDeviceMemory', '*');
84+
});
85+
const deviceMemory = await deviceMemoryPromise;
86+
results.push({
87+
name: "Ensure iframe changes work",
88+
result: deviceMemory,
89+
expected: 43338
90+
});
91+
results.push({
92+
name: "Expect frame top modification works",
93+
result: navigator.deviceMemory,
94+
expected: 43339
95+
});
96+
return results;
97+
});
98+
5999

60100
// eslint-disable-next-line no-undef
61101
renderResults();

0 commit comments

Comments
 (0)