Skip to content

Commit 0987a35

Browse files
pfaffeDevtools-frontend LUCI CQ
authored andcommitted
Migrate TimelineController test off of real connection
Bug: 357805727 Change-Id: Icfff64ecb314242bf4165364deb58fbcfbd72cde Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6555867 Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Philip Pfaffe <pfaffe@chromium.org>
1 parent 9901bf0 commit 0987a35

File tree

1 file changed

+41
-27
lines changed

1 file changed

+41
-27
lines changed

front_end/panels/timeline/TimelineController.test.ts

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
// found in the LICENSE file.
44

55
import * as SDK from '../../core/sdk/sdk.js';
6+
import * as LiveMetrics from '../../models/live-metrics/live-metrics.js';
67
import type * as Trace from '../../models/trace/trace.js';
7-
import {renderElementIntoDOM} from '../../testing/DOMHelpers.js';
8-
import {describeWithRealConnection} from '../../testing/RealConnection.js';
8+
import {createTarget} from '../../testing/EnvironmentHelpers.js';
9+
import {
10+
describeWithMockConnection,
11+
dispatchEvent,
12+
setMockConnectionResponseHandler
13+
} from '../../testing/MockConnection.js';
14+
import {defaultTraceEvent} from '../../testing/TraceHelpers.js';
915

1016
import * as Timeline from './timeline.js';
1117

12-
describeWithRealConnection('TimelineController', () => {
18+
describeWithMockConnection('TimelineController', () => {
1319
it('calls the callback methods on the client in the expected order', async function() {
1420
// The test needs at least 0.5s to have progress events be sent. Set a higher timeout to avoid flakiness.
1521
if (this.timeout() !== 0) {
@@ -43,42 +49,50 @@ describeWithRealConnection('TimelineController', () => {
4349
loadingCompleteForTest() {},
4450
};
4551

46-
const primaryPage = SDK.TargetManager.TargetManager.instance().primaryPageTarget();
52+
LiveMetrics.LiveMetrics.instance({forceNew: true});
53+
54+
const primaryPage = createTarget();
4755
if (!primaryPage) {
4856
throw new Error('Could not find primary page');
4957
}
50-
const root = SDK.TargetManager.TargetManager.instance().rootTarget();
51-
if (!root) {
58+
const rootTarget = SDK.TargetManager.TargetManager.instance().rootTarget();
59+
if (!rootTarget) {
5260
throw new Error('Could not find root target');
5361
}
5462

55-
const controller = new Timeline.TimelineController.TimelineController(root, primaryPage, client);
56-
57-
class TestTracingComponent extends HTMLElement {
58-
connectedCallback() {
59-
const newDiv = document.createElement('div');
60-
newDiv.innerHTML = 'testing';
61-
this.appendChild(newDiv);
62-
}
63-
}
64-
customElements.define('test-tracing-component', TestTracingComponent);
65-
const component = new TestTracingComponent();
66-
67-
// Start a recording and inject the test component to trigger some trace events.
63+
const controller = new Timeline.TimelineController.TimelineController(rootTarget, primaryPage, client);
64+
setMockConnectionResponseHandler('Target.setAutoAttach', () => ({}));
65+
setMockConnectionResponseHandler('DOM.enable', () => ({}));
66+
setMockConnectionResponseHandler('CSS.enable', () => ({}));
67+
setMockConnectionResponseHandler('Debugger.enable', () => ({}));
68+
setMockConnectionResponseHandler('Overlay.enable', () => ({}));
69+
setMockConnectionResponseHandler('Overlay.setShowViewportSizeOnResize', () => ({}));
70+
setMockConnectionResponseHandler('Animation.enable', () => ({}));
71+
setMockConnectionResponseHandler('DOM.disable', () => ({}));
72+
setMockConnectionResponseHandler('CSS.disable', () => ({}));
73+
setMockConnectionResponseHandler('Debugger.disable', () => ({}));
74+
setMockConnectionResponseHandler('Debugger.setAsyncCallStackDepth', () => ({}));
75+
setMockConnectionResponseHandler('Overlay.disable', () => ({}));
76+
setMockConnectionResponseHandler('Animation.disable', () => ({}));
77+
setMockConnectionResponseHandler('Tracing.start', () => ({}));
78+
setMockConnectionResponseHandler('Runtime.evaluate', () => ({}));
79+
setMockConnectionResponseHandler('Runtime.addBinding', () => ({}));
80+
setMockConnectionResponseHandler('Page.addScriptToEvaluateOnNewDocument', () => ({}));
81+
setMockConnectionResponseHandler('Tracing.end', () => {
82+
dispatchEvent(rootTarget, 'Tracing.tracingComplete', {dataLossOccurred: false});
83+
return {};
84+
});
6885
await controller.startRecording({});
69-
renderElementIntoDOM(component);
70-
// Run the test for at least 0.5s to have progress events be sent.
71-
await new Promise(resolve => setTimeout(resolve, 1500));
86+
dispatchEvent(rootTarget, 'Tracing.dataCollected', {value: [defaultTraceEvent]});
87+
dispatchEvent(rootTarget, 'Tracing.bufferUsage', {percentFull: .5});
7288
await controller.stopRecording();
7389
sinon.assert.callCount(stubs.processingStarted, 1);
74-
// Depending on the speed of the machine you might get more than 1 progress
75-
// call, hence we assert that there is at least one.
76-
assert.isAtLeast(stubs.recordingProgress.callCount, 1);
90+
sinon.assert.callCount(stubs.recordingProgress, 1);
7791
sinon.assert.callCount(stubs.loadingStarted, 1);
78-
assert.isAtLeast(stubs.loadingProgress.callCount, 1);
92+
sinon.assert.callCount(stubs.loadingProgress, 1);
7993
sinon.assert.callCount(stubs.loadingComplete, 1);
8094
const [collectedEvents] = stubs.loadingComplete.getCall(0).args as [Trace.Types.Events.Event[]];
8195
// Ensure we collected events during tracing.
82-
assert.isTrue(collectedEvents.length > 0);
96+
assert.lengthOf(collectedEvents, 1);
8397
});
8498
});

0 commit comments

Comments
 (0)