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'; 17jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 18 return {}; 19}); 20import { 21 heap, 22 HeapStruct, 23 NativeMemoryRender, 24 HeapRender, 25} from '../../../../src/trace/database/ui-worker/ProcedureWorkerHeap'; 26import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect'; 27 28describe(' Test', () => { 29 it('HeapTest01', () => { 30 let heapDataList = new Array(); 31 heapDataList.push({ 32 startTime: 40, 33 dur: 150, 34 frame: { x: 0, y: 19, width: 20, height: 10 }, 35 }); 36 heapDataList.push({ startTime: 12, dur: 21 }); 37 let rect = new Rect(0, 10, 30, 10); 38 let res = [ 39 { 40 startTs: 11, 41 dur: 166, 42 length: 15, 43 frame: '', 44 }, 45 ]; 46 heap(heapDataList, res, 1, 100254, 100254, rect, true); 47 }); 48 49 it('HeapTest02', () => { 50 let heapHataList = new Array(); 51 heapHataList.push({ 52 startTime: 1, 53 dur: 118, 54 frame: { x: 60, y: 9, width: 10, height: 10 }, 55 }); 56 heapHataList.push({ 57 startTime: 1, 58 dur: 15, 59 frame: { x: 0, y: 19, width: 110, height: 130 }, 60 }); 61 let rect = new Rect(0, 10, 10, 10); 62 let res = [ 63 { 64 startTs: 0, 65 dur: 10, 66 length: 0, 67 frame: '', 68 }, 69 ]; 70 heap(heapHataList, res, 1, 100254, 100254, rect, false); 71 }); 72 73 it('HeapTest03', () => { 74 const canvas = document.createElement('canvas'); 75 canvas.width = 11; 76 canvas.height = 12; 77 const ctx = canvas.getContext('2d'); 78 79 const data = { 80 frame: { 81 x: 250, 82 y: 250, 83 width: 100, 84 height: 100, 85 }, 86 startNS: 200, 87 value: 50, 88 }; 89 expect(HeapStruct.drawHeap(ctx, data, 0)).toBeUndefined(); 90 }); 91 it('HeapTest04', () => { 92 const canvas = document.createElement('canvas'); 93 canvas.width = 11; 94 canvas.height = 11; 95 const ctx = canvas.getContext('2d'); 96 97 const data = { 98 frame: { 99 x: 205, 100 y: 205, 101 width: 100, 102 height: 100, 103 }, 104 maxHeapSize: 200, 105 value: 50, 106 }; 107 expect(HeapStruct.drawHeap(ctx, data, 1)).toBeUndefined(); 108 }); 109 110 it('HeapTest05', function () { 111 let heapRender = new HeapRender(); 112 let heapReq = [{ 113 lazyRefresh: true, 114 type: '', 115 startNS: 3, 116 endNS: 9, 117 totalNS: 6, 118 frame: { 119 x: 20, 120 y: 20, 121 width: 200, 122 height: 200, 123 }, 124 useCache: false, 125 range: { 126 refresh: '', 127 }, 128 canvas: 'canvas', 129 context: { 130 font: '11px sans-serif', 131 fillStyle: '#ec407a', 132 globalAlpha: 0.56, 133 clearRect: jest.fn(() => true), 134 beginPath: jest.fn(() => false), 135 closePath: jest.fn(() => true), 136 measureText: jest.fn(() => true), 137 stroke: jest.fn(() => true), 138 fillRect: jest.fn(() => true), 139 fillText: jest.fn(() => true), 140 }, 141 lineColor: '#666666', 142 isHover: '', 143 hoverX: 1, 144 params: 'params', 145 wakeupBean: undefined, 146 flagMoveInfo: '', 147 flagSelectedInfo: '', 148 slicesTime: 1, 149 id: 1, 150 x: 20, 151 y: 20, 152 width: 320, 153 height: 320, 154 }]; 155 window.postMessage = jest.fn(() => true); 156 let frame = { x: 0, y: 9, width: 10, height: 10 }; 157 expect(heap(heapReq, heapReq, 0, 52100, 3569,frame , true)).toBeUndefined(); 158 }); 159 it('HeapTest04', () => { 160 const canvas = document.createElement('canvas'); 161 canvas.width = 1; 162 canvas.height = 1; 163 const ctx = canvas.getContext('2d'); 164 165 const data = { 166 frame: { 167 x: 20, 168 y: 20, 169 width: 100, 170 height: 100, 171 }, 172 startNS: 200, 173 value: 50, 174 }; 175 const node = { 176 frame: { 177 x: 20, 178 y: 20, 179 width: 100, 180 height: 100, 181 }, 182 startNS: 200, 183 value: 50, 184 }; 185 expect(HeapStruct.setFrame(node, 2, 1, 5, 4, data)).toBeUndefined(); 186 }); 187 it('HeapTest07', function () { 188 let heapRender = new HeapRender(); 189 let canvas = document.createElement('canvas') as HTMLCanvasElement; 190 let context = canvas.getContext('2d'); 191 const data = { 192 context: context!, 193 useCache: true, 194 type: '', 195 traceRange: [], 196 }; 197 window.postMessage = jest.fn(() => true); 198 expect(heapRender.renderMainThread(data, new TraceRow())).toBeUndefined(); 199 }); 200}); 201