Skip to content

Commit a13e0a6

Browse files
Robert LinDevtools-frontend LUCI CQ
Robert Lin
authored and
Devtools-frontend LUCI CQ
committed
preload: Replace ruleset url with ruleset tags if tag is present
Before changes: https://drive.google.com/file/d/1NrrEedeW6eUdY_pQZGgpFi_47Z3FgvTl/view?usp=sharing (dropdown) https://drive.google.com/file/d/1XeIE6wboWZ2XMhODL0o7XXbI1uBLME6T/view?usp=sharing https://drive.google.com/file/d/19QDG_9mt2PnGsdaXz7TE7jt2CFout9aK/view?usp=sharing Updated tab: https://drive.google.com/file/d/1zPPP7YM6Do2jcF8M3af8LscHO0jK7BhH/view?usp=sharing (dropdown) https://drive.google.com/file/d/1z8vnJkPHYzfi4OGltNbDKwIGvlMBksyp/view?usp=sharing https://drive.google.com/file/d/1t0mK1rIp18gwCu-ndsQ4qSDOG7lYNas6/view?usp=sharing Test site: https://prerender2-eventtesting.glitch.me/ Bug: 393408589 Change-Id: Id6e18ba6c9ad70215f348b177ff1b3bd1f5fa54c Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6427702 Reviewed-by: Domenic Denicola <domenic@chromium.org> Reviewed-by: Ken Okada <kenoss@chromium.org> Commit-Queue: Huanpo Lin <robertlin@chromium.org> Reviewed-by: Danil Somsikov <dsv@chromium.org>
1 parent 6399184 commit a13e0a6

File tree

6 files changed

+94
-3
lines changed

6 files changed

+94
-3
lines changed

front_end/panels/application/preloading/PreloadingView.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,12 @@ class PreloadingRuleSetSelector implements
677677
if (ruleSet === null) {
678678
return i18n.i18n.lockedString('Internal error');
679679
}
680+
681+
// TODO(https://crbug.com/393408589): Use `PreloadingString.ruleSetTagOrLocationShort` to reduce code redundancy.
682+
const sourceJson = JSON.parse(ruleSet['sourceText']);
683+
if ('tag' in sourceJson) {
684+
return '"' + sourceJson['tag'] + '"';
685+
}
680686
return PreloadingUIUtils.ruleSetLocationShort(ruleSet, pageURL());
681687
}
682688

front_end/panels/application/preloading/components/PreloadingGrid.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,50 @@ describeWithEnvironment('PreloadingGrid', () => {
7878
);
7979
});
8080

