• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16// @ts-ignore
17import {SpSystemTrace} from "../../../dist/trace/component/SpSystemTrace.js";
18// @ts-ignore
19import {TraceRow} from "../../../dist/trace/component/trace/base/TraceRow";
20// @ts-ignore
21import {procedurePool} from "../../../dist/trace/database/Procedure.js"
22
23window.ResizeObserver = window.ResizeObserver ||
24    jest.fn().mockImplementation(() => ({
25        disconnect: jest.fn(),
26        observe: jest.fn(),
27        unobserve: jest.fn(),
28    }));
29
30describe('SpSystemTrace Test', ()=>{
31    let spSystemTrace = new SpSystemTrace();
32    const offset = 1
33    const callback=true
34    const rowId=""
35    const rowParentId=""
36    const rowType=""
37    let smooth=true
38
39    spSystemTrace.initElements = jest.fn(()=> true)
40
41
42    it('SpSystemTraceTest01', function () {
43        expect(spSystemTrace.getScrollWidth()).toBe(0)
44    });
45
46    it('SpSystemTraceTest02', function () {
47        let resultLength = spSystemTrace.getVisibleRows([{}]).length;
48        expect(resultLength).toBe(0)
49    });
50
51    it('SpSystemTraceTest03', function () {
52        expect(spSystemTrace.timerShaftELRangeChange('')).toBeUndefined()
53    });
54
55    it('SpSystemTraceTest04', function () {
56        expect(spSystemTrace.rowsElOnScroll('Scroll')).toBeUndefined()
57    });
58
59    it('SpSystemTraceTest05', function () {
60        expect(spSystemTrace.documentOnMouseDown('MouseDown')).toBeUndefined()
61    });
62
63    it('SpSystemTraceTest06', function () {
64        spSystemTrace.timerShaftEL = jest.fn(()=>null)
65        spSystemTrace.timerShaftEL.sportRuler = jest.fn(()=>undefined)
66        spSystemTrace.timerShaftEL.sportRuler.frame = jest.fn(()=>"")
67        spSystemTrace.timerShaftEL.canvas = jest.fn(()=> undefined)
68        spSystemTrace.timerShaftEL.canvas.offsetLeft = jest.fn(()=>1)
69        spSystemTrace.timerShaftEL.sportRuler.frame.contains = jest.fn(()=>true)
70        spSystemTrace.documentOnMouseUp = jest.fn(()=>true)
71        expect(spSystemTrace.documentOnMouseUp('MouseUp')).toBeTruthy()
72    });
73
74    it('SpSystemTraceTest07', function () {
75        spSystemTrace.timerShaftEL = jest.fn(()=>undefined)
76        spSystemTrace.timerShaftEL.isScaling = jest.fn(()=>true)
77        expect(spSystemTrace.documentOnMouseMove('MouseMove')).toBeUndefined()
78    });
79
80    it('SpSystemTraceTest08', function () {
81        expect(spSystemTrace.hoverStructNull('')).toBeUndefined()
82    });
83
84    it('SpSystemTraceTest09', function () {
85        expect(spSystemTrace.selectStructNull('')).toBeUndefined()
86    });
87
88    it('SpSystemTraceTest11', function () {
89        expect(spSystemTrace.connectedCallback()).toBeUndefined()
90    });
91
92    it('SpSystemTraceTest12', function () {
93        spSystemTrace.timerShaftEL.removeEventListener = jest.fn(()=>true)
94        expect(spSystemTrace.disconnectedCallback()).toBeUndefined()
95    });
96
97    it('SpSystemTraceTest14', function () {
98        expect(spSystemTrace.loadDatabaseUrl).toBeTruthy()
99    });
100
101    it('SpSystemTraceTest15', function () {
102        spSystemTrace.rowsEL = jest.fn(()=>true)
103        spSystemTrace.rowsEL.scrollTo = jest.fn(()=>offset)
104        spSystemTrace.rowsEL.removeEventListener = jest.fn(()=>true)
105        spSystemTrace.rowsEL.addEventListener = jest.fn(()=>true)
106        expect(spSystemTrace.rowScrollTo(offset,callback)).toBeUndefined()
107    });
108
109    it('SpSystemTraceTest16', function () {
110        let spSystemTrace = new SpSystemTrace<any>({canvasNumber:1,alpha: true, contextId: '2d', isOffScreen: true});
111        expect(spSystemTrace.onClickHandler()).toBeUndefined()
112    });
113
114    it('SpSystemTraceTest17', function () {
115        let spSystemTrace = new SpSystemTrace<any>({canvasNumber:1,alpha: true, contextId: '2d', isOffScreen: true});
116        expect(spSystemTrace.search()).toBeUndefined()
117    });
118
119    it('SpSystemTraceTest18', function () {
120        let spSystemTrace = new SpSystemTrace<any>({canvasNumber:1,alpha: true, contextId: '2d', isOffScreen: true});
121        expect(spSystemTrace.searchCPU()).not.toBeUndefined()
122    });
123
124    it('SpSystemTraceTest19', function () {
125        expect(spSystemTrace.initHtml()).toMatchInlineSnapshot(`
126"
127        <style>
128        :host{
129            display: block;
130            width: 100%;
131            height: 100%;
132        }
133        .timer-shaft{
134            width: 100%;
135            z-index: 2;
136        }
137        .rows{
138            color: #fff;
139            display: block;
140            box-sizing: border-box;
141            /*flex-direction: column;*/
142            /*overflow-y: auto;*/
143            overflow: overlay;
144            overflow-anchor: none;
145            max-height: calc(100vh - 147px - 48px);
146            flex: 1;
147            width: 100%;
148            background: var(--dark-background4,#ffffff);
149            /*scroll-behavior: smooth;*/
150        }
151        .container{
152            width: 100%;
153            box-sizing: border-box;
154            height: 100%;
155            display: grid;
156            grid-template-columns: 1fr;
157            grid-template-rows: min-content min-content 1fr min-content;
158        }
159        .trace-sheet{
160            cursor: default;
161        }
162
163        </style>
164        <div class=\\"container\\">
165            <timer-shaft-element class=\\"timer-shaft\\">
166            </timer-shaft-element>
167            <div class=\\"spacer\\"></div>
168            <div class=\\"rows\\"></div>
169            <trace-sheet class=\\"trace-sheet\\" mode=\\"hidden\\">
170            </trace-sheet>
171        </div>
172        "
173`);
174    });
175
176    it('SpSystemTraceTest20', function () {
177        let spSystemTrace = new SpSystemTrace<any>({canvasNumber:1,alpha: true, contextId: '2d', isOffScreen: true});
178        // @ts-ignore
179        TraceRow.range = jest.fn(()=>undefined)
180        TraceRow.range.startNS = jest.fn(()=>1)
181        spSystemTrace.onClickHandler = jest.fn(()=>true)
182        expect(spSystemTrace.showPreCpuStruct(1,[{length:0}])).toBe(0)
183    });
184
185    it('SpSystemTraceTest21', function () {
186        let spSystemTrace = new SpSystemTrace<any>({canvasNumber:1,alpha: true, contextId: '2d', isOffScreen: true});
187        // @ts-ignore
188        TraceRow.range = jest.fn(()=>undefined)
189        TraceRow.range.startNS = jest.fn(()=>1)
190        spSystemTrace.onClickHandler = jest.fn(()=>true)
191        expect(spSystemTrace.showNextCpuStruct(1,[{length:0}])).toBe(0)
192    });
193
194    it('SpSystemTraceTest22', function () {
195        let spSystemTrace = new SpSystemTrace<any>({canvasNumber:1,alpha: true, contextId: '2d', isOffScreen: true});
196        procedurePool.clearCache = jest.fn(()=>true)
197        expect(spSystemTrace.reset()).toBeUndefined()
198    });
199    it('SpSystemTraceTest23', function () {
200        let spSystemTrace = new SpSystemTrace<any>({canvasNumber:1,alpha: true, contextId: '2d', isOffScreen: true});
201        let structs = [{
202            length:1,
203            starttime:1,
204        }]
205        let previous = 1;
206        let currentIndex = 1;
207        TraceRow.range = jest.fn(()=>undefined)
208        TraceRow.range.startNS = jest.fn(()=>1)
209        expect(spSystemTrace.showStruct(previous, currentIndex, structs)).not.toBeUndefined()
210    });
211    it('SpSystemTraceTest24', function () {
212        let spSystemTrace = new SpSystemTrace<any>({canvasNumber:1,alpha: true, contextId: '2d', isOffScreen: true});
213        TraceRow.range = jest.fn(()=>undefined)
214        TraceRow.range.startNS = jest.fn(()=>1)
215        expect(spSystemTrace.closeAllExpandRows()).toBeUndefined()
216    });
217    it('SpSystemTraceTest25', function () {
218        let spSystemTrace = new SpSystemTrace<any>({canvasNumber:1,alpha: true, contextId: '2d', isOffScreen: true});
219        spSystemTrace.rowsEL = jest.fn(()=>true)
220        spSystemTrace.rowsEL.scroll = jest.fn(()=>true)
221        expect(spSystemTrace.scrollToProcess()).toBeUndefined()
222    });
223    it('SpSystemTraceTest26', function () {
224        let spSystemTrace = new SpSystemTrace<any>({canvasNumber:1,alpha: true, contextId: '2d', isOffScreen: true});
225        spSystemTrace.rowsEL = jest.fn(()=>true)
226        spSystemTrace.rowsEL.scroll = jest.fn(()=>true)
227        expect(spSystemTrace.scrollToDepth()).toBeUndefined()
228    });
229    it('SpSystemTraceTest27', function () {
230        let spSystemTrace = new SpSystemTrace<any>({canvasNumber:1,alpha: true, contextId: '2d', isOffScreen: true});
231        expect(spSystemTrace.searchThreadsAndProcesses()).toStrictEqual([])
232    });
233})
234