Skip to content

Commit 9112a77

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[network] Fix VE context values for filter bar resource categories
Currently we use localized resource category names for the VE context, which breaks when using locales other than en-US. This CL fixes the problem by using en-US consistently as the underlying name for the category, while the label in the UI still gets transalted. Note that ideally we'd just use the enum variant name, but to stay backwards compatible with the already logged context names, we use the english UI strings. [email protected] Bug: None Change-Id: I94929e0157482cd37f44174df4a53a33cf7181f7 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5938364 Commit-Queue: Simon Zünd <[email protected]> Auto-Submit: Simon Zünd <[email protected]> Reviewed-by: Danil Somsikov <[email protected]> Commit-Queue: Danil Somsikov <[email protected]>
1 parent 3c522b4 commit 9112a77

File tree

3 files changed

+48
-39
lines changed

3 files changed

+48
-39
lines changed

front_end/core/common/ResourceType.test.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ const typeTestTitle = () => 'Type Test Title' as Platform.UIString.LocalizedStri
1818

1919
describe('ResourceCategory class', () => {
2020
it('is able to be instantiated successfully', () => {
21-
const resourceCategory = new ResourceCategory(testTitle, testShortTitle);
21+
const resourceCategory = new ResourceCategory('category name', testTitle, testShortTitle);
2222
assert.strictEqual(resourceCategory.title(), 'Test Title', 'title is not correct');
2323
assert.strictEqual(resourceCategory.shortTitle(), 'Test Short Title', 'short title is not correct');
2424
});
2525
});
2626

