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