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