• 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('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
17  return {};
18});
19
20import {
21  FrameDynamicRender,
22  FrameDynamicStruct,
23} from '../../../../src/trace/database/ui-worker/ProcedureWorkerFrameDynamic';
24import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect';
25import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow';
26import { AnimationRanges } from '../../../../src/trace/bean/FrameComponentBean';
27jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
28  return {};
29});
30describe('FrameDynamic Test', () => {
31  let frameDynamicRender = new FrameDynamicRender();
32  let rect = new Rect(341, 2, 10, 10);
33  let canvas = document.createElement('canvas');
34  canvas.width = 1;
35  canvas.height = 1;
36  let ctx = canvas.getContext('2d');
37  TraceRow.range = {
38    startNS: 0,
39    endNS: 16868000000,
40    totalNS: 16868000000,
41  };
42  let dataList = [
43    {
44      alpha: '0.00',
45      appName: 'test',
46      groupId: 4091445480,
47      height: 0,
48      id: 455,
49      ts: 4091445480,
50      width: 0,
51      x: 0,
52      y: 0,
53    },
54    {
55      alpha: '70.00',
56      appName: 'test',
57      groupId: 6970503809,
58      height: 0,
59      id: 456,
60      ts: 6970503809,
61      width: 0,
62      x: 0,
63      y: 0,
64    },
65    {
66      alpha: '13.00',
67      appName: 'test1',
68      frame: rect,
69      groupId: 32238,
70      height: 2766,
71      id: 717,
72      ts: 611455,
73      typeValue: 0,
74      width: 11223,
75      x: 0,
76      y: 1,
77    },
78  ];
79  let req = {
80    useCache: false,
81    context: ctx,
82    type: 'dynamicEffectCurve',
83    animationRanges: [{ start: 4091445476, end: 4774481414 }],
84  };
85  TraceRow.range = {
86    startNS: 0,
87    endNS: 16868000000,
88    totalNS: 16868000000,
89  };
90
91  let animationRanges = [{ start: 4091445476, end: 4774481414 }];
92  frameDynamicRender.frameDynamic(dataList, [], TraceRow.skeleton(), animationRanges, false);
93
94  it('FrameDynamicTest01', function () {
95    let [min, max] = frameDynamicRender.getMinAndMaxData(dataList, 'x');
96    expect([min, max]).toEqual([0, 1]);
97  });
98  it('FrameDynamicTest02', function () {
99    let currDynamic = {
100      alpha: '16.00',
101      appName: 'test2',
102      frame: rect,
103      groupId: 19312108,
104      height: 206,
105      id: 9654,
106      ts: 10242454,
107      typeValue: 10,
108      width: 1233,
109      x: 10,
110      y: 1,
111    };
112    frameDynamicRender.drawDynamicPointYStr(ctx, dataList, rect, 0, 20);
113    expect(frameDynamicRender.drawSinglePoint(ctx, currDynamic, TraceRow.skeleton(), 'x', 0, 20)).toBeUndefined();
114  });
115
116  it('FrameDynamicTest03', function () {
117    let row = TraceRow.skeleton();
118    row.dataList = dataList;
119    row.dataListCache = dataList;
120    frameDynamicRender.renderMainThread(req, row);
121    let currDynamicStruct = {
122      alpha: '11.00',
123      appName: 'test4',
124      frame: rect,
125      groupId: 2011538,
126      height: 2766,
127      id: 717,
128      ts: 12100454,
129      typeValue: 0,
130      width: 321,
131      x: 10,
132      y: 11,
133    };
134
135    let preDynamicStruct = {
136      alpha: '0.00',
137      appName: 'test',
138      frame: rect,
139      groupId: -1,
140      height: 0,
141      id: 456,
142      ts: 6970503809,
143      width: 0,
144      x: 0,
145      y: 0,
146    };
147    FrameDynamicStruct.draw(ctx, preDynamicStruct, currDynamicStruct, TraceRow.skeleton(), 'x');
148    FrameDynamicStruct.drawSelect(ctx, currDynamicStruct, TraceRow.skeleton());
149    expect(FrameDynamicStruct.drawSelectOrHoverArc(ctx, currDynamicStruct)).toBeUndefined();
150  });
151});
152