blob: 73f3b43aad62283dfa52d7832c961834fdafdd33 [file] [log] [blame]
Jeff Chang2aaa91a2018-11-08 18:04:16 +08001/*
2 * Copyright (C) 2018 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
17package com.android.systemui.statusbar.phone;
18
19import static org.junit.Assert.assertNotNull;
20import static org.junit.Assert.assertTrue;
21import static org.mockito.Mockito.mock;
22
23import android.graphics.PixelFormat;
24import android.hardware.display.DisplayManager;
25import android.hardware.display.VirtualDisplay;
26import android.media.ImageReader;
27import android.support.test.filters.SmallTest;
28import android.testing.AndroidTestingRunner;
29import android.testing.TestableLooper.RunWithLooper;
30import android.view.Display;
31import android.view.DisplayInfo;
32
33import com.android.systemui.SysuiTestCase;
34import com.android.systemui.SysuiTestableContext;
35import com.android.systemui.statusbar.CommandQueue;
36
37import org.junit.After;
38import org.junit.Before;
39import org.junit.Test;
40import org.junit.runner.RunWith;
41
42/** atest NavigationBarButtonTest */
43@RunWith(AndroidTestingRunner.class)
44@RunWithLooper
45@SmallTest
46public class NavigationBarButtonTest extends SysuiTestCase {
47
48 private ImageReader mReader;
49 private NavigationBarView mNavBar;
50 private VirtualDisplay mVirtualDisplay;
51
52 @Before
53 public void setup() {
54 final Display display = createVirtualDisplay();
55 final SysuiTestableContext context =
56 (SysuiTestableContext) mContext.createDisplayContext(display);
57 context.putComponent(CommandQueue.class, mock(CommandQueue.class));
58
59 mNavBar = new NavigationBarView(context, null);
60 }
61
62 private Display createVirtualDisplay() {
63 final String displayName = "NavVirtualDisplay";
64 final DisplayInfo displayInfo = new DisplayInfo();
65 mContext.getDisplay().getDisplayInfo(displayInfo);
66
67 final DisplayManager displayManager = mContext.getSystemService(DisplayManager.class);
68
69 mReader = ImageReader.newInstance(displayInfo.logicalWidth,
70 displayInfo.logicalHeight, PixelFormat.RGBA_8888, 2);
71
72 assertNotNull("ImageReader must not be null", mReader);
73
74 mVirtualDisplay = displayManager.createVirtualDisplay(displayName, displayInfo.logicalWidth,
75 displayInfo.logicalHeight, displayInfo.logicalDensityDpi, mReader.getSurface(),
76 0 /*flags*/);
77
78 assertNotNull("virtual display must not be null", mVirtualDisplay);
79
80 return mVirtualDisplay.getDisplay();
81 }
82
83 @After
84 public void tearDown() {
85 releaseDisplay();
86 }
87
88 private void releaseDisplay() {
89 mVirtualDisplay.release();
90 mReader.close();
91 }
92
93 @Test
94 public void testRecentsButtonDisabledOnSecondaryDisplay() {
95 assertTrue("The recents button must be disabled",
96 mNavBar.isRecentsButtonDisabled());
97 }
98}
99
100
101