• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16jest.mock('../../../../dist/trace/database/ui-worker/ProcedureWorker.js', () => {
17  return {};
18});
19
20// @ts-ignore
21import { TraceRow } from '../../../../dist/trace/component/trace/base/TraceRow.js';
22// @ts-ignore
23import {
24  FrameSpacingRender,
25  FrameSpacingStruct,
26} from '../../../../dist/trace/database/ui-worker/ProcedureWorkerFrameSpacing.js';
27// @ts-ignore
28import { Rect } from '../../../../dist/trace/component/trace/timer-shaft/Rect.js';
29
30describe('FrameSpacing Test', () => {
31  let frameSpacingRender = new FrameSpacingRender();
32  let canvas = document.createElement('canvas');
33  canvas.width = 1;
34  canvas.height = 1;
35  let ctx = canvas.getContext('2d');
36  let req = {
37    animationRanges: [{ start: 4091445476, end: 4774481414 }],
38    context: ctx,
39    frameRate: 90,
40    type: 'frame_spacing_slice',
41    useCache: false,
42  };
43  TraceRow.range = {
44    startNS: 0,
45    endNS: 16868000000,
46    totalNS: 16868000000,
47  };
48  let dataList = [
49    {
50      currentFrameHeight: 2753,
51      currentFrameWidth: 1339,
52      currentTs: 11618846517,
53      frame: new Rect(),
54      frameSpacingResult: 0.2,
55      groupId: 0,
56      id: 709,
57      nameId: 'test',
58      preFrameHeight: 2750,
59      preFrameWidth: 1338,
60      preTs: 11629160500,
61      x: 0,
62      y: 4,
63    },
64    {
65      currentFrameHeight: 2753,
66      currentFrameWidth: 1339,
67      currentTs: 11629160579,
68      frame: new Rect(),
69      frameSpacingResult: 0.1,
70      groupId: 11095334538,
71      id: 709,
72      nameId: 'test',
73      preFrameHeight: 2750,
74      preFrameWidth: 1338,
75      preTs: 11618846517,
76      x: 0,
77      y: 4,
78    },
79    {
80      currentFrameHeight: 2755,
81      currentFrameWidth: 1340,
82      currentTs: 11640114746,
83      frame: new Rect(),
84      frameSpacingResult: 0.1,
85      groupId: 11095334538,
86      id: 710,
87      nameId: 'test',
88      preFrameHeight: 2753,
89      preFrameWidth: 1339,
90      preTs: 11629160579,
91      x: 0,
92      y: 4,
93    },
94  ];
95  it('FrameSpacingTest01', function () {
96    expect(frameSpacingRender.render(req, dataList, TraceRow.skeleton())).toBeUndefined();
97  });
98
99  it('FrameSpacingTest02', function () {
100    frameSpacingRender.frameSpacing(
101      dataList,
102      [],
103      TraceRow.range.startNS,
104      TraceRow.range.endNS,
105      TraceRow.range.totalNS,
106      TraceRow.skeleton(),
107      req.animationRanges,
108      false
109    );
110    expect(frameSpacingRender).not.toBeUndefined();
111  });
112
113  it('FrameSpacingTest03', function () {
114    let currentStruct = {
115      currentFrameHeight: 2755,
116      currentFrameWidth: 1340,
117      currentTs: 11640114746,
118      frame: new Rect(),
119      frameSpacingResult: 0.1,
120      groupId: 11095334538,
121      id: 710,
122      nameId: 'test',
123      preFrameHeight: 2753,
124      preFrameWidth: 1339,
125      preTs: 11629160579,
126      x: 0,
127      y: 4,
128    };
129    expect(frameSpacingRender.drawPoint(ctx, currentStruct, TraceRow.skeleton(), 0, 20)).toBeUndefined();
130  });
131});
132