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