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 */ 15import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; 16import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect'; 17import { 18 HeapSnapshot, 19 HeapSnapshotRender, 20 HeapSnapshotStruct, 21} from '../../../../src/trace/database/ui-worker/ProcedureWorkerHeapSnapshot'; 22 23jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 24 return {}; 25}); 26jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 27 return {}; 28}); 29describe('ProcedureWorkerHeapTimeline Test', () => { 30 it('HeapSnapshotTest', () => { 31 const canvas = document.createElement('canvas'); 32 canvas.width = 1; 33 canvas.height = 1; 34 const ctx = canvas.getContext('2d'); 35 let dataList = new Array(); 36 dataList.push({ 37 startTime: 0, 38 frame: { x: 0, y: 9, width: 10, height: 10 }, 39 dur: 10, 40 }); 41 dataList.push({ startTime: 1, dur: 111 }); 42 let rect = new Rect(0, 10, 10, 10); 43 let filter = [ 44 { 45 frame: { x: 0, y: 0, width: 25, height: 40 }, 46 end_time: 50, 47 end_ts: 1520000, 48 file_name: 'Snapshot0', 49 start_ts: 88473061693464, 50 start_time: 0, 51 id: 0, 52 pid: 4243, 53 textMetricsWidth: 50.5810546875, 54 }, 55 ]; 56 let list = [ 57 { 58 file_name: 'Snapshot0', 59 frame: { x: 0, y: 0, width: 6222, height: 62222 }, 60 pid: 4243, 61 start_time: 0, 62 start_ts: 88473061693464, 63 textMetricsWidth: 50.5810546875, 64 end_time: 50, 65 end_ts: 1520000, 66 id: 0, 67 }, 68 ]; 69 HeapSnapshot(list, filter, 100254, 100254, rect, { height: 40, width: 1407, x: 0, y: 0 }); 70 }); 71 72 it('HeapSnapshotStructTest01', () => { 73 const data = { 74 cpu: 3, 75 startNs: 31, 76 value: 91, 77 frame: { 78 x: 23, 79 y: 22, 80 width: 200, 81 height: 120, 82 }, 83 maxValue: undefined, 84 startTime: 31, 85 filterID: 23, 86 size: 106, 87 }; 88 const canvas = document.createElement('canvas'); 89 canvas.width = 1; 90 canvas.height = 1; 91 const ctx = canvas.getContext('2d'); 92 expect(HeapSnapshotStruct.draw(ctx, data)).toBeUndefined(); 93 }); 94 95 it('HeapSnapshotStructTest02', () => { 96 const data = { 97 cpu: 0, 98 startNs: 71, 99 value: 17, 100 frame: { 101 x: 270, 102 y: 250, 103 width: 500, 104 height: 606, 105 }, 106 maxValue: undefined, 107 startTime: 61, 108 filterID: 21, 109 }; 110 let node = { 111 start_time: 3, 112 end_time: 4, 113 frame: null, 114 }; 115 expect(HeapSnapshotStruct.setFrame(node, 0, 1, 2, data)).toBeUndefined(); 116 }); 117 118 it('HeapSnapshotRenderTest03', () => { 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 let heapSnapshotRender = new HeapSnapshotRender(); 128 expect(heapSnapshotRender.renderMainThread(data, new TraceRow())).toBeUndefined(); 129 }); 130 it('HeapSnapshotStructTest04', () => { 131 expect(HeapSnapshotStruct).not.toBeUndefined(); 132 }); 133}); 134