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 */ 16import {assertDefined} from 'common/assert_utils'; 17import {UnitTestUtils} from 'test/unit/utils'; 18import {TraceType} from 'trace/trace_type'; 19import {ImeUtils} from './ime_utils'; 20 21describe('ImeUtils', () => { 22 it('processes WindowManager trace entry', async () => { 23 const entries = (await UnitTestUtils.getImeTraceEntries())[0]; 24 const processed = ImeUtils.processWindowManagerTraceEntry( 25 assertDefined(entries.get(TraceType.WINDOW_MANAGER)), 26 undefined, 27 ); 28 29 expect(processed.wmStateProperties.focusedApp).toEqual( 30 'com.google.android.apps.messaging/.ui.search.ZeroStateSearchActivity', 31 ); 32 33 expect(processed.wmStateProperties.focusedActivity).toEqual( 34 '{9d8c2ef com.google.android.apps.messaging/.ui.search.ZeroStateSearchActivity} state=RESUMED visible=true', 35 ); 36 37 expect(processed.wmStateProperties.focusedWindow).toEqual( 38 '{928b3d com.google.android.apps.messaging/com.google.android.apps.messaging.ui.search.ZeroStateSearchActivity EXITING} type=TYPE_BASE_APPLICATION cf={empty} pf=(0, 0) - (1080, 2400)', 39 ); 40 41 const imeControlTarget = assertDefined( 42 processed.wmStateProperties.imeControlTarget, 43 ); 44 45 expect( 46 imeControlTarget 47 .getChildByName('windowContainer') 48 ?.getChildByName('identifier') 49 ?.getChildByName('title') 50 ?.getValue(), 51 ).toEqual( 52 'com.google.android.apps.nexuslauncher/com.google.android.apps.nexuslauncher.NexusLauncherActivity', 53 ); 54 55 const imeInputTarget = assertDefined( 56 processed.wmStateProperties.imeInputTarget, 57 ); 58 expect( 59 imeInputTarget 60 .getChildByName('windowContainer') 61 ?.getChildByName('identifier') 62 ?.getChildByName('title') 63 ?.getValue(), 64 ).toEqual( 65 'com.google.android.apps.nexuslauncher/com.google.android.apps.nexuslauncher.NexusLauncherActivity', 66 ); 67 68 expect( 69 processed.wmStateProperties.imeInsetsSourceProvider?.getChildByName( 70 'insetsSourceProvider', 71 ), 72 ).toBeDefined(); 73 74 const imeLayeringTarget = assertDefined( 75 processed.wmStateProperties.imeLayeringTarget, 76 ); 77 expect( 78 imeLayeringTarget 79 .getChildByName('windowContainer') 80 ?.getChildByName('identifier') 81 ?.getChildByName('title') 82 ?.getValue(), 83 ).toEqual('SnapshotStartingWindow for taskId=1393'); 84 85 expect(processed.wmStateProperties.isInputMethodWindowVisible).toBeFalse(); 86 }); 87 88 it('processes SurfaceFlinger trace entry', async () => { 89 const entries = (await UnitTestUtils.getImeTraceEntries())[0]; 90 const processedWindowManagerState = ImeUtils.processWindowManagerTraceEntry( 91 assertDefined(entries.get(TraceType.WINDOW_MANAGER)), 92 undefined, 93 ); 94 const layers = assertDefined( 95 ImeUtils.getImeLayers( 96 assertDefined(entries.get(TraceType.SURFACE_FLINGER)), 97 processedWindowManagerState, 98 undefined, 99 ), 100 ); 101 102 const inputMethodSurface = assertDefined( 103 layers.properties.inputMethodSurface, 104 ); 105 const inputMethodSurfaceRect = assertDefined(inputMethodSurface.rect); 106 expect(inputMethodSurface.id).toEqual( 107 '280 Surface(name=77f1069 InputMethod)/@0xb4afb8f - animation-leash of insets_animation#280', 108 ); 109 expect(inputMethodSurface.isVisible).toEqual(false); 110 expect(inputMethodSurfaceRect.getChildByName('left')?.getValue()).toEqual( 111 -10800, 112 ); 113 expect(inputMethodSurfaceRect.getChildByName('top')?.getValue()).toEqual( 114 -24136, 115 ); 116 expect(inputMethodSurfaceRect.getChildByName('right')?.getValue()).toEqual( 117 10800, 118 ); 119 expect(inputMethodSurfaceRect.getChildByName('bottom')?.getValue()).toEqual( 120 23864, 121 ); 122 expect(inputMethodSurface.screenBounds).toBeDefined(); 123 124 const imeContainer = assertDefined(layers.properties.imeContainer); 125 expect(imeContainer.id).toEqual('12 ImeContainer#12'); 126 expect(imeContainer.z).toEqual(1); 127 expect(imeContainer.zOrderRelativeOfId).toEqual(115); 128 129 expect( 130 assertDefined(layers.properties.focusedWindowColor).formattedValue(), 131 ).toEqual('(0, 0, 0, 1)'); 132 133 const taskLayerOfImeContainer = assertDefined( 134 layers.taskLayerOfImeContainer, 135 ); 136 expect(taskLayerOfImeContainer.id).toEqual('114 Task=1391#114'); 137 expect(taskLayerOfImeContainer.name).toEqual('Task=1391#114'); 138 139 expect(layers.taskLayerOfImeSnapshot).toBeUndefined(); 140 }); 141}); 142