Skip to content

Commit b3042fb

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
Fix network category filters when using locales other than en-US
The CL https://crrev.com/c/5938364 changed resource categories to use an un-localized name as a key, as this was messsing with VE logging. This broke the filter UI for non-english locales, as the NetworkLogView would retrieve the "title" instead of the "name" from each NetworkRequest to check if a filter applies. This CL fixes this and adds a regression test. [email protected] Fixed: 382596366 Change-Id: I039614285a99b948ea21b224255be557ad5a5fb4 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6085916 Reviewed-by: Danil Somsikov <[email protected]> Commit-Queue: Simon Zünd <[email protected]>
1 parent fcc22ff commit b3042fb

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

front_end/panels/network/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ ts_library("unittests") {
162162
":bundle",
163163
":meta",
164164
"../../core/common:bundle",
165+
"../../core/i18n:bundle",
165166
"../../core/platform:bundle",
166167
"../../core/sdk:bundle",
167168
"../../generated:protocol",

front_end/panels/network/NetworkLogView.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44
import * as Common from '../../core/common/common.js';
55
import * as Host from '../../core/host/host.js';
6+
import * as i18n from '../../core/i18n/i18n.js';
67
import type * as Platform from '../../core/platform/platform.js';
78
import * as Root from '../../core/root/root.js';
89
import * as SDK from '../../core/sdk/sdk.js';
@@ -703,6 +704,37 @@ describeWithMockConnection('NetworkLogView', () => {
703704
]);
704705
});
705706

707+
it('filters localized resource categories', async () => {
708+
// "simulate" other locale by stubbing out resource categories with a different text
709+
sinon.stub(Common.ResourceType.resourceCategories.Document, 'title')
710+
.returns(i18n.i18n.lockedString('<localized document>'));
711+
sinon.stub(Common.ResourceType.resourceCategories.XHR, 'title').returns(i18n.i18n.lockedString('<localized xhr>'));
712+
713+
const documentRequest = createNetworkRequest('urlDocument', {finished: true});
714+
documentRequest.setResourceType(Common.ResourceType.resourceTypes.Document);
715+
const fetchRequest = createNetworkRequest('urlFetch', {finished: true});
716+
fetchRequest.setResourceType(Common.ResourceType.resourceTypes.Fetch);
717+
718+
const filterBar = new UI.FilterBar.FilterBar('network-panel', true);
719+
networkLogView = createNetworkLogView(filterBar);
720+
721+
networkLogView.markAsRoot();
722+
networkLogView.show(document.body);
723+
const rootNode = networkLogView.columns().dataGrid().rootNode();
724+
const shownRequestUrls = () => rootNode.children.map(
725+
n => (n as Network.NetworkDataGridNode.NetworkNode).request()?.url() as string | undefined);
726+
727+
const setting = Common.Settings.Settings.instance().createSetting('network-resource-type-filters', {});
728+
setting.set({all: true});
729+
assert.deepEqual(shownRequestUrls(), ['urlDocument', 'urlFetch']);
730+
731+
setting.set({[Common.ResourceType.resourceCategories.Document.name]: true});
732+
assert.deepEqual(shownRequestUrls(), ['urlDocument']);
733+
734+
setting.set({[Common.ResourceType.resourceCategories.XHR.name]: true});
735+
assert.deepEqual(shownRequestUrls(), ['urlFetch']);
736+
});
737+
706738
it('"Copy all" commands respects filters', async () => {
707739
createOverrideRequests();
708740

front_end/panels/network/NetworkLogView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1999,7 +1999,7 @@ export class NetworkLogView extends Common.ObjectWrapper.eventMixin<EventTypes,
19991999
if (this.timeFilter && !this.timeFilter(request)) {
20002000
return false;
20012001
}
2002-
const categoryName = request.resourceType().category().title();
2002+
const categoryName = request.resourceType().category().name;
20032003
if (!this.resourceCategoryFilterUI.accept(categoryName)) {
20042004
return false;
20052005
}

0 commit comments

Comments
 (0)