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/component/trace/TimerShaftElement', () => { 17 return { 18 sportRuler: { 19 frame: { 20 contains: {} 21 } 22 }, 23 canvas: { 24 offsetLeft: 0 25 }, 26 isScaling: true, 27 displayCollect: ()=>{}, 28 removeEventListener: ()=>{}, 29 drawTriangle: ()=>{}, 30 setSlicesMark: ()=>{}, 31 removeTriangle: ()=>{}, 32 }; 33}); 34jest.mock('../../../src/trace/component/trace/base/TraceSheet', () => { 35 return { 36 clearMemory: () => {} 37 }; 38}); 39import { SpSystemTrace } from '../../../src/trace/component/SpSystemTrace'; 40import { TraceRow } from '../../../src/trace/component/trace/base/TraceRow'; 41import { RangeSelect } from '../../../src/trace/component/trace/base/RangeSelect'; 42 43jest.mock('../../../src/base-ui/table/lit-table', () => { 44 return { 45 recycleDataSource: () => { 46 }, 47 }; 48}); 49jest.mock('../../../src/js-heap/logic/HeapLoader', () => { 50 return {}; 51}); 52jest.mock('../../../src/js-heap/model/DatabaseStruct', () => { 53 return {}; 54}); 55jest.mock('../../../src/trace/database/SqlLite'); 56 57const intersectionObserverMock = () => ({ 58 observe: () => null, 59}); 60window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock); 61 62// @ts-ignore 63window.ResizeObserver = 64 window.ResizeObserver || 65 jest.fn().mockImplementation(() => ({ 66 disconnect: jest.fn(), 67 observe: jest.fn(), 68 unobserve: jest.fn(), 69 })); 70 71describe('SpSystemTrace Test', () => { 72 let spSystemTrace = new SpSystemTrace<any>({ 73 canvasNumber: 1, 74 alpha: true, 75 contextId: '2d', 76 isOffScreen: true, 77 }); 78 const offset = 1; 79 const callback = true; 80 const rowId = ''; 81 const rowParentId = ''; 82 const rowType = ''; 83 let smooth = true; 84 spSystemTrace.searchCPU = jest.fn(); 85 spSystemTrace.initElements = jest.fn(() => true); 86 87 it('SpSystemTraceTest01', function () { 88 expect(spSystemTrace.getScrollWidth()).toBe(0); 89 }); 90 91 it('SpSystemTraceTest02', function () { 92 let resultLength = spSystemTrace.getRowsContentHeight(); 93 expect(resultLength).toBe(0); 94 }); 95 96 it('SpSystemTraceTest03', function () { 97 expect(spSystemTrace.timerShaftELRangeChange('')).toBeUndefined(); 98 }); 99 100 it('SpSystemTraceTest04', function () { 101 expect(spSystemTrace.rowsElOnScroll({ 102 target: { 103 scrollTop: {} 104 } 105 })).toBeUndefined(); 106 }); 107 108 it('SpSystemTraceTest05', function () { 109 expect(spSystemTrace.documentOnMouseDown('MouseDown')).toBeUndefined(); 110 }); 111 112 it('SpSystemTraceTest06', function () { 113 spSystemTrace.documentOnMouseUp = jest.fn(() => true); 114 expect(spSystemTrace.documentOnMouseUp('MouseUp')).toBeTruthy(); 115 }); 116 117 it('SpSystemTraceTest07', function () { 118 expect(spSystemTrace.documentOnMouseMove('MouseMove')).toBeUndefined(); 119 }); 120 121 it('SpSystemTraceTest08', function () { 122 expect(spSystemTrace.hoverStructNull()).not.toBeUndefined(); 123 }); 124 125 it('SpSystemTraceTest09', function () { 126 expect(spSystemTrace.selectStructNull()).not.toBeUndefined(); 127 }); 128 129 it('SpSystemTraceTest11', function () { 130 expect(spSystemTrace.connectedCallback()).toBeUndefined(); 131 }); 132 133 it('SpSystemTraceTest12', function () { 134 expect(spSystemTrace.disconnectedCallback()).toBeUndefined(); 135 }); 136 137 it('SpSystemTraceTest14', function () { 138 expect(spSystemTrace.loadDatabaseUrl).toBeTruthy(); 139 }); 140 141 it('SpSystemTraceTest15', function () { 142 spSystemTrace.rowsPaneEL = jest.fn(() => true); 143 spSystemTrace.rowsPaneEL.scrollTo = jest.fn(() => offset); 144 spSystemTrace.rowsPaneEL.removeEventListener = jest.fn(() => true); 145 spSystemTrace.rowsPaneEL.addEventListener = jest.fn(() => true); 146 let funcStract = { 147 dur: 152, 148 totalNS: 4252, 149 startTs: 522, 150 flag: '', 151 funName: 'binder async' 152 } 153 expect(spSystemTrace.scrollToActFunc(funcStract, true)).toBeUndefined(); 154 }); 155 156 it('SpSystemTraceTest16', function () { 157 expect(spSystemTrace.onClickHandler()).toBeUndefined(); 158 }); 159 160 it('SpSystemTraceTest17', function () { 161 expect(spSystemTrace.search()).toBeUndefined(); 162 }); 163 164 it('SpSystemTraceTest22', function () { 165 spSystemTrace.traceSheetEL!.clearMemory = jest.fn(() => true); 166 spSystemTrace.traceSheetEL.setMode = jest.fn(() => true); 167 spSystemTrace.rangeSelect = new RangeSelect(spSystemTrace); 168 spSystemTrace.timerShaftEL!.displayCollect = jest.fn(() => true); 169 spSystemTrace.timerShaftEL!.collecBtn = jest.fn(() => {}); 170 spSystemTrace.timerShaftEL!.reset = jest.fn(() => {}); 171 spSystemTrace.timerShaftEL!.collecBtn.removeAttribute = jest.fn(() => {}); 172 expect(spSystemTrace.reset(()=>{})).toBeUndefined(); 173 }); 174 it('SpSystemTraceTest23', function () { 175 let structs = [ 176 { 177 length: 1, 178 starttime: 1, 179 }, 180 ]; 181 let previous = 1; 182 let currentIndex = 1; 183 TraceRow.range = jest.fn(() => undefined); 184 TraceRow.range.startNS = jest.fn(() => 1); 185 spSystemTrace.timerShaftEL.drawTriangle = jest.fn(()=>{}); 186 expect(spSystemTrace.showStruct(previous, currentIndex, structs)).not.toBeUndefined(); 187 }); 188 it('SpSystemTraceTest24', function () { 189 TraceRow.range = jest.fn(() => undefined); 190 TraceRow.range.startNS = jest.fn(() => 1); 191 expect(spSystemTrace.closeAllExpandRows()).toBeUndefined(); 192 }); 193 it('SpSystemTraceTest25', function () { 194 spSystemTrace.rowsPaneEL = jest.fn(() => true); 195 spSystemTrace.rowsPaneEL.scroll = jest.fn(() => true); 196 expect(spSystemTrace.scrollToProcess()).toBeUndefined(); 197 }); 198 it('SpSystemTraceTest26', function () { 199 spSystemTrace.rowsPaneEL = jest.fn(() => true); 200 spSystemTrace.rowsPaneEL.scroll = jest.fn(() => true); 201 let anomalyTraceRow = TraceRow.skeleton(); 202 anomalyTraceRow.collect = true; 203 spSystemTrace.appendChild(anomalyTraceRow); 204 expect(spSystemTrace.scrollToDepth()).toBeUndefined(); 205 }); 206 it('SpSystemTraceTest28', function () { 207 expect(spSystemTrace.refreshFavoriteCanvas()).toBeUndefined(); 208 }); 209 it('SpSystemTraceTest29', function () { 210 expect(spSystemTrace.expansionAllParentRow({id: 1})).toBeUndefined(); 211 }); 212 it('SpSystemTraceTest30', function () { 213 let it = { 214 name: '', 215 rowType: '', 216 rowId: 'FileSystemLogicalWrite', 217 rowParentId: 'frameTime', 218 }; 219 expect(spSystemTrace.createPointEvent(it)).toBe(''); 220 }); 221 it('SpSystemTraceTest31', function () { 222 let a = { 223 rowEL: { 224 translateY: 1, 225 offsetTop: 0, 226 }, 227 y: 1, 228 offsetY: 0, 229 }; 230 let b = { 231 rowEL: { 232 translateY: 1, 233 offsetTop: 0, 234 }, 235 y: 1, 236 offsetY: 0, 237 }; 238 expect(spSystemTrace.addPointPair(a, b)).toBeUndefined(); 239 }); 240 it('SpSystemTraceTest32', function () { 241 spSystemTrace.timerShaftEL.setSlicesMark = jest.fn(()=>{}) 242 expect(spSystemTrace.setSLiceMark()).toBeUndefined(); 243 }); 244 it('SpSystemTraceTest33', function () { 245 spSystemTrace.rangeSelect = new RangeSelect(spSystemTrace); 246 spSystemTrace.timerShaftEL.removeTriangle = jest.fn(()=>{}) 247 expect(spSystemTrace.clickEmptyArea()).toBeUndefined(); 248 }); 249 it('SpSystemTraceTest34', function () { 250 expect(spSystemTrace.isWASDKeyPress()).toBeFalsy(); 251 }); 252 it('SpSystemTraceTest35', function () { 253 let selectJankStruct = { 254 frame_type: 'frameTime', 255 type: '', 256 pid: 1, 257 ts: 1, 258 dur: 0, 259 depth: 1, 260 }; 261 let data = { 262 frame_type: 'frameTime', 263 type: '', 264 pid: 1, 265 name: '', 266 children: { 267 frame_type: 'frameTime', 268 pid: 1, 269 length: 1, 270 }, 271 }; 272 273 expect(spSystemTrace.drawJankLine(null, selectJankStruct, data)).toBeUndefined(); 274 }); 275 it('SpSystemTraceTest36', function () { 276 let ev = { 277 maxDuration: 1, 278 timestamp: '', 279 }; 280 spSystemTrace.rangeSelect = new RangeSelect(spSystemTrace); 281 spSystemTrace.traceSheetEL.setMode = jest.fn(() => true); 282 expect(spSystemTrace.sliceMarkEventHandler(ev)).toBeUndefined(); 283 }); 284 it('SpSystemTraceTest37', function () { 285 expect(spSystemTrace.searchSdk([''], '')).toStrictEqual(['']); 286 }); 287 it('SpSystemTraceTest38', function () { 288 let funcStract = { 289 tid: 1, 290 pid: 0, 291 cookie: '', 292 funName: '', 293 type: '', 294 startTime: 2, 295 depth: 1, 296 }; 297 expect(spSystemTrace.scrollToActFunc(funcStract, true)).toBeUndefined(); 298 }); 299}); 300