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'; 17 18jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 19 return {}; 20}); 21import { ClockStruct, ClockRender } from '../../../../src/trace/database/ui-worker/ProcedureWorkerClock'; 22jest.mock('../../../../src/js-heap/model/DatabaseStruct', () => { 23 return {}; 24}); 25jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => { 26 return {}; 27}); 28describe('ProcedureWorkerClock Test', () => { 29 it('ProcedureWorkerClock01', () => { 30 const canvas = document.createElement('canvas'); 31 canvas.width = 12; 32 canvas.height = 12; 33 const ctx = canvas.getContext('2d'); 34 35 const data = { 36 frame: { 37 x: 202, 38 y: 202, 39 width: 100, 40 height: 100, 41 }, 42 filterId: 125, 43 value: 556, 44 startNS: 15454, 45 dur: 14552, 46 delta: 125, 47 }; 48 expect(ClockStruct.draw(ctx!, data, 2)).toBeUndefined(); 49 }); 50 it('ProcedureWorkerClock02 ', function () { 51 let clockRender = new ClockRender(); 52 let clockReq = { 53 lazyRefresh: true, 54 type: '', 55 startNS: 5, 56 endNS: 9, 57 totalNS: 3, 58 frame: { 59 x: 32, 60 y: 18, 61 width: 180, 62 height: 180, 63 }, 64 useCache: true, 65 range: { 66 refresh: '', 67 }, 68 canvas: 'b', 69 context: { 70 font: '12px sans-serif', 71 fillStyle: '#a1697d', 72 globalAlpha: 0.6, 73 measureText: jest.fn(() => true), 74 clearRect: jest.fn(() => true), 75 stroke: jest.fn(() => true), 76 closePath: jest.fn(() => false), 77 beginPath: jest.fn(() => true), 78 fillRect: jest.fn(() => false), 79 fillText: jest.fn(() => true), 80 }, 81 lineColor: '', 82 isHover: 'true', 83 hoverX: 0, 84 params: '', 85 wakeupBean: undefined, 86 flagMoveInfo: '', 87 flagSelectedInfo: '', 88 slicesTime: 4, 89 id: 1, 90 x: 24, 91 y: 24, 92 width: 100, 93 height: 100, 94 }; 95 expect(clockRender.renderMainThread(clockReq,new TraceRow<ClockStruct>())).toBeUndefined() 96 }); 97}); 98