|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
5 | 5 | import * as SDK from '../../core/sdk/sdk.js';
|
| 6 | +import * as LiveMetrics from '../../models/live-metrics/live-metrics.js'; |
6 | 7 | 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'; |
9 | 15 |
|
10 | 16 | import * as Timeline from './timeline.js';
|
11 | 17 |
|
12 |
| -describeWithRealConnection('TimelineController', () => { |
| 18 | +describeWithMockConnection('TimelineController', () => { |
13 | 19 | it('calls the callback methods on the client in the expected order', async function() {
|
14 | 20 | // The test needs at least 0.5s to have progress events be sent. Set a higher timeout to avoid flakiness.
|
15 | 21 | if (this.timeout() !== 0) {
|
@@ -43,42 +49,50 @@ describeWithRealConnection('TimelineController', () => {
|
43 | 49 | loadingCompleteForTest() {},
|
44 | 50 | };
|
45 | 51 |
|
46 |
| - const primaryPage = SDK.TargetManager.TargetManager.instance().primaryPageTarget(); |
| 52 | + LiveMetrics.LiveMetrics.instance({forceNew: true}); |
| 53 | + |
| 54 | + const primaryPage = createTarget(); |
47 | 55 | if (!primaryPage) {
|
48 | 56 | throw new Error('Could not find primary page');
|
49 | 57 | }
|
50 |
| - const root = SDK.TargetManager.TargetManager.instance().rootTarget(); |
51 |
| - if (!root) { |
| 58 | + const rootTarget = SDK.TargetManager.TargetManager.instance().rootTarget(); |
| 59 | + if (!rootTarget) { |
52 | 60 | throw new Error('Could not find root target');
|
53 | 61 | }
|
54 | 62 |
|
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 | + }); |
68 | 85 | 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}); |
72 | 88 | await controller.stopRecording();
|
73 | 89 | 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); |
77 | 91 | sinon.assert.callCount(stubs.loadingStarted, 1);
|
78 |
| - assert.isAtLeast(stubs.loadingProgress.callCount, 1); |
| 92 | + sinon.assert.callCount(stubs.loadingProgress, 1); |
79 | 93 | sinon.assert.callCount(stubs.loadingComplete, 1);
|
80 | 94 | const [collectedEvents] = stubs.loadingComplete.getCall(0).args as [Trace.Types.Events.Event[]];
|
81 | 95 | // Ensure we collected events during tracing.
|
82 |
| - assert.isTrue(collectedEvents.length > 0); |
| 96 | + assert.lengthOf(collectedEvents, 1); |
83 | 97 | });
|
84 | 98 | });
|
0 commit comments