• 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';
16
17jest.mock('../../../../src/js-heap/model/DatabaseStruct', () => {
18  return {};
19});
20jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => {
21  return {};
22});
23jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
24  return {};
25});
26jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
27  return {};
28});
29import { LogStruct, LogRender } from '../../../../src/trace/database/ui-worker/ProcedureWorkerLog';
30
31describe('ProcedureWorkerLog Test', () => {
32  let canvas = document.createElement('canvas');
33  canvas.width = 12;
34  canvas.height = 12;
35  const ctx = canvas.getContext('2d');
36  let data = {
37    id: 5230,
38    startTs: 27351020209,
39    level: 'E',
40    depth: 3,
41    tag: 'C01510/BinderInvoker1',
42    context: '124: SendRequest: handle=0 result = 2',
43    time: 15020293020884055,
44    pid: 577,
45    tid: 967,
46    processName: 'distributeddata',
47    dur: 1,
48    frame: {
49      x: 1385,
50      y: 22,
51      width: 1,
52      height: 7,
53    },
54  };
55  it('ProcedureWorkerLog01', () => {
56    expect(LogStruct.draw(ctx!, data)).toBeUndefined();
57  });
58  it('ProcedureWorkerLog02', () => {
59    let logRender = new LogRender();
60    let logReq = {
61      lazyRefresh: true,
62      type: 'log',
63      startNS: 5,
64      endNS: 9,
65      totalNS: 3,
66      frame: {
67        x: 32,
68        y: 20,
69        width: 130,
70        height: 180,
71      },
72      useCache: true,
73      range: {
74        refresh: '',
75      },
76      canvas: 'a',
77      context: {
78        font: '12px sans-serif',
79        fillStyle: '#a1697d',
80        globalAlpha: 0.3,
81        measureText: jest.fn(() => true),
82        clearRect: jest.fn(() => true),
83        stroke: jest.fn(() => true),
84        closePath: jest.fn(() => false),
85        beginPath: jest.fn(() => true),
86        fillRect: jest.fn(() => false),
87        fillText: jest.fn(() => true),
88      },
89      lineColor: '',
90      isHover: 'true',
91      hoverX: 0,
92      params: '',
93      wakeupBean: undefined,
94      flagMoveInfo: '',
95      flagSelectedInfo: '',
96      slicesTime: 4,
97      id: 1,
98      x: 24,
99      y: 24,
100      width: 100,
101      height: 100
102    };
103    window.postMessage = jest.fn(() => true);
104    TraceRow.range = jest.fn(() => true);
105    TraceRow.range.startNS = jest.fn(() => 1);
106    expect(logRender.renderMainThread(logReq, new TraceRow()));
107  });
108  it('ProcedureWorkerLog03 ', function () {
109    let logNode = {
110      frame: {
111        x: 60,
112        y: 24,
113        width: 430,
114        height: 460,
115      },
116      startNS: 100,
117      value: 980,
118      startTs: 53,
119      dur: 21,
120      height: 222,
121    };
122    let frame = {
123      x: 2,
124      y: 20,
125      width: 15,
126      height: 84,
127    };
128    expect(LogStruct.setLogFrame(logNode,1,1,1,1,frame)).toBeUndefined()
129  });
130});
131