• 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 {
17  CpuFreqExtendStruct,
18  FreqExtendRender
19} from '../../../../src/trace/database/ui-worker/ProcedureWorkerFreqExtend';
20jest.mock('../../../../src/trace/database/ui-worker/cpu/ProcedureWorkerCPU', () => {
21  return {};
22});
23jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
24  return {};
25});
26describe('ProcedureWorkerFreqExtend Test',()=>{
27  it('ProcedureWorkerFreqExtendTest01 ', function () {
28    const data = {
29      frame: {
30        x: 20,
31        y: 19,
32        width: 10,
33        height: 3,
34      },
35      dur: 1,
36      value: 'aa',
37      startTs: 12,
38      pid: 2,
39      process: 'null',
40      itid: 12,
41      endItid: 13,
42      tid: 3,
43      startName: '23',
44      stepName: 'st',
45    };
46    const canvas = document.createElement('canvas');
47    canvas.width = 1;
48    canvas.height = 1;
49    const ctx = canvas.getContext('2d');
50    expect(CpuFreqExtendStruct.draw(ctx,data)).toBeUndefined()
51  });
52  it('ProcedureWorkerFreqExtendTest02 ', function () {
53    let freqExtendRender = new FreqExtendRender();
54    let freqReq = {
55      lazyRefresh: true,
56      type: '',
57      startNS: 5,
58      endNS: 9,
59      totalNS: 4,
60      frame: {
61        x: 32,
62        y: 20,
63        width: 180,
64        height: 180,
65      },
66      useCache: true,
67      range: {
68        refresh: '',
69      },
70      canvas: 'a',
71      context: {
72        font: '12px sans-serif',
73        fillStyle: '#a1697d',
74        globalAlpha: 0.3,
75        measureText: jest.fn(() => true),
76        clearRect: jest.fn(() => true),
77        stroke: jest.fn(() => true),
78        closePath: jest.fn(() => false),
79        beginPath: jest.fn(() => true),
80        fillRect: jest.fn(() => false),
81        fillText: jest.fn(() => true),
82      },
83      lineColor: '',
84      isHover: 'true',
85      hoverX: 0,
86      params: '',
87      wakeupBean: undefined,
88      flagMoveInfo: '',
89      flagSelectedInfo: '',
90      slicesTime: 4,
91      id: 1,
92      x: 24,
93      y: 24,
94      width: 100,
95      height: 100,
96    };
97    window.postMessage = jest.fn(() => true);
98    expect(freqExtendRender.renderMainThread(freqReq,new TraceRow<CpuFreqExtendStruct>()))
99  });
100})