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 memoryAbility, 22 MemoryAbilityMonitorStruct, 23 MemoryAbilityRender, 24} from '../../../../src/trace/database/ui-worker/ProcedureWorkerMemoryAbility'; 25jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 26 return {}; 27}); 28describe('ProcedureWorkerMemoryAbility Test', () => { 29 let frame = { 30 x: 0, 31 y: 9, 32 width: 10, 33 height: 10, 34 }; 35 it('ProcedureWorkerMemoryAbilityTest01', () => { 36 const data = { 37 frame: { 38 width: 10, 39 height: 10, 40 x: 1, 41 y: 1, 42 }, 43 cpu: 1, 44 startNs: 1, 45 value: 1, 46 }; 47 const canvas = document.createElement('canvas'); 48 canvas.width = 1; 49 canvas.height = 1; 50 const ctx = canvas.getContext('2d'); 51 expect(MemoryAbilityMonitorStruct.draw(ctx, data)).toBeUndefined(); 52 }); 53 54 it('ProcedureWorkerMemoryAbilityTest02', function () { 55 let dataList = new Array(); 56 dataList.push({ 57 startNS: 0, 58 dur: 10, 59 frame: { x: 0, y: 9, width: 10, height: 10 }, 60 }); 61 dataList.push({ startNS: 1, dur: 2 }); 62 memoryAbility(dataList, [{ length: 0 }], 1, 8, 3, frame, true); 63 }); 64 65 it('ProcedureWorkerMemoryAbilityTest02', function () { 66 let dataList = new Array(); 67 dataList.push({ 68 startNS: 0, 69 dur: 10, 70 frame: { x: 0, y: 9, width: 10, height: 10 }, 71 }); 72 dataList.push({ startNS: 1, dur: 2 }); 73 memoryAbility(dataList, [{ length: 0 }], 1, 8, 3, frame, false); 74 }); 75 76 it('ProcedureWorkerMemoryAbilityTest03', function () { 77 let memoryAbilityRender = new MemoryAbilityRender(); 78 let memoryAbilityReq = { 79 lazyRefresh: true, 80 type: '', 81 startNS: 1, 82 endNS: 9, 83 totalNS: 8, 84 frame: { 85 x: 20, 86 y: 29, 87 width: 100, 88 height: 100, 89 }, 90 useCache: false, 91 range: { 92 refresh: '', 93 }, 94 canvas: 'a', 95 context: { 96 font: '11px sans-serif', 97 fillStyle: '#7800a8', 98 globalAlpha: 0.6, 99 clearRect: jest.fn(() => true), 100 beginPath: jest.fn(() => true), 101 stroke: jest.fn(() => true), 102 closePath: jest.fn(() => true), 103 measureText: jest.fn(() => true), 104 fillRect: jest.fn(() => true), 105 fillText: jest.fn(() => []), 106 }, 107 lineColor: '#170202', 108 isHover: '', 109 hoverX: 1, 110 params: '', 111 wakeupBean: undefined, 112 flagMoveInfo: '', 113 flagSelectedInfo: '', 114 slicesTime: 0, 115 id: 1, 116 x: 23, 117 y: 21, 118 width: 130, 119 height: 140, 120 }; 121 window.postMessage = jest.fn(() => true); 122 expect(memoryAbilityRender.renderMainThread(memoryAbilityReq, new TraceRow())).toBeUndefined(); 123 }); 124 it('ProcedureWorkerMemoryAbilityTest04', function () { 125 let memoryAbilityRender = new MemoryAbilityRender(); 126 let canvas = document.createElement('canvas') as HTMLCanvasElement; 127 let context = canvas.getContext('2d'); 128 const data = { 129 context: context!, 130 useCache: true, 131 type: '', 132 traceRange: [], 133 }; 134 window.postMessage = jest.fn(() => true); 135 expect(memoryAbilityRender.renderMainThread(data, new TraceRow())).toBeUndefined(); 136 }); 137}); 138