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 16jest.mock('../../../../src/trace/component/trace/base/TraceRow', () => { 17 return {}; 18}); 19jest.mock('../../../../src/js-heap/model/DatabaseStruct', () => { 20 return {}; 21}); 22import { 23 RangeRuler, 24 SportRuler, 25 timeline, 26 TimelineRender, 27} from '../../../../src/trace/database/ui-worker/ProcedureWorkerTimeline'; 28import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect'; 29jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => { 30 return {}; 31}); 32jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 33 return {}; }); 34 35describe(' ProcedureWorkerTimelineTest', () => { 36 it('timelineTest', () => { 37 const timelineCanvas = document.createElement('canvas'); 38 timelineCanvas.width = 12; 39 timelineCanvas.height = 12; 40 const ctx = timelineCanvas.getContext('2d'); 41 let dataList = new Array(); 42 dataList.push({ 43 startTime: 0, 44 dur: 120, 45 frame: { x: 0, y: 9, width: 120, height: 10 }, 46 }); 47 dataList.push({ startTime: 1, dur: 111 }); 48 let rect = new Rect(0, 10, 10, 10); 49 let keyboardEvent: KeyboardEvent = new KeyboardEvent('w', <KeyboardEventInit>{ ctrlKey: true, keyCode: 13 }); 50 timeline(timelineCanvas, ctx, 1, 100254, keyboardEvent, rect, null, null, null, null, null, null, 0, 0, (e: any) => {}); 51 }); 52 53 it('SportRulerTest01', () => { 54 const canvas = document.createElement('canvas'); 55 canvas.width = 1; 56 canvas.height = 1; 57 const ctx = canvas.getContext('2d'); 58 let rect = new Rect(0, 10, 10, 10); 59 let sportRuler = new SportRuler(canvas, ctx, rect); 60 sportRuler.modifyFlagList('amend'); 61 sportRuler.modifyFlagList('remove'); 62 sportRuler.drawTheFlag(0, '#999999', false, ''); 63 sportRuler.randomRgbColor(); 64 sportRuler.mouseMove(new MouseEvent('')); 65 sportRuler.mouseUp(new MouseEvent('')); 66 sportRuler.onFlagRangeEvent('1', 2); 67 }); 68 69 it('SportRulerTest02', () => { 70 const canvas = document.createElement('canvas'); 71 canvas.width = 2; 72 canvas.height = 1; 73 const ctx = canvas.getContext('2d'); 74 let rect = new Rect(0, 20, 10, 20); 75 let rangeRuler = new RangeRuler( 76 canvas, 77 ctx, 78 rect, 79 { 80 startX: 10, 81 endX: rect.width, 82 startNS: 40, 83 endNS: 14, 84 totalNS: 155, 85 xs: [], 86 xsTxt: [], 87 }, 88 (a: any) => {} 89 ); 90 rangeRuler.draw(); 91 rangeRuler.drawCpuUsage(); 92 rangeRuler.mouseDown({ offsetX: 1, offsetY: 1 }); 93 rangeRuler.mouseUp(new MouseEvent('')); 94 rangeRuler.mouseMove(new MouseEvent('')); 95 rangeRuler.mouseOut(new MouseEvent('')); 96 rangeRuler.range.startNS = -2; 97 rangeRuler.range.endNS = -2; 98 rangeRuler.range.totalNS = -7; 99 rangeRuler.fillX(); 100 rangeRuler.keyPress(new KeyboardEvent('')); 101 rangeRuler.pressFrameId != -1; 102 rangeRuler.keyUp(new KeyboardEvent('')); 103 rangeRuler.keyUp({ key: 'w' }); 104 rangeRuler.keyUp({ key: 's' }); 105 rangeRuler.keyUp({ key: 'a' }); 106 rangeRuler.keyUp({ key: 'd' }); 107 }); 108 109 it('SportRulerTest03', () => { 110 const canvas = document.createElement('canvas'); 111 canvas.width = 1; 112 canvas.height = 4; 113 const ctx = canvas.getContext('2d'); 114 let rect = new Rect(0, 50, 10, 50); 115 let rangeRuler = new RangeRuler( 116 canvas, 117 ctx, 118 rect, 119 { 120 startX: 60, 121 endX: rect.width, 122 startNS: 660, 123 endNS: 116, 124 totalNS: 661, 125 xs: [], 126 xsTxt: [], 127 }, 128 (a: any) => {} 129 ); 130 rangeRuler.cpuUsage = true; 131 expect(rangeRuler.cpuUsage).toBeUndefined(); 132 }); 133}); 134