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 {browser, by, element} from 'protractor';
18import {E2eTestUtils} from './utils';
19
20describe('Viewer Input Method Clients', () => {
21  const viewerSelector = 'viewer-input-method';
22
23  beforeEach(async () => {
24    browser.manage().timeouts().implicitlyWait(1000);
25    await E2eTestUtils.checkServerIsUp('Winscope', E2eTestUtils.WINSCOPE_URL);
26    await browser.get(E2eTestUtils.WINSCOPE_URL);
27  });
28
29  it('processes trace from zip and navigates correctly', async () => {
30    await E2eTestUtils.loadTraceAndCheckViewer(
31      'traces/deployment_full_trace_phone.zip',
32      'IME Clients',
33      viewerSelector,
34    );
35    await E2eTestUtils.checkTimelineTraceSelector({
36      icon: 'keyboard_alt',
37      color: 'rgba(250, 144, 62, 1)',
38    });
39    await E2eTestUtils.checkInitialRealTimestamp('2022-11-21, 18:05:11.145');
40    await E2eTestUtils.checkFinalRealTimestamp('2022-11-21, 18:05:18.245');
41
42    await E2eTestUtils.changeRealTimestampInWinscope(
43      '2022-11-21, 18:05:14.969',
44    );
45    await E2eTestUtils.checkWinscopeRealTimestamp('18:05:14.969');
46
47    await checkAdditionalProperties();
48    await clickWmState();
49    await checkWmStateProperties();
50    await clickImeContainer();
51    await checkImeContainerProperties();
52    await clickInputMethodSurface();
53    await checkInputMethodSurfaceProperties();
54
55    await E2eTestUtils.applyStateToHierarchyOptions(viewerSelector, true);
56    await checkHierarchy();
57    await E2eTestUtils.selectItemInHierarchy(viewerSelector, 'InputMethod#765');
58    await checkInputMethodLayerProperties();
59  });
60
61  async function checkHierarchy() {
62    const nodes = await element.all(
63      by.css(`${viewerSelector} hierarchy-view .node`),
64    );
65    expect(nodes.length).toEqual(5);
66    expect(await nodes[0].getText()).toContain(
67      'InputMethodClients - 2022-11-21, 18:05:14.969 - InsetsSourceConsumer#notifyAnimationFinished',
68    );
69    expect(await nodes[1].getText()).toContain('253 - SfSubtree - Task=8#253');
70    expect(await nodes[2].getText()).toContain(
71      '778 - Letterbox - left#778 HWC V',
72    );
73    expect(await nodes[3].getText()).toContain(
74      '786 - com.google.(...).ZeroStateSearchActivity#786 HWC V',
75    );
76    expect(await nodes[4].getText()).toContain('765 - InputMethod#765 HWC V');
77  }
78
79  async function checkInputMethodLayerProperties() {
80    await E2eTestUtils.checkItemInPropertiesTree(
81      viewerSelector,
82      'activeBuffer',
83      'activeBuffer:\nw: 1006, h: 2204, stride: 268437760, format: 1',
84    );
85
86    await E2eTestUtils.checkItemInPropertiesTree(
87      viewerSelector,
88      'bufferTransform',
89      'bufferTransform:\nROT_270',
90    );
91
92    await E2eTestUtils.checkItemInPropertiesTree(
93      viewerSelector,
94      'hwcCompositionType',
95      'hwcCompositionType:\nDEVICE',
96    );
97
98    await E2eTestUtils.checkItemInPropertiesTree(
99      viewerSelector,
100      'bounds',
101      'bounds:\n(0, 0) - (2204, 1006)',
102    );
103  }
104
105  async function checkAdditionalProperties() {
106    const additionalProperties = element(by.css('ime-additional-properties'));
107    expect(await additionalProperties.isPresent()).toBeTruthy();
108
109    const sfState = additionalProperties.element(by.css('.sf-state'));
110    const sfStateTimestamp = await sfState.getText();
111    expect(sfStateTimestamp).toEqual('2022-11-21, 18:05:14.902');
112
113    const wmState = additionalProperties.element(by.css('.wm-state'));
114    const wmStateTimestamp = await wmState.getText();
115    expect(wmStateTimestamp).toEqual('2022-11-21, 18:05:14.896');
116
117    const focusSection = additionalProperties.element(by.css('.focus'));
118    const focusSectionText = await focusSection.getText();
119    expect(focusSectionText).toContain(
120      'Focused App: com.google.android.apps.messaging/.ui.search.ZeroStateSearchActivity',
121    );
122    expect(focusSectionText).toContain(
123      'Focused Activity: {8170434 com.google.android.apps.messaging/.ui.search.ZeroStateSearchActivity} state=RESUMED visible=true',
124    );
125    expect(focusSectionText).toContain(
126      'Focused Window: {25d7778 com.google.android.apps.messaging/com.google.android.apps.messaging.ui.search.ZeroStateSearchActivity EXITING} type=TYPE_BASE_APPLICATION cf={empty} pf=(136, 0) - (2340, 1080)',
127    );
128    expect(focusSectionText).toContain(
129      'Focused Window Color: {empty}, alpha: 1',
130    );
131    expect(focusSectionText).toContain(
132      'Input Control Target Frame:\nLeft\nTop\nRight\nBottom\n136\n0\n2340\n1080',
133    );
134
135    const visibilitySection = additionalProperties.element(
136      by.css('.visibility'),
137    );
138    const visibilitySectionText = await visibilitySection.getText();
139    expect(visibilitySectionText).toEqual(
140      'Visibility\nInputMethod Window: true\nInputMethod Surface: false',
141    );
142
143    const imeContainer = additionalProperties.element(by.css('.ime-container'));
144    const imeContainerText = await imeContainer.getText();
145    expect(imeContainerText).toEqual(
146      'Ime Container\nZOrderRelativeOfId: 780\nZ: 1',
147    );
148
149    const inputMethodSurface = additionalProperties.element(
150      by.css('.input-method-surface'),
151    );
152    const inputMethodSurfaceText = await inputMethodSurface.getText();
153    expect(inputMethodSurfaceText).toContain(
154      'Screen Bounds:\nLeft\nTop\nRight\nBottom\n-10800\n-23400\n10800\n23400',
155    );
156    expect(inputMethodSurfaceText).toContain(
157      'Rect:\nLeft\nTop\nRight\nBottom\n-10936\n-23548\n10664\n23252',
158    );
159  }
160
161  async function clickWmState() {
162    const wmStateButton = element(
163      by.css('ime-additional-properties .wm-state-button'),
164    );
165    await wmStateButton.click();
166  }
167
168  async function checkWmStateProperties() {
169    await E2eTestUtils.checkItemInPropertiesTree(
170      viewerSelector,
171      'screenState',
172      'screenState:\nSCREEN_STATE_ON',
173    );
174
175    await E2eTestUtils.checkItemInPropertiesTree(
176      viewerSelector,
177      'windowFramesValid',
178      'windowFramesValid:\ntrue',
179    );
180  }
181
182  async function clickImeContainer() {
183    const imeStateButton = element(
184      by.css('ime-additional-properties .ime-container-button'),
185    );
186    await imeStateButton.click();
187  }
188
189  async function checkImeContainerProperties() {
190    await E2eTestUtils.checkItemInPropertiesTree(
191      viewerSelector,
192      'id',
193      'id:\n12',
194    );
195
196    await E2eTestUtils.checkItemInPropertiesTree(
197      viewerSelector,
198      'bounds',
199      'bounds:\n(-10800, -23400) - (10800, 23400)',
200    );
201  }
202
203  async function clickInputMethodSurface() {
204    const imeStateButton = element(
205      by.css('ime-additional-properties .input-method-surface-button'),
206    );
207    await imeStateButton.click();
208  }
209
210  async function checkInputMethodSurfaceProperties() {
211    await E2eTestUtils.checkItemInPropertiesTree(
212      viewerSelector,
213      'id',
214      'id:\n795',
215    );
216
217    await E2eTestUtils.checkItemInPropertiesTree(
218      viewerSelector,
219      'position',
220      'position:\nx: 136, y: 148',
221    );
222
223    await E2eTestUtils.checkItemInPropertiesTree(
224      viewerSelector,
225      'transform',
226      'transform:\nTRANSLATE',
227    );
228  }
229});
230