1/* 2 * Copyright (C) 2024 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 {assertDefined} from 'common/assert_utils'; 18import {TamperedMessageType} from 'parsers/tampered_message_type'; 19import root from 'protos/test/intdef_translation/json'; 20import {PropertyTreeBuilder} from 'test/unit/property_tree_builder'; 21import {PropertyTreeNode} from 'trace/tree_node/property_tree_node'; 22import {TranslateIntDef} from './translate_intdef'; 23 24describe('TranslateIntDef', () => { 25 let propertyRoot: PropertyTreeNode; 26 let operation: TranslateIntDef; 27 let rootType: TamperedMessageType; 28 29 beforeEach(() => { 30 rootType = TamperedMessageType.tamper(root.lookupType('RootMessage')); 31 }); 32 33 it('translates intdef from stored mapping', () => { 34 propertyRoot = new PropertyTreeBuilder() 35 .setIsRoot(true) 36 .setRootId('test') 37 .setName('node') 38 .setChildren([{name: 'layoutParamsFlags', value: 1}]) 39 .build(); 40 41 const field = rootType.fields['intdefMappingEntry']; 42 operation = new TranslateIntDef(field); 43 operation.apply(propertyRoot); 44 expect( 45 assertDefined( 46 propertyRoot.getChildByName('layoutParamsFlags'), 47 ).formattedValue(), 48 ).toEqual('FLAG_ALLOW_LOCK_WHILE_SCREEN_ON'); 49 }); 50 51 it('translates intdef from field mapping', () => { 52 propertyRoot = new PropertyTreeBuilder() 53 .setIsRoot(true) 54 .setRootId('test') 55 .setName('node') 56 .setChildren([ 57 { 58 name: 'windowLayoutParams', 59 value: undefined, 60 children: [ 61 {name: 'type', value: 1}, 62 {name: 'gravity', value: 1}, 63 {name: 'softInputMode', value: 1}, 64 {name: 'inputFeatureFlags', value: 1}, 65 {name: 'flags', value: 1}, 66 {name: 'systemUiVisibilityFlags', value: 1}, 67 {name: 'subtreeSystemUiVisibilityFlags', value: 1}, 68 {name: 'appearance', value: 1}, 69 {name: 'behavior', value: 1}, 70 ], 71 }, 72 ]) 73 .build(); 74 75 const field = rootType.fields['windowLayoutParams']; 76 operation = new TranslateIntDef(field); 77 operation.apply(propertyRoot); 78 79 const params = assertDefined( 80 propertyRoot.getChildByName('windowLayoutParams'), 81 ); 82 83 expect( 84 assertDefined(params.getChildByName('type')).formattedValue(), 85 ).toEqual('TYPE_BASE_APPLICATION'); 86 expect( 87 assertDefined(params.getChildByName('gravity')).formattedValue(), 88 ).toEqual('CENTER_HORIZONTAL'); 89 expect( 90 assertDefined(params.getChildByName('softInputMode')).formattedValue(), 91 ).toEqual('SOFT_INPUT_STATE_UNCHANGED'); 92 expect( 93 assertDefined( 94 params.getChildByName('inputFeatureFlags'), 95 ).formattedValue(), 96 ).toEqual('INPUT_FEATURE_NO_INPUT_CHANNEL'); 97 expect( 98 assertDefined(params.getChildByName('flags')).formattedValue(), 99 ).toEqual('FLAG_ALLOW_LOCK_WHILE_SCREEN_ON'); 100 expect( 101 assertDefined( 102 params.getChildByName('systemUiVisibilityFlags'), 103 ).formattedValue(), 104 ).toEqual('SYSTEM_UI_FLAG_LOW_PROFILE'); 105 expect( 106 assertDefined( 107 params.getChildByName('subtreeSystemUiVisibilityFlags'), 108 ).formattedValue(), 109 ).toEqual('SYSTEM_UI_FLAG_LOW_PROFILE'); 110 expect( 111 assertDefined(params.getChildByName('appearance')).formattedValue(), 112 ).toEqual('APPEARANCE_OPAQUE_STATUS_BARS'); 113 expect( 114 assertDefined(params.getChildByName('behavior')).formattedValue(), 115 ).toEqual('BEHAVIOR_DEFAULT'); 116 }); 117}); 118