2727
describeWithEnvironment('ResourceType class', () => {
2828
it('is able to be instantiated successfully', () => {
29-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
29+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
3030
const resourceType = new ResourceType('Type Test Name', typeTestTitle, testResourceCategory, true);
3131
assert.strictEqual(resourceType.name(), 'Type Test Name', 'name was not set correctly');
3232
assert.strictEqual(resourceType.title(), 'Type Test Title', 'title was not set correctly');
@@ -234,153 +234,153 @@ describeWithEnvironment('ResourceType class', () => {
234234
});
235235

236236
it('is able to return its title successfully', () => {
237-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
237+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
238238
const resourceType = new ResourceType('Type Test Name', typeTestTitle, testResourceCategory, true);
239239
assert.strictEqual(resourceType.title(), 'Type Test Title', 'title was not returned correctly');
240240
});
241241

242242
it('is able to return its isTextType value successfully', () => {
243-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
243+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
244244
const resourceType = new ResourceType('Type Test Name', typeTestTitle, testResourceCategory, true);
245245
assert.isTrue(resourceType.isTextType(), 'isTextType was not returned correctly');
246246
});
247247

248248
it('is able to return whether or not its a script if its name equals the value "script"', () => {
249-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
249+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
250250
const resourceType = new ResourceType('script', typeTestTitle, testResourceCategory, true);
251251
assert.isTrue(resourceType.isScript(), 'the resource should be considered as a script');
252252
});
253253

254254
it('is able to return whether or not its a script if its name equals the value "sm-script"', () => {
255-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
255+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
256256
const resourceType = new ResourceType('sm-script', typeTestTitle, testResourceCategory, true);
257257
assert.isTrue(resourceType.isScript(), 'the resource should be considered as a script');
258258
});
259259

260260
it('is able to return whether or not its a script if its name is not equal to the values "script" or "sm-script"',
261261
() => {
262-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
262+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
263263
const resourceType = new ResourceType('Type Test Name', typeTestTitle, testResourceCategory, true);
264264
assert.isFalse(resourceType.isScript(), 'the resource should not be considered as a script');
265265
});
266266

267267
it('is able to return whether or not its a document if its name equals the value "document"', () => {
268-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
268+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
269269
const resourceType = new ResourceType('document', typeTestTitle, testResourceCategory, true);
270270
assert.isTrue(resourceType.isDocument(), 'the resource should be considered as a document');
271271
});
272272

273273
it('is able to return whether or not its a document if its name does not equal the value "document"', () => {
274-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
274+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
275275
const resourceType = new ResourceType('Type Test Name', typeTestTitle, testResourceCategory, true);
276276
assert.isFalse(resourceType.isDocument(), 'the resource should not be considered as a document');
277277
});
278278

279279
it('is able to determine if a resource has scripts if it is a script', () => {
280-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
280+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
281281
const resourceType = new ResourceType('script', typeTestTitle, testResourceCategory, true);
282282
assert.isTrue(resourceType.hasScripts(), 'the resource should be considered as a having scripts');
283283
});
284284

285285
it('is able to determine if a resource has scripts if it is a document', () => {
286-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
286+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
287287
const resourceType = new ResourceType('document', typeTestTitle, testResourceCategory, true);
288288
assert.isTrue(resourceType.hasScripts(), 'the resource should be considered as a having scripts');
289289
});
290290

291291
it('is able to determine if a resource has scripts if it is not a script or a document', () => {
292-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
292+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
293293
const resourceType = new ResourceType('Type Test Name', typeTestTitle, testResourceCategory, true);
294294
assert.isFalse(resourceType.hasScripts(), 'the resource should not be considered as a having scripts');
295295
});
296296

297297
it('is able to return whether or not its a stylesheet if its name equals the value "stylesheet"', () => {
298-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
298+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
299299
const resourceType = new ResourceType('stylesheet', typeTestTitle, testResourceCategory, true);
300300
assert.isTrue(resourceType.isStyleSheet(), 'the resource should be considered as a stylesheet');
301301
});
302302

303303
it('is able to return whether or not its a stylesheet if its name equals the value "sm-stylesheet"', () => {
304-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
304+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
305305
const resourceType = new ResourceType('sm-stylesheet', typeTestTitle, testResourceCategory, true);
306306
assert.isTrue(resourceType.isStyleSheet(), 'the resource should be considered as a stylesheet');
307307
});
308308

309309
it('is able to return whether or not its a stylesheet if its name is not equal to the values "stylesheet" or "sm-stylesheet"',
310310
() => {
311-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
311+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
312312
const resourceType = new ResourceType('Type Test Name', typeTestTitle, testResourceCategory, true);
313313
assert.isFalse(resourceType.isStyleSheet(), 'the resource should not be considered as a stylesheet');
314314
});
315315

316316
it('is able to return whether it is a document, a script or a stylesheet if it was a document', () => {
317-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
317+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
318318
const resourceType = new ResourceType('document', typeTestTitle, testResourceCategory, true);
319319
assert.isTrue(resourceType.isDocumentOrScriptOrStyleSheet(), 'the resource should be considered as a document');
320320
});
321321

322322
it('is able to return whether it is a document, a script or a stylesheet if it was a script', () => {
323-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
323+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
324324
const resourceType = new ResourceType('script', typeTestTitle, testResourceCategory, true);
325325
assert.isTrue(resourceType.isDocumentOrScriptOrStyleSheet(), 'the resource should be considered as a script');
326326
});
327327

328328
it('is able to return whether it is a document, a script or a stylesheet if it was a stylesheet', () => {
329-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
329+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
330330
const resourceType = new ResourceType('stylesheet', typeTestTitle, testResourceCategory, true);
331331
assert.isTrue(resourceType.isDocumentOrScriptOrStyleSheet(), 'the resource should be considered as a stylesheet');
332332
});
333333

334334
it('is able to return whether it is a document, a script or a stylesheet if it was none of those things', () => {
335-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
335+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
336336
const resourceType = new ResourceType('Type Test Name', typeTestTitle, testResourceCategory, true);
337337
assert.isFalse(
338338
resourceType.isDocumentOrScriptOrStyleSheet(),
339339
'the resource should be considered as a doucment, a script or a stylesheet');
340340
});
341341

342342
it('is able to determine if it is from source map if it began with "sm-"', () => {
343-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
343+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
344344
const resourceType = new ResourceType('sm-Type Test Name', typeTestTitle, testResourceCategory, true);
345345
assert.isTrue(resourceType.isFromSourceMap(), 'the resource should be considered to be from source map');
346346
});
347347

348348
it('is able to determine if it is from source map if it did not begin with "sm-"', () => {
349-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
349+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
350350
const resourceType = new ResourceType('Type Test Name', typeTestTitle, testResourceCategory, true);
351351
assert.isFalse(resourceType.isFromSourceMap(), 'the resource should not be considered to be from source map');
352352
});
353353

354354
it('is able to be converted to a string by returning its name', () => {
355-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
355+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
356356
const resourceType = new ResourceType('Type Test Name', typeTestTitle, testResourceCategory, true);
357357
assert.strictEqual(
358358
resourceType.toString(), 'Type Test Name', 'the resource type was not converted to a string correctly');
359359
});
360360

361361
it('is able to return the canonical mime type of a document', () => {
362-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
362+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
363363
const resourceType = new ResourceType('document', typeTestTitle, testResourceCategory, true);
364364
assert.strictEqual(
365365
resourceType.canonicalMimeType(), 'text/html', 'the canonical mime type was not returned correctly');
366366
});
367367

368368
it('is able to return the canonical mime type of a script', () => {
369-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
369+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
370370
const resourceType = new ResourceType('script', typeTestTitle, testResourceCategory, true);
371371
assert.strictEqual(
372372
resourceType.canonicalMimeType(), 'text/javascript', 'the canonical mime type was not returned correctly');
373373
});
374374

375375
it('is able to return the canonical mime type of a stylesheet', () => {
376-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
376+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
377377
const resourceType = new ResourceType('stylesheet', typeTestTitle, testResourceCategory, true);
378378
assert.strictEqual(
379379
resourceType.canonicalMimeType(), 'text/css', 'the canonical mime type was not returned correctly');
380380
});
381381

382382
it('returns an empty string as a canonical mime type if it was not a document, a script or a stylesheet', () => {
383-
const testResourceCategory = new ResourceCategory(categoryTestTitle, categoryTestShortTitle);
383+
const testResourceCategory = new ResourceCategory('category name', categoryTestTitle, categoryTestShortTitle);
384384
const resourceType = new ResourceType('Type Test Name', typeTestTitle, testResourceCategory, true);
385385
assert.strictEqual(resourceType.canonicalMimeType(), '', 'the canonical mime type was not returned correctly');
386386
});

front_end/core/common/ResourceType.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,13 @@ export class ResourceType {
354354
}
355355

356356
export class ResourceCategory {
357+
readonly name: string;
357358
title: () => Platform.UIString.LocalizedString;
358359
shortTitle: () => Platform.UIString.LocalizedString;
359-
constructor(title: () => Platform.UIString.LocalizedString, shortTitle: () => Platform.UIString.LocalizedString) {
360+
constructor(
361+
name: string, title: () => Platform.UIString.LocalizedString,
362+
shortTitle: () => Platform.UIString.LocalizedString) {
363+
this.name = name;
360364
this.title = title;
361365
this.shortTitle = shortTitle;
362366
}
@@ -368,17 +372,22 @@ export class ResourceCategory {
368372
}
369373

370374
export const resourceCategories = {
371-
XHR: new ResourceCategory(i18nLazyString(UIStrings.fetchAndXHR), i18n.i18n.lockedLazyString('Fetch/XHR')),
372-
Document: new ResourceCategory(i18nLazyString(UIStrings.document), i18nLazyString(UIStrings.doc)),
373-
Stylesheet: new ResourceCategory(i18nLazyString(UIStrings.css), i18nLazyString(UIStrings.css)),
374-
Script: new ResourceCategory(i18nLazyString(UIStrings.javascript), i18nLazyString(UIStrings.js)),
375-
Font: new ResourceCategory(i18nLazyString(UIStrings.font), i18nLazyString(UIStrings.font)),
376-
Image: new ResourceCategory(i18nLazyString(UIStrings.image), i18nLazyString(UIStrings.img)),
377-
Media: new ResourceCategory(i18nLazyString(UIStrings.media), i18nLazyString(UIStrings.media)),
378-
Manifest: new ResourceCategory(i18nLazyString(UIStrings.manifest), i18nLazyString(UIStrings.manifest)),
379-
WebSocket: new ResourceCategory(i18nLazyString(UIStrings.websocket), i18nLazyString(UIStrings.ws)),
380-
Wasm: new ResourceCategory(i18nLazyString(UIStrings.webassembly), i18nLazyString(UIStrings.wasm)),
381-
Other: new ResourceCategory(i18nLazyString(UIStrings.other), i18nLazyString(UIStrings.other)),
375+
XHR: new ResourceCategory(
376+
'Fetch and XHR', i18nLazyString(UIStrings.fetchAndXHR), i18n.i18n.lockedLazyString('Fetch/XHR')),
377+
Document: new ResourceCategory(UIStrings.document, i18nLazyString(UIStrings.document), i18nLazyString(UIStrings.doc)),
378+
Stylesheet: new ResourceCategory(UIStrings.css, i18nLazyString(UIStrings.css), i18nLazyString(UIStrings.css)),
379+
Script:
380+
new ResourceCategory(UIStrings.javascript, i18nLazyString(UIStrings.javascript), i18nLazyString(UIStrings.js)),
381+
Font: new ResourceCategory(UIStrings.font, i18nLazyString(UIStrings.font), i18nLazyString(UIStrings.font)),
382+
Image: new ResourceCategory(UIStrings.image, i18nLazyString(UIStrings.image), i18nLazyString(UIStrings.img)),
383+
Media: new ResourceCategory(UIStrings.media, i18nLazyString(UIStrings.media), i18nLazyString(UIStrings.media)),
384+
Manifest:
385+
new ResourceCategory(UIStrings.manifest, i18nLazyString(UIStrings.manifest), i18nLazyString(UIStrings.manifest)),
386+
WebSocket:
387+
new ResourceCategory(UIStrings.websocket, i18nLazyString(UIStrings.websocket), i18nLazyString(UIStrings.ws)),
388+
Wasm: new ResourceCategory(
389+
UIStrings.webassembly, i18nLazyString(UIStrings.webassembly), i18nLazyString(UIStrings.wasm)),
390+
Other: new ResourceCategory(UIStrings.other, i18nLazyString(UIStrings.other), i18nLazyString(UIStrings.other)),
382391
};
383392

384393
/**

front_end/panels/network/NetworkLogView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ export class NetworkLogView extends Common.ObjectWrapper.eventMixin<EventTypes,
587587

588588
const filterItems =
589589
Object.entries(Common.ResourceType.resourceCategories).map(([key, category]) => ({
590-
name: category.title(),
590+
name: category.name,
591591
label: () => category.shortTitle(),
592592
title: category.title(),
593593
jslogContext:

0 commit comments

Comments
 (0)