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