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('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 17 return {}; 18}); 19 20import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; 21import { 22 FrameSpacingRender, 23 FrameSpacingStruct, 24} from '../../../../src/trace/database/ui-worker/ProcedureWorkerFrameSpacing'; 25import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect'; 26 27describe('FrameSpacing Test', () => { 28 let frameSpacingRender = new FrameSpacingRender(); 29 let canvas = document.createElement('canvas'); 30 canvas.width = 1; 31 canvas.height = 1; 32 let ctx = canvas.getContext('2d'); 33 let req = { 34 animationRanges: [{ start: 4091445476, end: 4774481414 }], 35 context: ctx, 36 frameRate: 90, 37 type: 'frame_spacing_slice', 38 useCache: false, 39 }; 40 TraceRow.range = { 41 startNS: 0, 42 endNS: 16868000000, 43 totalNS: 16868000000, 44 }; 45 let dataList = [ 46 { 47 currentFrameHeight: 2753, 48 currentFrameWidth: 1339, 49 currentTs: 11618846517, 50 frame: new Rect(), 51 frameSpacingResult: 0.2, 52 groupId: 0, 53 id: 709, 54 nameId: 'test', 55 preFrameHeight: 2750, 56 preFrameWidth: 1338, 57 preTs: 11629160500, 58 x: 0, 59 y: 4, 60 }, 61 { 62 currentFrameHeight: 2753, 63 currentFrameWidth: 1339, 64 currentTs: 11629160579, 65 frame: new Rect(), 66 frameSpacingResult: 0.1, 67 groupId: 11095334538, 68 id: 709, 69 nameId: 'test', 70 preFrameHeight: 2750, 71 preFrameWidth: 1338, 72 preTs: 11618846517, 73 x: 0, 74 y: 4, 75 }, 76 { 77 currentFrameHeight: 2755, 78 currentFrameWidth: 1340, 79 currentTs: 11640114746, 80 frame: new Rect(), 81 frameSpacingResult: 0.1, 82 groupId: 11095334538, 83 id: 710, 84 nameId: 'test', 85 preFrameHeight: 2753, 86 preFrameWidth: 1339, 87 preTs: 11629160579, 88 x: 0, 89 y: 4, 90 }, 91 ]; 92 it('FrameSpacingTest01', function () { 93 expect(frameSpacingRender.render(req, dataList, TraceRow.skeleton())).toBeUndefined(); 94 }); 95 96 it('FrameSpacingTest02', function () { 97 frameSpacingRender.frameSpacing( 98 dataList, 99 [], 100 TraceRow.range.startNS, 101 TraceRow.range.endNS, 102 TraceRow.range.totalNS, 103 TraceRow.skeleton(), 104 req.animationRanges, 105 false 106 ); 107 expect(frameSpacingRender).not.toBeUndefined(); 108 }); 109 110 it('FrameSpacingTest03', function () { 111 let currentStruct = { 112 currentFrameHeight: 2755, 113 currentFrameWidth: 1340, 114 currentTs: 11640114746, 115 frame: new Rect(), 116 frameSpacingResult: 0.1, 117 groupId: 11095334538, 118 id: 710, 119 nameId: 'test', 120 preFrameHeight: 2753, 121 preFrameWidth: 1339, 122 preTs: 11629160579, 123 x: 0, 124 y: 4, 125 }; 126 expect(frameSpacingRender.drawPoint(ctx, currentStruct, TraceRow.skeleton(), 0, 20)).toBeUndefined(); 127 }); 128}); 129