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'; 17import { IrqRender, IrqStruct } from '../../../../src/trace/database/ui-worker/ProcedureWorkerIrq'; 18jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 19 return {}; 20}); 21describe('ProcedureWorkerIrq Test', () => { 22 it('ProcedureWorkerIrq01', () => { 23 const canvas = document.createElement('canvas'); 24 canvas.width = 4; 25 canvas.height = 4; 26 const ctx = canvas.getContext('2d'); 27 28 const data = { 29 frame: { 30 x: 210, 31 y: 210, 32 width: 100, 33 height: 100, 34 }, 35 id: 155, 36 startNS: 1745, 37 name: '4515', 38 dur: 4555, 39 argSetId: 10, 40 }; 41 expect(IrqStruct.draw(ctx!, data, true)).toBeUndefined(); 42 }); 43 44 it('ProcedureWorkerIrq02', () => { 45 const canvas = document.createElement('canvas'); 46 canvas.width = 1; 47 canvas.height = 1; 48 const ctx = canvas.getContext('2d'); 49 let data = { textMetricsWidth: 1 }; 50 expect( 51 IrqStruct.draw( 52 ctx, 53 '253', 54 2, 55 { 56 x: 20, 57 y: 20, 58 width: 100, 59 height: 100, 60 }, 61 data 62 ) 63 ).toBeUndefined(); 64 }); 65 it('ProcedureWorkerIrq03', () => { 66 let irqRender = new IrqRender(); 67 let req = { 68 lazyRefresh: true, 69 type: '', 70 startNS: 5, 71 endNS: 9, 72 totalNS: 4, 73 frame: { 74 x: 32, 75 y: 20, 76 width: 170, 77 height: 180, 78 }, 79 useCache: true, 80 range: { 81 refresh: '', 82 }, 83 canvas: 'b', 84 context: { 85 font: '12px sans-serif', 86 fillStyle: '#a1697d', 87 globalAlpha: 0.5, 88 measureText: jest.fn(() => true), 89 clearRect: jest.fn(() => true), 90 stroke: jest.fn(() => true), 91 closePath: jest.fn(() => false), 92 beginPath: jest.fn(() => true), 93 fillRect: jest.fn(() => false), 94 fillText: jest.fn(() => true), 95 }, 96 lineColor: '', 97 isHover: 'true', 98 hoverX: 0, 99 params: '', 100 wakeupBean: undefined, 101 flagMoveInfo: '', 102 flagSelectedInfo: '', 103 slicesTime: 4, 104 id: 1, 105 x: 24, 106 y: 24, 107 width: 100, 108 height: 100, 109 }; 110 window.postMessage = jest.fn(() => true); 111 TraceRow.range = jest.fn(() => true); 112 TraceRow.range.startNS = jest.fn(() => 1); 113 expect(irqRender.renderMainThread(req,new TraceRow<IrqStruct>())); 114 }); 115}); 116