Skip to content

Commit 88564e7

Browse files
paulirishDevtools-frontend LUCI CQ
authored andcommitted
Ensure all emulated Chrome UAs use up-to-date major version
Bug:376599410,40281049,41158407 Change-Id: I1bb14367088b3bfa959cbe02b13971a848697721 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6089911 Commit-Queue: Paul Irish <[email protected]> Reviewed-by: Ergün Erdoğmuş <[email protected]>
1 parent afe4e3d commit 88564e7

File tree

5 files changed

+65
-25
lines changed

5 files changed

+65
-25
lines changed

front_end/models/emulation/EmulatedDevices.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import {describeWithEnvironment} from '../../testing/EnvironmentHelpers.js';
56
import * as EmulationModel from '../emulation/emulation.js';
67

78
const BASE_URL = new URL('../../../front_end/emulated_devices/', import.meta.url).toString();
@@ -39,3 +40,22 @@ describe('EmulatedDevices can compute CSS image URLs', () => {
3940
'a lot of @url(stuff) in a @url(single)line and more url() @@url (not/a/resource.gif)'));
4041
});
4142
});
43+
44+
describeWithEnvironment('emulatedDevices', () => {
45+
it('before parsing, all Chrome UAs all have %s placeholder for major version patching', () => {
46+
const devices = EmulationModel.EmulatedDevices.EmulatedDevicesList.rawEmulatedDevicesForTest();
47+
const chromeRawDevices = devices.filter(d => d['user-agent'].includes(' Chrome/'));
48+
assert.isAtLeast(chromeRawDevices.length, 20);
49+
// We should not add any new UAs without the %s that gets patched via `patchUserAgentWithChromeVersion`
50+
assert.isTrue(chromeRawDevices.every(d => d['user-agent'].includes('Chrome/%s')));
51+
});
52+
53+
it('after parsing, all Chrome UAs all have %s placeholder for major version patching', () => {
54+
const edList = new EmulationModel.EmulatedDevices.EmulatedDevicesList();
55+
const parsedDevices = edList.standard();
56+
const chromeDevices = parsedDevices.filter(d => d.userAgent.includes(' Chrome/'));
57+
assert.isAtLeast(chromeDevices.length, 20);
58+
// They are patched while parsed, so there should be none remaining
59+
assert.lengthOf(chromeDevices.filter(d => d.userAgent.includes('Chrome/%s')), 0);
60+
});
61+
});

front_end/models/emulation/EmulatedDevices.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ export class EmulatedDevicesList extends Common.ObjectWrapper.ObjectWrapper<Even
535535

