xref: /aosp_15_r20/development/tools/winscope/src/parsers/operations/translate_intdef_test.ts (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
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  it('translates BigInt', () => {
119    propertyRoot = new PropertyTreeBuilder()
120      .setIsRoot(true)
121      .setRootId('test')
122      .setName('node')
123      .setChildren([{name: 'layoutParamsFlags', value: 1n}])
124      .build();
125
126    const field = rootType.fields['intdefMappingEntry'];
127    operation = new TranslateIntDef(field);
128    operation.apply(propertyRoot);
129    expect(
130      assertDefined(
131        propertyRoot.getChildByName('layoutParamsFlags'),
132      ).formattedValue(),
133    ).toEqual('FLAG_ALLOW_LOCK_WHILE_SCREEN_ON');
134  });
135
136  it('formats leftover', () => {
137    propertyRoot = new PropertyTreeBuilder()
138      .setIsRoot(true)
139      .setRootId('test')
140      .setName('node')
141      .setChildren([{name: 'inputConfig', value: 3}])
142      .build();
143
144    const field = rootType.fields['intdefMappingEntry'];
145    operation = new TranslateIntDef(field);
146    operation.apply(propertyRoot);
147    expect(
148      assertDefined(
149        propertyRoot.getChildByName('inputConfig'),
150      ).formattedValue(),
151    ).toEqual('NO_INPUT_CHANNEL | 2');
152  });
153});
154