• 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 */
15import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow';
16import { func, FuncStruct, FuncRender } from '../../../../src/trace/database/ui-worker/ProcedureWorkerFunc';
17import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect';
18
19
20jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
21  return {};
22});
23jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
24  return {};
25});
26describe(' ProcedureWorkerFuncTest', () => {
27  it('FuncTest01', () => {
28    let funcDataList = new Array();
29    funcDataList.push({
30      startTime: 10,
31      dur: 410,
32      frame: {x: 0, y: 9, width: 10, height: 10},
33    });
34    funcDataList.push({startTime: 17, dur: 141});
35    let rect = new Rect(0, 30, 30, 30);
36    let res = [
37      {
38        startTs: 31,
39        dur: 140,
40        length: 16,
41        frame: '',
42      },
43    ];
44    func(funcDataList, res, 1, 100254, 100254, rect, true, false);
45  });
46
47  it('FuncTest02', () => {
48    let funcDataList = new Array();
49    funcDataList.push({
50      startTime: 450,
51      dur: 140,
52      frame: {x: 0, y: 93, width: 120, height: 320},
53    });
54    funcDataList.push({
55      startTime: 41,
56      dur: 661,
57      frame: {x: 70, y: 9, width: 16, height: 17},
58    });
59    let rect = new Rect(30, 50, 53, 13);
60    let res = [
61      {
62        startTs: 10,
63        dur: 10,
64        length: 60,
65        frame: '',
66      },
67    ];
68    func(funcDataList, res, 1, 100254, 100254, rect, false, false);
69  });
70
71  it('FuncTest03', () => {
72    const canvas = document.createElement('canvas');
73    canvas.width = 9;
74    canvas.height = 9;
75    const ctx = canvas.getContext('2d');
76
77    const data = {
78      frame: {
79        x: 209,
80        y: 209,
81        width: 100,
82        height: 100,
83      },
84      startNS: 200,
85      value: 50,
86      dur: undefined || null || 0,
87      funName: '',
88    };
89    const flagConfig = {
90        TaskPool: 'Enabled',
91    }
92    expect(FuncStruct.draw(ctx, data, flagConfig)).toBeUndefined();
93  });
94
95  it('FuncTest04', () => {
96    let funcRender = new FuncRender();
97    const canvas = document.createElement('canvas');
98    canvas.width = 1;
99    canvas.height = 1;
100    const ctx = canvas.getContext('2d');
101
102    const data = {
103      frame: {
104        x: 240,
105        y: 240,
106        width: 100,
107        height: 100,
108      },
109      context: {
110        font: '12px sans-serif',
111        fillStyle: '#a1697d',
112        globalAlpha: 0.6,
113        measureText: jest.fn(() => true),
114        clearRect: jest.fn(() => true),
115        stroke: jest.fn(() => true),
116        closePath: jest.fn(() => false),
117        beginPath: jest.fn(() => true),
118        fillRect: jest.fn(() => false),
119        fillText: jest.fn(() => true),
120      },
121      startNS: 200,
122      value: 50,
123      dur: 10,
124      funName: 'H:Task PerformTask End: taskId : 1, executeId : 1, performResult : IsCanceled',
125    };
126    const flagConfig = {
127        TaskPool: 'Enabled',
128    }
129    TraceRow.range = jest.fn(() => true);
130    TraceRow.range.startNS = jest.fn(() => 1);
131    expect(FuncStruct.draw(ctx, data, flagConfig)).toBeUndefined();
132    expect(funcRender.renderMainThread(data, new TraceRow<FuncStruct>())).toBeUndefined();
133    expect(funcRender.render(data, [], [])).toBeUndefined();
134  });
135
136  it('FuncTest07', function () {
137    let str = '';
138    expect(FuncStruct.isBinder({})).toBe(false);
139  });
140
141  it('FuncTest08', function () {
142    let data = {
143      startTs: 2,
144      depth: 1,
145    };
146    expect(FuncStruct.isSelected(data)).toBe(false);
147  });
148
149  it('FuncTest09', function () {
150    let funcRender = new FuncRender();
151    let req = {
152      lazyRefresh: undefined,
153      type: '',
154      startNS: 31,
155      endNS: 71,
156      totalNS: 40,
157      frame: {
158        x: 30,
159        y: 22,
160        width: 550,
161        height: 150,
162      },
163      useCache: false,
164      range: {
165        refresh: '',
166      },
167      canvas: '',
168      context: {
169        font: '11px sans-serif',
170        fillStyle: '#30a16f',
171        globalAlpha: 0.556,
172        height: 177,
173        width: 150,
174      },
175      lineColor: '#014d5f',
176      isHover: '',
177      hoverX: 21,
178      wakeupBean: undefined,
179      flagMoveInfo: '',
180      flagSelectedInfo: '',
181      slicesTime: 53,
182      id: 64,
183      x: 760,
184      y: 67,
185      width: 106,
186      height: 170,
187      params: {
188        isLive: false,
189        maxHeight: 222,
190        dpr: 431,
191        hoverFuncStruct: '',
192        selectFuncStruct: undefined,
193      },
194    };
195    window.postMessage = jest.fn(() => true);
196    expect(funcRender.render(req, [], [])).toBeUndefined();
197  });
198});
199