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 16jest.mock('../../../../dist/trace/component/trace/base/TraceRow.js', () => { 17 return {}; 18}); 19 20// @ts-ignore 21import { fps, FpsStruct, FpsRender } from '../../../../dist/trace/database/ui-worker/ProcedureWorkerFPS.js'; 22// @ts-ignore 23import { Rect } from '../../../../dist/trace/component/trace/timer-shaft/Rect.js'; 24 25describe(' FPSTest', () => { 26 it('FpsTest01', () => { 27 const canvas = document.createElement('canvas'); 28 canvas.width = 1; 29 canvas.height = 1; 30 const ctx = canvas.getContext('2d'); 31 let dataList = new Array(); 32 dataList.push({ 33 startTime: 0, 34 dur: 10, 35 frame: { x: 0, y: 9, width: 10, height: 10 }, 36 }); 37 dataList.push({ startTime: 1, dur: 111 }); 38 let rect = new Rect(0, 10, 10, 10); 39 fps(dataList, [{ length: 1 }], 1, 100254, 100254, rect, true); 40 }); 41 42 it('FpsTest02', () => { 43 let fpsDataList = new Array(); 44 fpsDataList.push({ 45 startTime: 34, 46 dur: 14, 47 frame: { x: 40, y: 442, width: 230, height: 340 }, 48 }); 49 fpsDataList.push({ 50 startTime: 61, 51 dur: 156, 52 frame: { x: 60, y: 9, width: 10, height: 10 }, 53 }); 54 let rect = new Rect(0, 50, 50, 16); 55 fps(fpsDataList, [{ length: 0 }], 1, 100254, 100254, rect, false); 56 }); 57 58 it('FpsTest03', () => { 59 const canvas = document.createElement('canvas'); 60 canvas.width = 8; 61 canvas.height = 8; 62 const ctx = canvas.getContext('2d'); 63 64 const data = { 65 frame: { 66 x: 218, 67 y: 201, 68 width: 220, 69 height: 320, 70 }, 71 startNS: 255, 72 value: 4, 73 }; 74 75 expect(FpsStruct.draw(ctx, data)).toBeUndefined(); 76 }); 77 78 it('FpsTest04', () => { 79 const canvas = document.createElement('canvas'); 80 canvas.width = 1; 81 canvas.height = 8; 82 const ctx = canvas.getContext('2d'); 83 84 const data = { 85 frame: { 86 x: 80, 87 y: 30, 88 width: 320, 89 height: 220, 90 }, 91 startNS: 200, 92 value: 50, 93 }; 94 new FpsStruct(1); 95 FpsStruct.hoverFpsStruct = jest.fn(() => { 96 startNS: 200; 97 }); 98 FpsStruct.a = jest.fn(() => data); 99 expect(FpsStruct.draw(ctx, data)).toBeUndefined(); 100 }); 101 it('FpsTest05 ', () => { 102 const canvas = document.createElement('canvas'); 103 canvas.width = 1; 104 canvas.height = 1; 105 const ctx = canvas.getContext('2d'); 106 const Sourcedate = { 107 frame: { 108 x: 520, 109 y: 50, 110 width: 300, 111 height: 300, 112 }, 113 maxFps: 255, 114 value: 550, 115 }; 116 expect(FpsStruct.draw(ctx, Sourcedate)).toBeUndefined(); 117 }); 118 119 it('FpsTest06', function () { 120 let fpsRender = new FpsRender(); 121 let fpsReq = { 122 lazyRefresh: true, 123 type: '', 124 startNS: 1, 125 endNS: 32, 126 totalNS: 31, 127 frame: { 128 x: 54, 129 y: 50, 130 width: 133, 131 height: 133, 132 }, 133 useCache: false, 134 range: { 135 refresh: '', 136 }, 137 canvas: 'a', 138 context: { 139 font: '12px sans-serif', 140 fillStyle: '#af919b', 141 globalAlpha: 0.56, 142 height: 120, 143 width: 100, 144 clearRect: jest.fn(() => true), 145 beginPath: jest.fn(() => true), 146 measureText: jest.fn(() => true), 147 closePath: jest.fn(() => true), 148 fillRect: jest.fn(() => []), 149 fillText: jest.fn(() => true), 150 stroke: jest.fn(() => true), 151 }, 152 lineColor: '', 153 isHover: '', 154 hoverX: 21, 155 wakeupBean: undefined, 156 flagMoveInfo: '', 157 flagSelectedInfo: '', 158 slicesTime: 34, 159 id: 1, 160 x: 220, 161 y: 203, 162 width: 1030, 163 height: 890, 164 params: { 165 isLive: false, 166 maxHeight: 52, 167 dpr: 41, 168 hoverFuncStruct: '', 169 selectFuncStruct: undefined, 170 }, 171 }; 172 window.postMessage = jest.fn(() => true); 173 expect(fpsRender.render(fpsReq, [], [])).toBeUndefined(); 174 }); 175}); 176