Debian Codegraph @

apct-tests/perftests/core/src/android/view/ViewPerfTest.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2016 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
17 package android.view;
18
19 import static junit.framework.Assert.assertTrue;
20
21 import android.content.Context;
22 import android.perftests.utils.PerfTestActivity;
23 import android.widget.FrameLayout;
24
25 import androidx.benchmark.BenchmarkState;
26 import androidx.benchmark.junit4.BenchmarkRule;
27 import androidx.test.InstrumentationRegistry;
28 import androidx.test.filters.LargeTest;
29 import androidx.test.rule.ActivityTestRule;
30
31 import com.android.perftests.core.R;
32
33 import org.junit.Before;
34 import org.junit.Rule;
35 import org.junit.Test;
36
37 @LargeTest
38 public class ViewPerfTest {
39 @Rule
40 public final BenchmarkRule mBenchmarkRule = new BenchmarkRule();
41
42 @Rule
43 public final ActivityTestRule<PerfTestActivity> mActivityRule =
44 new ActivityTestRule<>(PerfTestActivity.class);
45
46 private Context mContext;
47
48 @Before
49 public void setUp() {
50 mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
51 }
52
53 @Test
54 public void testSimpleViewInflate() {
55 final BenchmarkState state = mBenchmarkRule.getState();
56 LayoutInflater inflater = LayoutInflater.from(mContext);
57 FrameLayout root = new FrameLayout(mContext);
58 while (state.keepRunning()) {
59 inflater.inflate(R.layout.test_simple_view, root, false);
60 }
61 }
62
63 @Test
64 public void testTwelveKeyInflate() {
65 final BenchmarkState state = mBenchmarkRule.getState();
66 LayoutInflater inflater = LayoutInflater.from(mContext);
67 FrameLayout root = new FrameLayout(mContext);
68 while (state.keepRunning()) {
69 inflater.inflate(R.layout.twelve_key_entry, root, false);
70 }
71 }
72
73 @Test
74 public void testPerformHapticFeedback() throws Throwable {
75 final BenchmarkState state = mBenchmarkRule.getState();
76 mActivityRule.runOnUiThread(() -> {
77 state.pauseTiming();
78 View view = new View(mContext);
79 mActivityRule.getActivity().setContentView(view);
80 assertTrue("View needs to be attached to Window to perform haptic feedback",
81 view.isAttachedToWindow());
82 state.resumeTiming();
83
84 // Disable settings so perform will never be ignored.
85 int flags = HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING
86 | HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING;
87
88 while (state.keepRunning()) {
89 assertTrue("Call to performHapticFeedback was ignored",
90 view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_PRESS, flags));
91 }
92 });
93 }
94 }