[go: nahoru, domu]

blob: 322d3dafc92c718f5da8fc9fd4526129f2930429 [file] [log] [blame]
Jack Franklin45522ff2023-06-01 13:19:511// Copyright 2023 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import * as Timeline from '../../../../../front_end/panels/timeline/timeline.js';
6import type * as TimelineModel from '../../../../../front_end/models/timeline_model/timeline_model.js';
7import type * as SDK from '../../../../../front_end/core/sdk/sdk.js';
8
9async function loadWebDevTraceAsFile(): Promise<File> {
10 const file = new URL('../../../fixtures/traces/web-dev.json.gz', import.meta.url);
11 const response = await fetch(file);
12 const asBlob = await response.blob();
13 const asFile = new File([asBlob], 'web-dev.json.gz', {
14 type: 'application/gzip',
15 });
16 return asFile;
17}
18
19describe('TimelineLoader', () => {
20 it('can load a saved file', async () => {
21 const file = await loadWebDevTraceAsFile();
22
23 const loadingStartedSpy = sinon.spy();
24 const loadingProgressSpy = sinon.spy();
25 const processingStartedSpy = sinon.spy();
26 const loadingCompleteSpy = sinon.spy();
27
28 const client: Timeline.TimelineLoader.Client = {
29 async loadingStarted() {
30 loadingStartedSpy();
31 },
32 async loadingProgress(progress?: number) {
33 loadingProgressSpy(progress);
34 },
35 async processingStarted() {
36 processingStartedSpy();
37 },
38 async loadingComplete(
39 tracingModel: SDK.TracingModel.TracingModel|null,
40 exclusiveFilter: TimelineModel.TimelineModelFilter.TimelineModelFilter|null,
41 ) {
42 loadingCompleteSpy(tracingModel, exclusiveFilter);
43 },
44 };
45 await Timeline.TimelineLoader.TimelineLoader.loadFromFile(file, client);
46
47 assert.isTrue(loadingStartedSpy.calledOnce);
48 // Exact number is deterministic so we can assert, but the fact it was 28
49 // calls doesn't really matter. We just want to check it got called "a
50 // bunch of times".
51 assert.strictEqual(loadingProgressSpy.callCount, 28);
52 assert.isTrue(processingStartedSpy.calledOnce);
53 assert.isTrue(loadingCompleteSpy.calledOnce);
54
55 // Get the arguments of the first (and only) call to the loadingComplete
56 // function. TS doesn't know what the types are (they are [any, any] by
57 // default), so we tell it that they align with the types of the
58 // loadingComplete parameters.
59 const [tracingModel, exclusiveFilter] =
60 loadingCompleteSpy.args[0] as Parameters<Timeline.TimelineLoader.Client['loadingComplete']>;
61 assert.isNull(exclusiveFilter); // We are not filtering out any events for this trace.
62 if (!tracingModel) {
63 throw new Error('No tracing model found from results of loadTraceFromFile');
64 }
65 // Ensure that we loaded something that looks about right!
66 assert.lengthOf(tracingModel.allRawEvents(), 8252);
67 });
68});