Jeff Chang | 2aaa91a | 2018-11-08 18:04:16 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
| 19 | import static org.junit.Assert.assertNotNull; |
| 20 | import static org.junit.Assert.assertTrue; |
| 21 | import static org.mockito.Mockito.mock; |
| 22 | |
| 23 | import android.graphics.PixelFormat; |
| 24 | import android.hardware.display.DisplayManager; |
| 25 | import android.hardware.display.VirtualDisplay; |
| 26 | import android.media.ImageReader; |
| 27 | import android.support.test.filters.SmallTest; |
| 28 | import android.testing.AndroidTestingRunner; |
| 29 | import android.testing.TestableLooper.RunWithLooper; |
| 30 | import android.view.Display; |
| 31 | import android.view.DisplayInfo; |
| 32 | |
| 33 | import com.android.systemui.SysuiTestCase; |
| 34 | import com.android.systemui.SysuiTestableContext; |
| 35 | import com.android.systemui.statusbar.CommandQueue; |
| 36 | |
| 37 | import org.junit.After; |
| 38 | import org.junit.Before; |
| 39 | import org.junit.Test; |
| 40 | import org.junit.runner.RunWith; |
| 41 | |
| 42 | /** atest NavigationBarButtonTest */ |
| 43 | @RunWith(AndroidTestingRunner.class) |
| 44 | @RunWithLooper |
| 45 | @SmallTest |
| 46 | public 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 | |