536536
private updateStandardDevices(): void {
537537
const devices = new Set<EmulatedDevice>();
538-
for (const extension of emulatedDevices) {
539-
const device = EmulatedDevice.fromJSONV1(extension);
538+
for (const emulatedDevice of emulatedDevices) {
539+
const device = EmulatedDevice.fromJSONV1(emulatedDevice);
540540
if (device) {
541541
devices.add(device);
542542
}
@@ -566,6 +566,10 @@ export class EmulatedDevicesList extends Common.ObjectWrapper.ObjectWrapper<Even
566566
return success;
567567
}
568568

569+
static rawEmulatedDevicesForTest(): typeof emulatedDevices {
570+
return emulatedDevices;
571+
}
572+
569573
standard(): EmulatedDevice[] {
570574
return [...this.#standardInternal];
571575
}
@@ -758,7 +762,7 @@ const emulatedDevices = [
758762
},
759763
'capabilities': ['touch', 'mobile'],
760764
'user-agent':
761-
'Mozilla/5.0 (Linux; Android 11; Pixel 3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.181 Mobile Safari/537.36',
765+
'Mozilla/5.0 (Linux; Android 11; Pixel 3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36',
762766
'user-agent-metadata':
763767
{'platform': 'Android', 'platformVersion': '11', 'architecture': '', 'model': 'Pixel 3', 'mobile': true},
764768
'type': 'phone',
@@ -780,7 +784,7 @@ const emulatedDevices = [
780784
},
781785
'capabilities': ['touch', 'mobile'],
782786
'user-agent':
783-
'Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36',
787+
'Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36',
784788
'user-agent-metadata':
785789
{'platform': 'Android', 'platformVersion': '13', 'architecture': '', 'model': 'Pixel 5', 'mobile': true},
786790
'type': 'phone',
@@ -802,7 +806,7 @@ const emulatedDevices = [
802806
},
803807
'capabilities': ['touch', 'mobile'],
804808
'user-agent':
805-
'Mozilla/5.0 (Linux; Android 8.0.0; SM-G955U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36',
809+
'Mozilla/5.0 (Linux; Android 8.0.0; SM-G955U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36',
806810
'user-agent-metadata':
807811
{'platform': 'Android', 'platformVersion': '8.0.0', 'architecture': '', 'model': 'SM-G955U', 'mobile': true},
808812
'type': 'phone',
@@ -824,7 +828,7 @@ const emulatedDevices = [
824828
},
825829
'capabilities': ['touch', 'mobile'],
826830
'user-agent':
827-
'Mozilla/5.0 (Linux; Android 13; SM-G981B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36',
831+
'Mozilla/5.0 (Linux; Android 13; SM-G981B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36',
828832
'user-agent-metadata':
829833
{'platform': 'Android', 'platformVersion': '13', 'architecture': '', 'model': 'SM-G981B', 'mobile': true},
830834
'type': 'phone',
@@ -906,7 +910,7 @@ const emulatedDevices = [
906910
},
907911
'capabilities': ['touch', 'mobile'],
908912
'user-agent':
909-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
913+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Safari/537.36',
910914
'type': 'tablet',
911915
},
912916
{
@@ -1033,7 +1037,7 @@ const emulatedDevices = [
10331037
},
10341038
'capabilities': ['touch'],
10351039
'user-agent':
1036-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
1040+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Safari/537.36',
10371041
'user-agent-metadata':
10381042
{'platform': 'Windows', 'platformVersion': '11.0', 'architecture': '', 'model': 'UX9702AA', 'mobile': false},
10391043
'type': 'tablet',
@@ -1069,7 +1073,7 @@ const emulatedDevices = [
10691073
},
10701074
'capabilities': ['touch', 'mobile'],
10711075
'user-agent':
1072-
'Mozilla/5.0 (Linux; Android 8.0.0; SM-G955U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36',
1076+
'Mozilla/5.0 (Linux; Android 8.0.0; SM-G955U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36',
10731077
'user-agent-metadata':
10741078
{'platform': 'Android', 'platformVersion': '8.0.0', 'architecture': '', 'model': 'SM-G955U', 'mobile': true},
10751079
'type': 'phone',
@@ -1095,7 +1099,7 @@ const emulatedDevices = [
10951099
},
10961100
'capabilities': ['touch', 'mobile'],
10971101
'user-agent':
1098-
'Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.188 Safari/537.36 CrKey/1.54.250320',
1102+
'Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Safari/537.36 CrKey/1.54.250320',
10991103
'type': 'tablet',
11001104
'modes': [{'title': 'default', 'orientation': 'horizontal'}],
11011105
},
@@ -1120,7 +1124,7 @@ const emulatedDevices = [
11201124
},
11211125
'capabilities': ['touch', 'mobile'],
11221126
'user-agent':
1123-
'Mozilla/5.0 (Linux; Android) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.109 Safari/537.36 CrKey/1.54.248666',
1127+
'Mozilla/5.0 (Linux; Android) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Safari/537.36 CrKey/1.54.248666',
11241128
'user-agent-metadata':
11251129
{'platform': 'Android', 'platformVersion': '', 'architecture': '', 'model': '', 'mobile': false},
11261130
'type': 'tablet',
@@ -1485,7 +1489,7 @@ const emulatedDevices = [
14851489
},
14861490
'capabilities': ['touch', 'mobile'],
14871491
'user-agent':
1488-
'Mozilla/5.0 (Linux; Android 9; Pixel 3 Build/PQ1A.181105.017.A1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.158 Mobile Safari/537.36',
1492+
'Mozilla/5.0 (Linux; Android 9; Pixel 3 Build/PQ1A.181105.017.A1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36',
14891493
'user-agent-metadata':
14901494
{'platform': 'Android', 'platformVersion': '9', 'architecture': '', 'model': 'Pixel 3', 'mobile': true},
14911495
'type': 'phone',
@@ -1500,7 +1504,7 @@ const emulatedDevices = [
15001504
},
15011505
'capabilities': ['touch', 'mobile'],
15021506
'user-agent':
1503-
'Mozilla/5.0 (Linux; Android 10; Pixel 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Mobile Safari/537.36',
1507+
'Mozilla/5.0 (Linux; Android 10; Pixel 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36',
15041508
'user-agent-metadata':
15051509
{'platform': 'Android', 'platformVersion': '10', 'architecture': '', 'model': 'Pixel 4', 'mobile': true},
15061510
'type': 'phone',
@@ -1556,7 +1560,7 @@ const emulatedDevices = [
15561560
},
15571561
'capabilities': ['touch', 'mobile'],
15581562
'user-agent':
1559-
'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 550) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263',
1563+
'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 550) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36 Edge/14.14263',
15601564
'user-agent-metadata':
15611565
{'platform': 'Android', 'platformVersion': '4.2.1', 'architecture': '', 'model': 'Lumia 550', 'mobile': true},
15621566
'type': 'phone',
@@ -1571,7 +1575,7 @@ const emulatedDevices = [
15711575
},
15721576
'capabilities': ['touch', 'mobile'],
15731577
'user-agent':
1574-
'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263',
1578+
'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36 Edge/14.14263',
15751579
'user-agent-metadata':
15761580
{'platform': 'Android', 'platformVersion': '4.2.1', 'architecture': '', 'model': 'Lumia 950', 'mobile': true},
15771581
'type': 'phone',
@@ -1617,7 +1621,7 @@ const emulatedDevices = [
16171621
},
16181622
'capabilities': ['touch', 'mobile'],
16191623
'user-agent':
1620-
'Mozilla/5.0 (Linux; Android 7.0; SM-G950U Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36',
1624+
'Mozilla/5.0 (Linux; Android 7.0; SM-G950U Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36',
16211625
'user-agent-metadata':
16221626
{'platform': 'Android', 'platformVersion': '7.0', 'architecture': '', 'model': 'SM-G950U', 'mobile': true},
16231627
'type': 'phone',
@@ -1632,7 +1636,7 @@ const emulatedDevices = [
16321636
},
16331637
'capabilities': ['touch', 'mobile'],
16341638
'user-agent':
1635-
'Mozilla/5.0 (Linux; Android 8.0.0; SM-G965U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.111 Mobile Safari/537.36',
1639+
'Mozilla/5.0 (Linux; Android 8.0.0; SM-G965U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36',
16361640
'user-agent-metadata':
16371641
{'platform': 'Android', 'platformVersion': '8.0.0', 'architecture': '', 'model': 'SM-G965U', 'mobile': true},
16381642
'type': 'phone',
@@ -1647,7 +1651,7 @@ const emulatedDevices = [
16471651
},
16481652
'capabilities': ['touch', 'mobile'],
16491653
'user-agent':
1650-
'Mozilla/5.0 (Linux; Android 8.1.0; SM-T837A) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.80 Safari/537.36',
1654+
'Mozilla/5.0 (Linux; Android 8.1.0; SM-T837A) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Safari/537.36',
16511655
'user-agent-metadata':
16521656
{'platform': 'Android', 'platformVersion': '8.1.0', 'architecture': '', 'model': 'SM-T837A', 'mobile': false},
16531657
'type': 'phone',

front_end/panels/network/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ ts_library("unittests") {
144144

145145
sources = [
146146
"BlockedURLsPane.test.ts",
147+
"NetworkConfigView.test.ts",
147148
"NetworkDataGridNode.test.ts",
148149
"NetworkItemView.test.ts",
149150
"NetworkLogView.test.ts",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2024 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import * as Network from './network.js';
6+
7+
describe('userAgentGroups', () => {
8+
it('Chrome UAs all have placeholder for major version patching', () => {
9+
const {userAgentGroups} = Network.NetworkConfigView;
10+
const chromeUAs = userAgentGroups.map(g => g.values).flat().filter(v => v.value.includes(' Chrome/'));
11+
assert.isAtLeast(chromeUAs.length, 10);
12+
// We should not add any new UAs without the %s that gets patched via `patchUserAgentWithChromeVersion`
13+
assert.isTrue(chromeUAs.every(v => v.value.includes('Chrome/%s')));
14+
});
15+
});

front_end/panels/network/NetworkConfigView.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ export const userAgentGroups: UserAgentGroup[] = [
723723
{
724724
title: 'Microsoft Edge \u2014 Android Mobile',
725725
value:
726-
'Mozilla/5.0 (Linux; Android 8.1.0; Pixel Build/OPM4.171019.021.D1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.109 Mobile Safari/537.36 EdgA/42.0.0.2057',
726+
'Mozilla/5.0 (Linux; Android 8.1.0; Pixel Build/OPM4.171019.021.D1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36 EdgA/42.0.0.2057',
727727
metadata: {
728728
brands: [
729729
{brand: 'Not A;Brand', version: '99'},
@@ -741,7 +741,7 @@ export const userAgentGroups: UserAgentGroup[] = [
741741
{
742742
title: 'Microsoft Edge \u2014 Android Tablet',
743743
value:
744-
'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MOB30X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.109 Safari/537.36 EdgA/42.0.0.2057',
744+
'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MOB30X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Safari/537.36 EdgA/42.0.0.2057',
745745
metadata: {
746746
brands: [
747747
{brand: 'Not A;Brand', version: '99'},
@@ -759,13 +759,13 @@ export const userAgentGroups: UserAgentGroup[] = [
759759
{
760760
title: 'Microsoft Edge (EdgeHTML) \u2014 Windows',
761761
value:
762-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19042',
762+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Safari/537.36 Edge/18.19042',
763763
metadata: null,
764764
},
765765
{
766766
title: 'Microsoft Edge (EdgeHTML) \u2014 XBox',
767767
value:
768-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; Xbox; Xbox One) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19041',
768+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; Xbox; Xbox One) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Safari/537.36 Edge/18.19041',
769769
metadata: null,
770770
},
771771
],
@@ -776,13 +776,13 @@ export const userAgentGroups: UserAgentGroup[] = [
776776
{
777777
title: 'Opera \u2014 Mac',
778778
value:
779-
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36 OPR/65.0.3467.48',
779+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Safari/537.36 OPR/65.0.3467.48',
780780
metadata: null,
781781
},
782782
{
783783
title: 'Opera \u2014 Windows',
784784
value:
785-
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36 OPR/65.0.3467.48',
785+
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Safari/537.36 OPR/65.0.3467.48',
786786
metadata: null,
787787
},
788788
{
@@ -836,7 +836,7 @@ export const userAgentGroups: UserAgentGroup[] = [
836836
{
837837
title: 'UC Browser \u2014 Android Mobile',
838838
value:
839-
'Mozilla/5.0 (Linux; U; Android 8.1.0; en-US; Nexus 6P Build/OPM7.181205.001) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/12.11.1.1197 Mobile Safari/537.36',
839+
'Mozilla/5.0 (Linux; U; Android 8.1.0; en-US; Nexus 6P Build/OPM7.181205.001) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/%s UCBrowser/12.11.1.1197 Mobile Safari/537.36',
840840
metadata: null,
841841
},
842842
{

0 commit comments

Comments
 (0)