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 { frameJanksSender } from '../../../../src/trace/database/data-trafic/FrameJanksSender'; 18import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; 19import { JanksStruct } from '../../../../src/trace/bean/JanksStruct'; 20import { QueryEnum } from '../../../../src/trace/database/data-trafic/utils/QueryEnum'; 21jest.mock('../../../../src/js-heap/model/DatabaseStruct', () => {}); 22jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => { 23 return {}; 24}); 25jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 26 return {}; 27}); 28 29describe('FrameJanksSender Test', () => { 30 let expectedData = { 31 app_dur: 16603333, 32 cmdline: "com.ohos.launch", 33 depth: 0, 34 dur: 16603333, 35 frame: {x: 167, y: 0, width: 3, height: 20}, 36 frame_type: "frameTime", 37 id: 157, 38 ipid: 19, 39 jank_tag: 65535, 40 name: 2087, 41 pid: 2128, 42 rs_dur: 16603333, 43 rs_ipid: 15, 44 rs_name: "swapper", 45 rs_pid: 994, 46 rs_ts: 1038812, 47 rs_vsync: 1080, 48 ts: 1038812 49 } 50 51 let actualData = { 52 app_dur: 3403000, 53 cmdline: "com.ohos.launch", 54 depth: 0, 55 dur: 17569000, 56 frame: {x: 739, y: 0, width: 3, height: 20}, 57 frame_type: "frameTime", 58 id: 898, 59 ipid: 19, 60 jank_tag: 0, 61 name: 2275, 62 pid: 2128, 63 rs_dur: 1192000, 64 rs_ipid: 15, 65 rs_name: "swapper", 66 rs_pid: 994, 67 rs_ts: 4598062, 68 rs_vsync: 1255, 69 ts: 4581685, 70 type: "0" 71 } 72 73 it('FrameJanksSenderTest01', () => { 74 threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 75 callback(expectedData, 1, true); 76 }); 77 let expectedTraceRow = TraceRow.skeleton<JanksStruct>(); 78 frameJanksSender(QueryEnum.FrameExpectedData, expectedTraceRow).then(result => { 79 expect(result).toHaveLength(1); 80 }); 81 }); 82 83 it('FrameJanksSenderTest02', () => { 84 threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 85 callback(actualData, 1, true); 86 }); 87 let actualTraceRow = TraceRow.skeleton<JanksStruct>(); 88 frameJanksSender(QueryEnum.FrameActualData, actualTraceRow).then(result => { 89 expect(result).toHaveLength(1); 90 expect(Array.isArray(result)).toBe(true); 91 }); 92 }); 93});