Skip to content

Commit c01afb7

Browse files
jackfranklinDevtools-frontend LUCI CQ
authored andcommitted
RPP: add test for details view showing a frame
I want to start refactoring some of the `TimelineSelection` logic, but realised we are missing tests for a few places where it is used. This CL adds a test to ensure screenshots are shown when the user selects a frame, and moves the rendering logic into a standalone function to make it a bit easier to read. Bug: 370716587 Change-Id: Iedb0de633884ddc2b0b2c0a74c9a98c6de315870 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5946889 Auto-Submit: Jack Franklin <[email protected]> Commit-Queue: Andres Olivares <[email protected]> Reviewed-by: Andres Olivares <[email protected]>
1 parent 1990c0a commit c01afb7

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

front_end/panels/timeline/TimelineDetailsView.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import type * as Trace from '../../models/trace/trace.js';
6+
import {doubleRaf} from '../../testing/DOMHelpers.js';
67
import {describeWithEnvironment} from '../../testing/EnvironmentHelpers.js';
78
import {TraceLoader} from '../../testing/TraceLoader.js';
89

@@ -41,4 +42,25 @@ describeWithEnvironment('TimelineDetailsView', function() {
4142
// NetworkRequestDetails and RelatedInsightsChips nodes.
4243
assert.strictEqual(detailsContentElement.childNodes.length, 2);
4344
});
45+
46+
it('displays the details for a frame correctly', async function() {
47+
const {parsedTrace} = await TraceLoader.traceEngine(this, 'web-dev-with-commit.json.gz');
48+
const detailsView = new Timeline.TimelineDetailsView.TimelineDetailsView(mockViewDelegate);
49+
await detailsView.setModel(
50+
{parsedTrace, selectedEvents: null, traceInsightsSets: null, eventToRelatedInsightsMap: null});
51+
52+
const frame = parsedTrace.Frames.frames.at(0);
53+
assert.isOk(frame);
54+
const selection = Timeline.TimelineSelection.TimelineSelection.fromFrame(frame);
55+
await detailsView.setSelection(selection);
56+
await doubleRaf(); // to let the image be fetched + rendered.
57+
const detailsContentElement = detailsView.getDetailsContentElementForTest();
58+
const frameImg = detailsContentElement.querySelector('.timeline-filmstrip-preview img');
59+
assert.instanceOf(frameImg, HTMLImageElement);
60+
assert.isDefined(frameImg.src);
61+
62+
const duration = detailsContentElement.querySelector<HTMLElement>('[data-row-title="Duration"]');
63+
assert.isOk(duration);
64+
assert.strictEqual(duration.innerText, 'Duration37.85 ms (at 109.82 ms)');
65+
});
4466
});

front_end/panels/timeline/TimelineDetailsView.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,19 @@ export class TimelineDetailsView extends UI.Widget.VBox {
290290
return frameTimeMilliSeconds - frame.endTime < 10 ? filmStripFrame : null;
291291
}
292292

293+
#setSelectionForTimelineFrame(frame: Trace.Types.Events.LegacyTimelineFrame): void {
294+
const matchedFilmStripFrame = this.#getFilmStripFrame(frame);
295+
this.setContent(TimelineUIUtils.generateDetailsContentForFrame(frame, this.#filmStrip, matchedFilmStripFrame));
296+
const target = SDK.TargetManager.TargetManager.instance().rootTarget();
297+
if (frame.layerTree && target) {
298+
const layerTreeForFrame = new TimelineModel.TracingLayerTree.TracingFrameLayerTree(target, frame.layerTree);
299+
const layersView = this.layersView();
300+
layersView.showLayerTree(layerTreeForFrame);
301+
if (!this.tabbedPane.hasTab(Tab.LayerViewer)) {
302+
this.appendTab(Tab.LayerViewer, i18nString(UIStrings.layers), layersView);
303+
}
304+
}
305+
}
293306
async setSelection(selection: TimelineSelection|null): Promise<void> {
294307
if (!this.#parsedTrace) {
295308
// You can't make a selection if we have no trace data.
@@ -333,18 +346,7 @@ export class TimelineDetailsView extends UI.Widget.VBox {
333346
this.appendDetailsTabsForTraceEventAndShowDetails(event, traceEventDetails);
334347
}
335348
} else if (TimelineSelection.isLegacyTimelineFrame(selectionObject)) {
336-
const frame = selectionObject;
337-
const matchedFilmStripFrame = this.#getFilmStripFrame(frame);
338-
this.setContent(TimelineUIUtils.generateDetailsContentForFrame(frame, this.#filmStrip, matchedFilmStripFrame));
339-
const target = SDK.TargetManager.TargetManager.instance().rootTarget();
340-
if (frame.layerTree && target) {
341-
const layerTreeForFrame = new TimelineModel.TracingLayerTree.TracingFrameLayerTree(target, frame.layerTree);
342-
const layersView = this.layersView();
343-
layersView.showLayerTree(layerTreeForFrame);
344-
if (!this.tabbedPane.hasTab(Tab.LayerViewer)) {
345-
this.appendTab(Tab.LayerViewer, i18nString(UIStrings.layers), layersView);
346-
}
347-
}
349+
this.#setSelectionForTimelineFrame(selectionObject);
348350
} else if (TimelineSelection.isRangeSelection(selectionObject)) {
349351
this.updateSelectedRangeStats(this.selection.startTime, this.selection.endTime);
350352
}

0 commit comments

Comments
 (0)