• 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
16import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow';
17
18jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
19  return {};
20});
21
22import { SdkCounterRender, CounterStruct } from '../../../../src/trace/database/ui-worker/ProduceWorkerSdkCounter';
23jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
24  return {};
25});
26describe('ProduceWorkerSdkCounter Test', () => {
27  it('ProduceWorkerSdkCounterTest01', function () {
28    let sdkCounterRender = new SdkCounterRender();
29    let List = [
30      {
31        length: 11,
32        ts: 9,
33        frame: {
34          x: 20,
35          y: 33,
36          width: 600,
37          height: 600,
38        },
39      },
40    ];
41    let arr = [
42      {
43        frame: null,
44        length: 1,
45      },
46    ];
47    let frame = {
48      x: 23,
49      y: 25,
50      width: 200,
51      height: 220,
52    };
53    expect(sdkCounterRender.counter(List, arr, 1, 1, 1, frame, true)).toBeUndefined();
54  });
55
56  it('ProduceWorkerSdkCounterTest02', function () {
57    let sdkCounterRender = new SdkCounterRender();
58    let List = [
59      {
60        length: 17,
61        ts: 41,
62        frame: {
63          x: 21,
64          y: 32,
65          width: 700,
66          height: 100,
67        },
68      },
69    ];
70    let arr = [
71      {
72        frame: null,
73        length: 0,
74      },
75    ];
76    let frame = {
77      x: 20,
78      y: 20,
79      width: 100,
80      height: 100,
81    };
82    expect(sdkCounterRender.counter(List, arr, 1, 1, 1, frame, false)).toBeUndefined();
83  });
84
85  it('ProduceWorkerSdkCounterTest03', () => {
86    const data = {
87      startNs: 1,
88      value: 1,
89      frame: {
90        x: 20,
91        y: 20,
92        width: 160,
93        height: 160,
94      },
95      startTime: 1,
96      ts: 2,
97    };
98    const canvas = document.createElement('canvas');
99    canvas.width = 1;
100    canvas.height = 1;
101    const ctx = canvas.getContext('2d');
102    expect(CounterStruct.draw(ctx, data, 1)).toBeUndefined();
103  });
104
105  it('ProduceWorkerSdkCounterTest04', () => {
106    let node = {
107      startNs: 1,
108      value: 1,
109      frame: {
110        x: 13,
111        y: 13,
112        width: 130,
113        height: 130,
114      },
115      ts: 1,
116      dur: 1,
117    };
118    let frame = {
119      x: 20,
120      y: 20,
121      width: 100,
122      height: 100,
123    };
124    expect(CounterStruct.setCounterFrame(node, 2, 1, 2, 2, frame)).toBeUndefined();
125  });
126
127  it('ProduceWorkerSdkCounterTest05', () => {
128    let node = {
129      startNs: 1,
130      value: 1,
131      frame: {
132        x: 50,
133        y: 50,
134        width: 150,
135        height: 150,
136      },
137      ts: 0,
138      dur: 3,
139    };
140    let frame = {
141      x: 20,
142      y: 20,
143      width: 100,
144      height: 100,
145    };
146    expect(CounterStruct.setCounterFrame(node, 2, 1, 2, 2, frame)).toBeUndefined();
147  });
148
149  it('ProduceWorkerSdkCounterTest06', function () {
150    let sdkCounterRender = new SdkCounterRender();
151    let sdkCounterReq = {
152      lazyRefresh: true,
153      type: '',
154      startNS: 1,
155      endNS: 199,
156      totalNS: 198,
157      frame: {
158        x: 20,
159        y: 20,
160        width: 100,
161        height: 120,
162      },
163      useCache: false,
164      range: {
165        refresh: '',
166      },
167      canvas: 'a',
168      context: {
169        font: '11px sans-serif',
170        fillStyle: '#effa8e',
171        globalAlpha: 0.71,
172        clearRect: jest.fn(() => true),
173        beginPath: jest.fn(() => true),
174        stroke: jest.fn(() => true),
175        closePath: jest.fn(() => true),
176        measureText: jest.fn(() => true),
177        fillText: jest.fn(() => false),
178        fillRect: jest.fn(() => true),
179      },
180      lineColor: '#78e2ba',
181      isHover: '',
182      hoverX: 144,
183      params: '',
184      wakeupBean: undefined,
185      flagMoveInfo: '',
186      flagSelectedInfo: '',
187      slicesTime: 342,
188      id: 1,
189      x: 20,
190      y: 20,
191      width: 123,
192      height: 135,
193    };
194    window.postMessage = jest.fn(() => true);
195    expect(sdkCounterRender.renderMainThread(sdkCounterReq, new TraceRow())).toBeUndefined();
196  });
197  it('ProduceWorkerSdkCounterTest06', function () {
198    let sdkCounterRender = new SdkCounterRender();
199    let canvas = document.createElement('canvas') as HTMLCanvasElement;
200    let context = canvas.getContext('2d');
201    const data = {
202      context: context!,
203      useCache: true,
204      type: '',
205      traceRange: [],
206    };
207    window.postMessage = jest.fn(() => true);
208    expect(sdkCounterRender.renderMainThread(data, new TraceRow())).toBeUndefined();
209  });
210});
211