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