Skip to content

Commit 8460a24

Browse files
and-oliDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Add annotations again after toggling custom track setting
Bug: 402298436 Change-Id: I997ae0605e0f7f5ca0e7f17990256ac0371462ce Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6361636 Reviewed-by: Jack Franklin <[email protected]> Commit-Queue: Andres Olivares <[email protected]>
1 parent 3067d40 commit 8460a24

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

front_end/panels/timeline/ModificationsManager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ export class ModificationsManager extends EventTarget {
307307
return [...this.#overlayForAnnotation.values()];
308308
}
309309

310+
applyAnnotationsFromCache(): void {
311+
this.#modifications = this.toJSON();
312+
// The cache is filled by applyModificationsIfPresent, so we clear
313+
// it beforehand to prevent duplicate entries.
314+
this.#overlayForAnnotation.clear();
315+
this.#applyStoredAnnotations(this.#modifications.annotations);
316+
}
317+
310318
/**
311319
* Builds all modifications into a serializable object written into
312320
* the 'modifications' trace file metadata field.

front_end/panels/timeline/TimelineFlameChartView.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ export class TimelineFlameChartView extends Common.ObjectWrapper.eventMixin<Even
11781178
this.resizeToPreferredHeights();
11791179
this.setMarkers(this.#parsedTrace);
11801180
this.dimThirdPartiesIfRequired();
1181+
ModificationsManager.activeManager()?.applyAnnotationsFromCache();
11811182
}
11821183

11831184
setInsights(

front_end/panels/timeline/TimelinePanel.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describeWithEnvironment('TimelinePanel', function() {
9797
const tracksAfterEnablingSetting = timeline.getFlameChart().getMainDataProvider().timelineData().groups;
9898
assert.deepEqual(tracksBeforeDisablingSetting, tracksAfterEnablingSetting);
9999
});
100-
it('should keep overlays when the custom tracks setting is toggled', async function() {
100+
it('should keep marker overlays when the custom tracks setting is toggled', async function() {
101101
const events = await TraceLoader.rawEvents(this, 'web-dev.json.gz') as Trace.Types.Events.Event[];
102102
await timeline.loadingComplete(events, null, null);
103103
const overlaysBeforeDisablingSetting = timeline.getFlameChart().overlays().allOverlays();
@@ -137,4 +137,33 @@ describeWithEnvironment('TimelinePanel', function() {
137137
assert.exists(dimIndicesAfterToggle);
138138
assert.isAbove(dimIndicesAfterToggle.length, 0);
139139
});
140+
141+
it('keeps annotations after toggling the custom tracks setting', async function() {
142+
const events = await TraceLoader.rawEvents(this, 'web-dev.json.gz') as Trace.Types.Events.Event[];
143+
await timeline.loadingComplete(events, null, null);
144+
const parsedTrace = traceModel.parsedTrace();
145+
assert.isOk(parsedTrace?.Meta.traceBounds.min);
146+
const modificationsManager = Timeline.ModificationsManager.ModificationsManager.activeManager();
147+
assert.isOk(modificationsManager);
148+
149+
// Add an annotation
150+
modificationsManager.createAnnotation({
151+
bounds: Trace.Helpers.Timing.traceWindowFromMicroSeconds(
152+
parsedTrace.Meta.traceBounds.min, parsedTrace.Meta.traceBounds.max),
153+
type: 'TIME_RANGE',
154+
label: '',
155+
});
156+
157+
const annotationsBeforeToggle =
158+
timeline.getFlameChart().overlays().allOverlays().filter(e => e.type === 'TIME_RANGE');
159+
assert.exists(annotationsBeforeToggle);
160+
assert.isAbove(annotationsBeforeToggle.length, 0);
161+
162+
// Toggle the custom track setting and verify annotations remain.
163+
Timeline.TimelinePanel.TimelinePanel.extensionDataVisibilitySetting().set(true);
164+
const annotationsAfterToggle =
165+
timeline.getFlameChart().overlays().allOverlays().filter(e => e.type === 'TIME_RANGE');
166+
assert.exists(annotationsAfterToggle);
167+
assert.isAbove(annotationsAfterToggle.length, 0);
168+
});
140169
});
Binary file not shown.

0 commit comments

Comments
 (0)