1/* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import {FunctionUtils} from 'common/function_utils'; 18import {WinscopeEvent} from 'messaging/winscope_event'; 19import {EmitEvent} from 'messaging/winscope_event_emitter'; 20import {Trace} from 'trace/trace'; 21import {View, Viewer, ViewType} from './viewer'; 22 23class ViewerStub implements Viewer { 24 private readonly traces: Array<Trace<object>> = []; 25 private htmlElement: HTMLElement; 26 private title: string; 27 private view: View; 28 private emitAppEvent: EmitEvent = FunctionUtils.DO_NOTHING_ASYNC; 29 30 constructor( 31 title: string, 32 viewContent?: string, 33 trace?: Trace<object>, 34 viewType?: ViewType, 35 ) { 36 this.title = title; 37 38 if (viewContent !== undefined) { 39 this.htmlElement = document.createElement('div'); 40 this.htmlElement.innerText = viewContent; 41 } else { 42 this.htmlElement = undefined as unknown as HTMLElement; 43 } 44 if (trace) this.traces = [trace]; 45 46 this.view = new View( 47 viewType ?? ViewType.TRACE_TAB, 48 this.getTraces(), 49 this.htmlElement, 50 this.title, 51 ); 52 } 53 54 onWinscopeEvent(event: WinscopeEvent): Promise<void> { 55 return Promise.resolve(); 56 } 57 58 setEmitEvent(callback: EmitEvent) { 59 this.emitAppEvent = callback; 60 } 61 62 async emitAppEventForTesting(event: WinscopeEvent) { 63 await this.emitAppEvent(event); 64 } 65 66 getViews(): View[] { 67 return [this.view]; 68 } 69 70 getTraces(): Array<Trace<object>> { 71 return this.traces; 72 } 73} 74 75export {ViewerStub}; 76