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/js-heap/model/DatabaseStruct', () => {}); 19jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => { 20 return {}; 21}); 22import { 23 proc, 24 ProcessStruct, 25 ProcessRender, 26} from '../../../../src/trace/database/ui-worker/ProcedureWorkerProcess'; 27import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect'; 28 29jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 30 return {}; 31}); 32 33describe(' ProcessTest', () => { 34 let res = [ 35 { 36 startNS: 6, 37 dur: 650, 38 frame: { 39 x: 99, 40 y: 92, 41 width: 190, 42 height: 193, 43 }, 44 }, 45 ]; 46 it('ProcessTest01', () => { 47 let dataList = new Array(); 48 dataList.push({ 49 startTime: 0, 50 dur: 10, 51 frame: { x: 0, y: 9, width: 10, height: 10 }, 52 }); 53 dataList.push({ startTime: 1, dur: 111 }); 54 let rect = new Rect(0, 10, 10, 10); 55 proc(dataList, res, 1, 100254, 100254, rect); 56 }); 57 58 it('ProcessTest02', () => { 59 let processDataList = new Array(); 60 processDataList.push({ 61 startTime: 450, 62 dur: 150, 63 frame: { x: 32, y: 3, width: 10, height: 120 }, 64 }); 65 processDataList.push({ 66 startTime: 1, 67 dur: 51, 68 frame: { x: 30, y: 93, width: 20, height: 10 }, 69 }); 70 let rect = new Rect(0, 10, 10, 50); 71 proc(processDataList, res, 1, 100254, 100254, rect); 72 }); 73 74 it('ProcessTest04', () => { 75 const node = { 76 frame: { 77 x: 104, 78 y: 20, 79 width: 105, 80 height: 100, 81 }, 82 startNS: 200, 83 value: 30, 84 startTime: 0, 85 dur: 0, 86 }; 87 const frame = { 88 x: 20, 89 y: 120, 90 width: 100, 91 height: 100, 92 }; 93 expect(ProcessStruct.setFrame(node, 1, 1, 1, frame)).toBeUndefined(); 94 }); 95 96 it('ProcessTest05', () => { 97 const node = { 98 frame: { 99 x: 201, 100 y: 20, 101 width: 3, 102 height: 100, 103 }, 104 startNS: 200, 105 value: 50, 106 startTime: 2, 107 dur: 2, 108 }; 109 const frame = { 110 x: 20, 111 y: 40, 112 width: 100, 113 height: 100, 114 }; 115 expect(ProcessStruct.setFrame(node, 1, 1, 1, frame)).toBeUndefined(); 116 }); 117 it('ProcessTest06 ', function () { 118 let processRender = new ProcessRender(); 119 let canvas = document.createElement('canvas') as HTMLCanvasElement; 120 let context = canvas.getContext('2d'); 121 const data = { 122 context: context!, 123 useCache: true, 124 type: '', 125 traceRange: [], 126 }; 127 window.postMessage = jest.fn(() => true); 128 TraceRow.range = jest.fn(() => true); 129 TraceRow.range.startNS = jest.fn(() => 2); 130 expect(processRender.renderMainThread(data,new TraceRow<ProcessStruct>())) 131 }); 132}); 133