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 { threadPool } from '../../../../src/trace/database/SqlLite'; 17import { FrameAnimationStruct } from '../../../../src/trace/database/ui-worker/ProcedureWorkerFrameAnimation'; 18import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; 19import { 20 frameAnimationSender, 21 frameDynamicSender, 22 frameSpacingSender 23} from '../../../../src/trace/database/data-trafic/FrameDynamicEffectSender'; 24import { FrameDynamicStruct } from '../../../../src/trace/database/ui-worker/ProcedureWorkerFrameDynamic'; 25import { FrameSpacingStruct } from '../../../../src/trace/database/ui-worker/ProcedureWorkerFrameSpacing'; 26jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => { 27 return {}; 28}); 29jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 30 return {}; 31}); 32jest.mock('../../../../src/js-heap/model/DatabaseStruct', () => { 33}); 34describe('FrameDynamicEffectSender Test', () => { 35 let animationData = 36 { 37 animationId: 0, 38 depth: 0, 39 dur: 79379, 40 endTs: 145133, 41 frame: {x: 204, y: 2, width: 12, height: 16}, 42 frameInfo: "0", 43 name: "H:APP_LIST_FLING, com.tencent.mm", 44 startTs: 137, 45 status: "Response delay", 46 textMetricsWidth: 120.1328125 47 } 48 49 let dynamicCurveData = { 50 alpha: 1, 51 appName: "WindowScene_mm37", 52 frame: {x: 295, y: 97, width: 0, height: 100}, 53 groupId: 1371974481, 54 height: 2772, 55 id: 100, 56 ts: 197, 57 typeValue: 0, 58 width: 1344, 59 x: 0, 60 y: 0 61 } 62 63 let frameSpacingData = { 64 currentFrameHeight: 2772, 65 currentFrameWidth: 1344, 66 currentTs: 32952, 67 frame: {x: 491, y: 137, width: 0, height: 0}, 68 frameSpacingResult: [2.33], 69 groupId: 1371974481, 70 id: 218, 71 nameId: "WindowScene_mm37", 72 physicalHeight: 2772, 73 physicalWidth: 1344, 74 preFrameHeight: 2772, 75 preFrameWidth: 1344, 76 preTs: 32811, 77 preX: 0, 78 preY: 0, 79 x: 0, 80 y: 0 81 } 82 it('FrameDynamicEffectSenderTest01', () => { 83 threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 84 callback(animationData, 1, true); 85 }); 86 let animationTraceRow = TraceRow.skeleton<FrameAnimationStruct>(); 87 frameAnimationSender(animationTraceRow).then(result => { 88 expect(result).toHaveLength(1); 89 }); 90 }); 91 92 it('FrameDynamicEffectSenderTest02', () => { 93 threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 94 callback(dynamicCurveData, 1, true); 95 }); 96 let frameDynamicTraceRow = TraceRow.skeleton<FrameDynamicStruct>(); 97 frameDynamicSender(frameDynamicTraceRow).then(result => { 98 expect(result).toHaveLength(1); 99 }); 100 }); 101 102 it('FrameDynamicEffectSenderTest03', () => { 103 threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 104 callback(frameSpacingData, 1, true); 105 }); 106 let frameSpacingTraceRow = TraceRow.skeleton<FrameSpacingStruct>(); 107 frameSpacingSender(1255, 5255, frameSpacingTraceRow).then(result => { 108 expect(result).toHaveLength(1); 109 expect(Array.isArray(result)).toBe(true); 110 }); 111 }); 112}); 113