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