• 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
16// @ts-ignore
17import { TraceRow } from '../../../../dist/trace/component/trace/base/TraceRow.js';
18
19jest.mock('../../../../dist/trace/database/ui-worker/ProcedureWorker.js', () => {
20  return {};
21});
22// @ts-ignore
23import {
24  DiskAbilityMonitorStruct,
25  diskIoAbility,
26  DiskIoAbilityRender,
27} from '../../../../dist/trace/database/ui-worker/ProcedureWorkerDiskIoAbility.js';
28//@ts-ignore
29import { Rect } from '../../../dist/trace/database/ProcedureWorkerCommon';
30
31describe('ProcedureWorkerDiskIoAbility Test', () => {
32  const canvas = document.createElement('canvas');
33  canvas.width = 6;
34  canvas.height = 6;
35  const ctx = canvas.getContext('2d');
36
37  const data = {
38    frame: {
39      x: 206,
40      y: 206,
41      width: 100,
42      height: 100,
43    },
44    startNS: 200,
45    value: 50,
46  };
47  const Sourcedata = {
48    frame: {
49      x: 20,
50      y: 20,
51      width: 100,
52      height: 100,
53    },
54    maxDiskRate: 300,
55    value: 80,
56  };
57  let res = [
58    {
59      startNS: 11,
60      dur: 30,
61      frame: {
62        x: 6,
63        y: 49,
64        width: 30,
65        height: 60,
66      },
67    },
68  ];
69
70  it('ProcedureWorkerDiskIoAbilityTest01', function () {
71    expect(DiskAbilityMonitorStruct.draw(ctx, data)).toBeUndefined();
72  });
73
74  it('ProcedureWorkerDiskIoAbilityTest03', function () {
75    expect(DiskAbilityMonitorStruct.draw(ctx, Sourcedata)).toBeUndefined();
76  });
77  it('CpuAbilityMonitorStructTest02', function () {
78    let dataList = new Array();
79    dataList.push({
80      startNS: 0,
81      dur: 10,
82      frame: { x: 0, y: 9, width: 10, height: 10 },
83    });
84    dataList.push({ startNS: 1, dur: 111 });
85    diskIoAbility(dataList, [{ length: 1 }], 1, 100254, 100254, '', true);
86  });
87
88  it('CpuAbilityMonitorStructTest03', function () {
89    let dataList = new Array();
90    dataList.push({
91      startNS: 0,
92      dur: 10,
93      frame: { x: 0, y: 9, width: 10, height: 10 },
94    });
95    dataList.push({ startNS: 1, dur: 111 });
96    diskIoAbility(dataList, [{ length: 0 }], 1, 100254, 100254, '', false);
97  });
98
99  it('CpuAbilityMonitorStructTest04', function () {
100    let diskIoAbilityRender = new DiskIoAbilityRender();
101    let diskIoReq = {
102      lazyRefresh: true,
103      type: '',
104      startNS: 5,
105      endNS: 9,
106      totalNS: 4,
107      frame: {
108        x: 32,
109        y: 20,
110        width: 180,
111        height: 180,
112      },
113      useCache: true,
114      range: {
115        refresh: '',
116      },
117      canvas: 'a',
118      context: {
119        font: '12px sans-serif',
120        fillStyle: '#a1697d',
121        globalAlpha: 0.3,
122        measureText: jest.fn(() => true),
123        clearRect: jest.fn(() => true),
124        stroke: jest.fn(() => true),
125        closePath: jest.fn(() => false),
126        beginPath: jest.fn(() => true),
127        fillRect: jest.fn(() => false),
128        fillText: jest.fn(() => true),
129      },
130      lineColor: '',
131      isHover: 'true',
132      hoverX: 0,
133      params: '',
134      wakeupBean: undefined,
135      flagMoveInfo: '',
136      flagSelectedInfo: '',
137      slicesTime: 4,
138      id: 1,
139      x: 24,
140      y: 24,
141      width: 100,
142      height: 100,
143    };
144    window.postMessage = jest.fn(() => true);
145    expect(diskIoAbilityRender.render(diskIoReq, [], [])).toBeUndefined();
146  });
147  it('CpuAbilityMonitorStructTest05', function () {
148    let diskIoAbilityRender = new DiskIoAbilityRender();
149    let canvas = document.createElement('canvas') as HTMLCanvasElement;
150    let context = canvas.getContext('2d');
151    const data = {
152      context: context!,
153      useCache: true,
154      type: '',
155      traceRange: [],
156    };
157    window.postMessage = jest.fn(() => true);
158    expect(diskIoAbilityRender.renderMainThread(data, new TraceRow())).toBeUndefined();
159  });
160});
161