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 { SpFrameTimeChart } from '../../../../src/trace/component/chart/SpFrameTimeChart'; 17import { SpSystemTrace } from '../../../../src/trace/component/SpSystemTrace'; 18import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; 19import { SpChartManager } from '../../../../src/trace/component/chart/SpChartManager'; 20import { FlagsConfig } from '../../../../src/trace/component/SpFlags'; 21 22const intersectionObserverMock = () => ({ 23 observe: () => null, 24}); 25window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock); 26 27const sqlite = require('../../../../src/trace/database/SqlLite'); 28jest.mock('../../../../src/trace/database/SqlLite'); 29jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 30 return {}; 31}); 32 33window.ResizeObserver = 34 window.ResizeObserver || 35 jest.fn().mockImplementation(() => ({ 36 disconnect: jest.fn(), 37 observe: jest.fn(), 38 unobserve: jest.fn(), 39 })); 40 41describe('SpFrameTimeChart Test', () => { 42 let trace = new SpSystemTrace(); 43 let manager = new SpChartManager(trace); 44 let spFrameTimeChart = new SpFrameTimeChart(manager); 45 46 let queryFrameTime = sqlite.queryFrameTimeData; 47 let queryFrameTimeData = [ 48 { 49 pid: 256, 50 }, 51 ]; 52 queryFrameTime.mockResolvedValue(queryFrameTimeData); 53 54 let queryExpectedFrame = sqlite.queryExpectedFrameDate; 55 let queryExpectedFrameDate = [ 56 { 57 dur: 2585, 58 depth: 1, 59 }, 60 { 61 dur: 6688, 62 depth: 1, 63 }, 64 ]; 65 queryExpectedFrame.mockResolvedValue(queryExpectedFrameDate); 66 67 let queryActualFrame = sqlite.queryActualFrameDate; 68 let queryActualFrameDate = [ 69 { 70 dur: 6878, 71 depth: 1, 72 }, 73 { 74 dur: 6238, 75 depth: 1, 76 }, 77 ]; 78 queryActualFrame.mockResolvedValue(queryActualFrameDate); 79 80 let frameApp = sqlite.queryFrameApp; 81 let frameAppData = [ 82 { 83 appName: 'test0', 84 }, 85 { 86 appName: 'test1', 87 }, 88 { 89 appName: 'test2', 90 }, 91 ]; 92 frameApp.mockResolvedValue(frameAppData); 93 94 let frameAnimation = sqlite.queryFrameAnimationData; 95 let frameAnimationData = [ 96 { animationId: 1, dynamicEndTs: 4774481414, dynamicStartTs: 4091445476, ts: 4091445476 }, 97 { 98 animationId: 2, 99 dynamicEndTs: 8325095997, 100 dynamicStartTs: 7652588184, 101 ts: 7652588184, 102 }, 103 ]; 104 frameAnimation.mockResolvedValue(frameAnimationData); 105 106 let allProcessNames = sqlite.queryAllProcessNames; 107 let allProcessNameData = [ 108 { 109 id: 12, 110 name: "test name", 111 pid: 255 112 } 113 ]; 114 allProcessNames.mockResolvedValue(allProcessNameData); 115 116 let dynamicIdAndName = sqlite.queryDynamicIdAndNameData; 117 let data = [ 118 { 119 id: 12, 120 appName: "name" 121 } 122 ]; 123 dynamicIdAndName.mockResolvedValue(data); 124 125 let animationTimeRange = sqlite.queryAnimationTimeRangeData; 126 let rangeData = [ 127 { 128 status: "Response delay", 129 startTs: 225, 130 endTs: 6355 131 } 132 ]; 133 animationTimeRange.mockResolvedValue(rangeData); 134 135 136 let animationIdAndName = sqlite.queryAnimationIdAndNameData; 137 let animationIdAndNameData = [ 138 { 139 id: 12, 140 name: "test", 141 info: "{}" 142 } 143 ]; 144 animationIdAndName.mockResolvedValue(animationIdAndNameData); 145 146 let frameDynamic = sqlite.queryFrameDynamicData; 147 let frameDynamicData = [ 148 { alpha: '1.00', appName: 'test0', height: 2772, id: 74, ts: 28565790, width: 1344, x: 0, y: 0 }, 149 { 150 alpha: '1.00', 151 appName: 'test0', 152 height: 2772, 153 id: 75, 154 ts: 42341310, 155 width: 1344, 156 x: 0, 157 y: 0, 158 }, 159 ]; 160 frameDynamic.mockResolvedValue(frameDynamicData); 161 162 let frameSpacing = sqlite.queryFrameSpacing; 163 let frameSpacingData = [ 164 { 165 currentFrameHeight: 2768, 166 currentFrameWidth: 1344, 167 currentTs: 17535295995, 168 frameSpacingResult: 0.1, 169 id: 1216, 170 nameId: 'test0', 171 preFrameHeight: 2767, 172 preFrameWidth: 1343, 173 preTs: 17523356412, 174 x: 0, 175 y: 1, 176 }, 177 { 178 currentFrameHeight: 2768, 179 currentFrameWidth: 1344, 180 currentTs: 17546478287, 181 frameSpacingResult: 0, 182 id: 1217, 183 nameId: 'test0', 184 preFrameHeight: 2768, 185 preFrameWidth: 1344, 186 preTs: 17535295995, 187 x: 0, 188 y: 1, 189 }, 190 ]; 191 frameSpacing.mockResolvedValue(frameSpacingData); 192 193 let physical = sqlite.queryPhysicalData; 194 let physicalData = [{ physicalFrameRate: 90, physicalHeight: 2772, physicalWidth: 1344 }]; 195 physical.mockResolvedValue(physicalData); 196 197 it('TabPaneFramesTest01', function () { 198 expect(spFrameTimeChart.init()).toBeTruthy(); 199 }); 200 201 it('TabPaneFramesTest02', function () { 202 FlagsConfig.updateFlagsConfig('AnimationAnalysis', 'Enabled'); 203 spFrameTimeChart.initAnimatedScenesChart( 204 TraceRow.skeleton(), 205 { 206 pid: 1, 207 processName: 'render_service', 208 }, 209 TraceRow.skeleton() 210 ); 211 }); 212 it('TabPaneFramesTest03', function () { 213 expect(spFrameTimeChart.frameNoExpandTimeOut()).toBeTruthy(); 214 }); 215 it('TabPaneFramesTest04', function () { 216 expect(spFrameTimeChart.frameExpandTimeOut()).toBeTruthy(); 217 }); 218}); 219