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