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 {UnitTestUtils} from 'test/unit/utils'; 17import {TraceType} from 'trace/trace_type'; 18import {ImeUtils} from './ime_utils'; 19 20describe('ImeUtils', () => { 21 it('processes WindowManager trace entry', async () => { 22 const entries = await UnitTestUtils.getImeTraceEntries(); 23 const processed = ImeUtils.processWindowManagerTraceEntry( 24 entries.get(TraceType.WINDOW_MANAGER) 25 ); 26 27 expect(processed.focusedApp).toEqual( 28 'com.google.android.apps.messaging/.ui.search.ZeroStateSearchActivity' 29 ); 30 31 expect(processed.focusedActivity.token).toEqual('9d8c2ef'); 32 expect(processed.focusedActivity.layerId).toEqual(260); 33 34 expect(processed.focusedWindow.token).toEqual('928b3d'); 35 expect(processed.focusedWindow.title).toEqual( 36 'com.google.android.apps.messaging/com.google.android.apps.messaging.ui.search.ZeroStateSearchActivity' 37 ); 38 39 expect(processed.protoImeControlTarget.windowContainer.identifier.title).toEqual( 40 'com.google.android.apps.nexuslauncher/com.google.android.apps.nexuslauncher.NexusLauncherActivity' 41 ); 42 expect(processed.protoImeControlTarget.windowContainer.identifier.hashCode).toEqual(247026562); 43 44 expect(processed.protoImeInputTarget.windowContainer.identifier.title).toEqual( 45 'com.google.android.apps.nexuslauncher/com.google.android.apps.nexuslauncher.NexusLauncherActivity' 46 ); 47 expect(processed.protoImeInputTarget.windowContainer.identifier.hashCode).toEqual(247026562); 48 49 expect(processed.protoImeInsetsSourceProvider.insetsSourceProvider).toBeDefined(); 50 51 expect(processed.protoImeLayeringTarget.windowContainer.identifier.title).toEqual( 52 'SnapshotStartingWindow for taskId=1393' 53 ); 54 expect(processed.protoImeLayeringTarget.windowContainer.identifier.hashCode).toEqual(222907471); 55 56 expect(processed.isInputMethodWindowVisible).toBeFalse(); 57 }); 58 59 it('processes SurfaceFlinger trace entry', async () => { 60 const entries = await UnitTestUtils.getImeTraceEntries(); 61 const processedWindowManagerState = ImeUtils.processWindowManagerTraceEntry( 62 entries.get(TraceType.WINDOW_MANAGER) 63 ); 64 const layers = ImeUtils.getImeLayers( 65 entries.get(TraceType.SURFACE_FLINGER), 66 processedWindowManagerState 67 )!; 68 69 expect(layers.inputMethodSurface.id).toEqual(280); 70 expect(layers.inputMethodSurface.isVisible).toEqual(false); 71 expect(layers.inputMethodSurface.rect.label).toEqual( 72 'Surface(name=77f1069 InputMethod)/@0xb4afb8f - animation-leash of insets_animation#280' 73 ); 74 expect(layers.inputMethodSurface.screenBounds).toBeDefined(); 75 76 expect(layers.imeContainer.id).toEqual(12); 77 expect(layers.imeContainer.z).toEqual(1); 78 expect(layers.imeContainer.zOrderRelativeOfId).toEqual(115); 79 80 expect(String(layers.focusedWindow.color)).toEqual('r:0 g:0 b:0 a:1'); 81 82 expect(layers.taskOfImeContainer.kind).toEqual('SF subtree - 114'); 83 expect(layers.taskOfImeContainer.name).toEqual('Task=1391#114'); 84 85 expect(layers.taskOfImeSnapshot).toBeUndefined(); 86 }); 87}); 88