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 16// @ts-ignore 17import {fps, FpsStruct,FpsRender} from "../../../../dist/trace/database/ui-worker/ProcedureWorkerFPS.js"; 18// @ts-ignore 19import {Rect} from "../../../../dist/trace/component/trace/timer-shaft/Rect.js"; 20 21describe(' FPSTest', () => { 22 23 it('FpsTest01', () => { 24 let dataList = new Array(); 25 dataList.push({startTime: 0, dur: 10, frame: {x:0, y:9, width:10, height:10}}) 26 dataList.push({startTime: 1, dur: 111}) 27 let rect = new Rect(0, 10, 10, 10); 28 fps(dataList, [{length: 1}], 1, 100254, 100254, rect,true) 29 }) 30 31 it('FpsTest02', () => { 32 let dataList = new Array(); 33 dataList.push({startTime: 0, dur: 10, frame: {x:0, y:9, width:10, height:10}}) 34 dataList.push({startTime: 1, dur: 111, frame: {x:0, y:9, width:10, height:10}}) 35 let rect = new Rect(0, 10, 10, 10); 36 fps(dataList, [{length: 0}], 1, 100254, 100254, rect,false) 37 }) 38 39 it('FpsTest03', () => { 40 const canvas = document.createElement('canvas'); 41 canvas.width = 1; 42 canvas.height = 1; 43 const ctx = canvas.getContext('2d'); 44 45 const data = { 46 frame: { 47 x: 20, 48 y: 20, 49 width: 100, 50 height: 100 51 }, 52 startNS: 200, 53 value: 50 54 } 55 56 expect(FpsStruct.draw(ctx, data)).toBeUndefined() 57 }) 58 59 60 it('FpsTest04', () => { 61 const canvas = document.createElement('canvas'); 62 canvas.width = 1; 63 canvas.height = 1; 64 const ctx = canvas.getContext('2d'); 65 66 const data = { 67 frame: { 68 x: 20, 69 y: 20, 70 width: 100, 71 height: 100 72 }, 73 startNS: 200, 74 value: 50 75 } 76 new FpsStruct(1); 77 FpsStruct.hoverFpsStruct = jest.fn(() => {startNS:200}) 78 FpsStruct.a = jest.fn(() => data); 79 expect(FpsStruct.draw(ctx, data)).toBeUndefined() 80 }) 81 it('FpsTest05 ', () => { 82 const canvas = document.createElement('canvas'); 83 canvas.width = 1; 84 canvas.height = 1; 85 const ctx = canvas.getContext('2d'); 86 const Sourcedate = { 87 frame: { 88 x: 20, 89 y: 20, 90 width: 100, 91 height: 100 92 }, 93 maxFps: 200, 94 value: 50 95 } 96 expect(FpsStruct.draw(ctx,Sourcedate)).toBeUndefined() 97 }); 98 99 it('FpsTest06', function () { 100 let fpsRender = new FpsRender() 101 let req = { 102 lazyRefresh:true, 103 type:"", 104 startNS:1, 105 endNS:1, 106 totalNS:1, 107 frame: { 108 x: 20, 109 y: 20, 110 width: 100, 111 height: 100 112 }, 113 useCache:false, 114 range:{ 115 refresh:"", 116 }, 117 canvas:'', 118 context:{ 119 font:"11px sans-serif", 120 fillStyle:"#ec407a", 121 globalAlpha:0.6, 122 height:150, 123 width:100 124 }, 125 lineColor:'', 126 isHover:'', 127 hoverX:1, 128 wakeupBean:undefined, 129 flagMoveInfo:'', 130 flagSelectedInfo:'', 131 slicesTime:3, 132 id:1, 133 x: 20, 134 y: 20, 135 width: 100, 136 height: 100, 137 params:{ 138 isLive:false, 139 maxHeight:2, 140 dpr:1, 141 hoverFuncStruct:'', 142 selectFuncStruct:undefined, 143 } 144 } 145 window.postMessage = jest.fn(()=>true) 146 expect(fpsRender.render(req,[],[])).toBeUndefined() 147 }); 148});