• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {TraceBuilder} from 'test/unit/trace_builder';
21import {Trace} from 'trace/trace';
22import {TraceType} from 'trace/trace_type';
23import {View, Viewer, ViewType} from './viewer';
24
25class ViewerStub implements Viewer {
26  private readonly trace: Trace<object>;
27  private htmlElement: HTMLElement;
28  private title: string;
29  private view: View;
30  private emitAppEvent: EmitEvent = FunctionUtils.DO_NOTHING_ASYNC;
31
32  constructor(
33    title: string,
34    viewContent?: string,
35    trace?: Trace<object>,
36    viewType?: ViewType,
37  ) {
38    this.title = title;
39
40    if (viewContent !== undefined) {
41      this.htmlElement = document.createElement('div');
42      this.htmlElement.innerText = viewContent;
43    } else {
44      this.htmlElement = undefined as unknown as HTMLElement;
45    }
46
47    this.trace =
48      trace ??
49      new TraceBuilder<object>().setType(TraceType.WINDOW_MANAGER).build();
50
51    this.view = new View(
52      viewType ?? ViewType.TAB,
53      this.getTraces(),
54      this.htmlElement,
55      this.title,
56    );
57  }
58
59  onWinscopeEvent(event: WinscopeEvent): Promise<void> {
60    return Promise.resolve();
61  }
62
63  setEmitEvent(callback: EmitEvent) {
64    this.emitAppEvent = callback;
65  }
66
67  async emitAppEventForTesting(event: WinscopeEvent) {
68    await this.emitAppEvent(event);
69  }
70
71  getViews(): View[] {
72    return [this.view];
73  }
74
75  getTraces(): Array<Trace<object>> {
76    return [this.trace];
77  }
78}
79
80export {ViewerStub};
81