81+
it('renders tag instead of url correctly', async () => {
82+
await assertRenderResult(
83+
{
84+
rows: [{
85+
id: 'id',
86+
pipeline: SDK.PreloadingModel.PreloadPipeline.newFromAttemptsForTesting([{
87+
action: Protocol.Preload.SpeculationAction.Prefetch,
88+
key: {
89+
loaderId: 'loaderId:1' as Protocol.Network.LoaderId,
90+
action: Protocol.Preload.SpeculationAction.Prefetch,
91+
url: urlString`https://example.com/prefetched.html`,
92+
},
93+
pipelineId: 'pipelineId:1' as Protocol.Preload.PreloadPipelineId,
94+
status: SDK.PreloadingModel.PreloadingStatus.RUNNING,
95+
prefetchStatus: null,
96+
requestId: 'requestId:1' as Protocol.Network.RequestId,
97+
ruleSetIds: ['ruleSetId:0.1'] as Protocol.Preload.RuleSetId[],
98+
nodeIds: [1] as Protocol.DOM.BackendNodeId[],
99+
}]),
100+
ruleSets: [{
101+
id: 'ruleSetId:0.1' as Protocol.Preload.RuleSetId,
102+
loaderId: 'loaderId:1' as Protocol.Network.LoaderId,
103+
sourceText: `
104+
{
105+
"tag": "tag1",
106+
"prefetch":[
107+
{
108+
"source": "list",
109+
"urls": ["/prefetched.html"]
110+
}
111+
]
112+
}
113+
`,
114+
}],
115+
}],
116+
pageURL: urlString`https://example.com/`,
117+
},
118+
['URL', 'Action', 'Rule set', 'Status'],
119+
[
120+
['/prefetched.html', 'Prefetch', '\"tag1"', 'Running'],
121+
],
122+
);
123+
});
124+
81125
it('shows full URL for cross-origin preloading', async () => {
82126
await assertRenderResult(
83127
{

front_end/panels/application/preloading/components/PreloadingGrid.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type * as UI from '../../../../ui/legacy/legacy.js';
1616
import * as Lit from '../../../../ui/lit/lit.js';
1717

1818
import preloadingGridStyles from './preloadingGrid.css.js';
19-
import {capitalizedAction, composedStatus, ruleSetLocationShort} from './PreloadingString.js';
19+
import {capitalizedAction, composedStatus, ruleSetTagOrLocationShort} from './PreloadingString.js';
2020

2121
const {PreloadingStatus} = SDK.PreloadingModel;
2222

@@ -100,7 +100,7 @@ export class PreloadingGrid extends LegacyWrapper.LegacyWrapper.WrappableCompone
100100
return html`<tr data-id=${row.id}>
101101
<td title=${attempt.key.url}>${this.#urlShort(row, securityOrigin)}</td>
102102
<td>${capitalizedAction(attempt.action)}</td>
103-
<td>${row.ruleSets.length === 0 ? '' : ruleSetLocationShort(row.ruleSets[0], pageURL)}</td>
103+
<td>${row.ruleSets.length === 0 ? '' : ruleSetTagOrLocationShort(row.ruleSets[0], pageURL)}</td>
104104
<td>
105105
<div style=${styleMap({color: hasWarning ? 'var(--sys-color-orange-bright)'
106106
: hasError ? 'var(--sys-color-error)'

front_end/panels/application/preloading/components/PreloadingString.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,17 @@ export function ruleSetLocationShort(
728728
return Bindings.ResourceUtils.displayNameForURL(url);
729729
}
730730

731+
export function ruleSetTagOrLocationShort(
732+
ruleSet: Protocol.Preload.RuleSet, pageURL: Platform.DevToolsPath.UrlString): string {
733+
if (!ruleSet.errorMessage) {
734+
const parsedRuleset = JSON.parse(ruleSet['sourceText']);
735+
if ('tag' in parsedRuleset) {
736+
return '"' + parsedRuleset['tag'] + '"';
737+
}
738+
}
739+
return ruleSetLocationShort(ruleSet, pageURL);
740+
}
741+
731742
export function capitalizedAction(action: Protocol.Preload.SpeculationAction): Common.UIString.LocalizedString {
732743
// Use "prefetch"/"prerender" as is in SpeculationRules.
733744
switch (action) {

front_end/panels/application/preloading/components/RuleSetGrid.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,36 @@ describeWithEnvironment('RuleSetGrid', () => {
6161
);
6262
});
6363

64+
it('renders tag instead of url correctly', async () => {
65+
await assertRenderResult(
66+
{
67+
rows: [{
68+
ruleSet: {
69+
id: 'ruleSetId:0.1' as Protocol.Preload.RuleSetId,
70+
loaderId: 'loaderId:1' as Protocol.Network.LoaderId,
71+
sourceText: `
72+
{
73+
"tag": "tag1",
74+
"prefetch":[
75+
{
76+
"source": "list",
77+
"urls": ["/prefetched.html"]
78+
}
79+
]
80+
}
81+
`,
82+
},
83+
preloadsStatusSummary: '1 Not triggered, 2 Ready, 3 Failure',
84+
}],
85+
pageURL: urlString`https://example.com/`,
86+
},
87+
['Rule set', 'Status'],
88+
[
89+
['\"tag1\"', '1 Not triggered, 2 Ready, 3 Failure'],
90+
],
91+
);
92+
});
93+
6494
it('shows short url for out-of-document speculation rules', async () => {
6595
await assertRenderResult(
6696
{

front_end/panels/application/preloading/components/RuleSetGrid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class RuleSetGrid extends LegacyWrapper.LegacyWrapper.WrappableComponent<
139139
</th>
140140
</tr>
141141
${rows.map(({ruleSet, preloadsStatusSummary}) => {
142-
const location = PreloadingString.ruleSetLocationShort(ruleSet, pageURL);
142+
const location = PreloadingString.ruleSetTagOrLocationShort(ruleSet, pageURL);
143143
const revealInElements = ruleSet.backendNodeId !== undefined;
144144
const revealInNetwork = ruleSet.url !== undefined && ruleSet.requestId;
145145
return html`

0 commit comments

Comments
 (0)