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