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