• 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
23//@ts-ignore
24import {
25  NetworkAbilityMonitorStruct,
26  NetworkAbilityRender,
27} from '../../../../dist/trace/database/ui-worker/ProcedureWorkerNetworkAbility.js';
28
29describe('ProcedureWorkerNetworkAbility Test', () => {
30  const canvas = document.createElement('canvas');
31  canvas.width = 1;
32  canvas.height = 1;
33  const ctx = canvas.getContext('2d');
34
35  const data = {
36    frame: {
37      x: 2,
38      y: 2,
39      width: 10,
40      height: 10,
41    },
42    startNS: 11,
43    value: 15,
44  };
45  let res = [
46    {
47      startNS: 12,
48      dur: 13,
49      frame: {
50        x: 440,
51        y: 94,
52        width: 40,
53        height: 140,
54      },
55    },
56  ];
57
58  it('ProcedureWorkerNetworkAbilityTest01', function () {
59    expect(NetworkAbilityMonitorStruct.draw(ctx, data)).toBeUndefined();
60  });
61
62  it('ProcedureWorkerNetworkAbilityTest02', function () {
63    let networkAbilityRender = new NetworkAbilityRender();
64    let networkAbility = {
65      lazyRefresh: true,
66      type: '',
67      startNS: 32,
68      endNS: 33,
69      totalNS: 1,
70      frame: {
71        x: 23,
72        y: 23,
73        width: 603,
74        height: 103,
75      },
76      useCache: false,
77      range: {
78        refresh: '',
79      },
80      canvas: '',
81      context: {
82        font: '11px sans-serif',
83        fillStyle: '#272822',
84        globalAlpha: 0.6,
85      },
86      lineColor: '#120f82',
87      isHover: '',
88      hoverX: 10,
89      params: '',
90      wakeupBean: undefined,
91      flagMoveInfo: '',
92      flagSelectedInfo: '',
93      slicesTime: 13,
94      id: 1,
95      x: 60,
96      y: 60,
97      width: 100,
98      height: 106,
99    };
100    window.postMessage = jest.fn(() => true);
101    expect(networkAbilityRender.render(networkAbility, [], [])).toBeUndefined();
102  });
103  it('ProcedureWorkerNetworkAbilityTest03', function () {
104    let networkAbilityRender = new NetworkAbilityRender();
105    let canvas = document.createElement('canvas') as HTMLCanvasElement;
106    let context = canvas.getContext('2d');
107    const data = {
108      context: context!,
109      useCache: true,
110      type: '',
111      traceRange: [],
112    };
113    window.postMessage = jest.fn(() => true);
114    expect(networkAbilityRender.renderMainThread(data, new TraceRow())).toBeUndefined();
115  });
116});
117