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