Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.statusbar.phone; |
| 16 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 17 | import static org.junit.Assert.assertNotNull; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 18 | import static org.mockito.Mockito.mock; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 19 | import static org.mockito.Mockito.when; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 20 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 21 | import android.app.Fragment; |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 22 | import android.content.Context; |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 23 | import android.os.Bundle; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 24 | import android.os.Looper; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 25 | import android.testing.AndroidTestingRunner; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 26 | import android.testing.LeakCheck.Tracker; |
Aaron Heuckroth | 96cd93f | 2018-11-20 11:14:40 -0500 | [diff] [blame] | 27 | import android.testing.TestableLooper.RunWithLooper; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 28 | import android.view.Display; |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 29 | import android.view.WindowManager; |
Aaron Heuckroth | 96cd93f | 2018-11-20 11:14:40 -0500 | [diff] [blame] | 30 | import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener; |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 31 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 32 | import androidx.test.filters.SmallTest; |
| 33 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 34 | import com.android.internal.logging.MetricsLogger; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 35 | import com.android.systemui.Dependency; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 36 | import com.android.systemui.SysuiBaseFragmentTest; |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 37 | import com.android.systemui.assist.AssistManager; |
Aaron Heuckroth | 96cd93f | 2018-11-20 11:14:40 -0500 | [diff] [blame] | 38 | import com.android.systemui.recents.OverviewProxyService; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 39 | import com.android.systemui.recents.Recents; |
| 40 | import com.android.systemui.stackdivider.Divider; |
| 41 | import com.android.systemui.statusbar.CommandQueue; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 42 | import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper; |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 43 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 44 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 45 | import org.junit.Before; |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 46 | import org.junit.Test; |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 47 | import org.junit.runner.RunWith; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 48 | |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 49 | @RunWith(AndroidTestingRunner.class) |
Aaron Heuckroth | 96cd93f | 2018-11-20 11:14:40 -0500 | [diff] [blame] | 50 | @RunWithLooper() |
Jason Monk | 25a52b6 | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 51 | @SmallTest |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 52 | public class NavigationBarFragmentTest extends SysuiBaseFragmentTest { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 53 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 54 | private OverviewProxyService mOverviewProxyService = |
| 55 | mDependency.injectMockDependency(OverviewProxyService.class); |
| 56 | private AccessibilityManagerWrapper mAccessibilityWrapper = |
| 57 | new AccessibilityManagerWrapper(mContext) { |
| 58 | Tracker mTracker = mLeakCheck.getTracker("accessibility_manager"); |
| 59 | |
| 60 | @Override |
| 61 | public void addCallback(AccessibilityServicesStateChangeListener listener) { |
| 62 | mTracker.getLeakInfo(listener).addAllocation(new Throwable()); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public void removeCallback(AccessibilityServicesStateChangeListener listener) { |
| 67 | mTracker.getLeakInfo(listener).clearAllocations(); |
| 68 | } |
| 69 | }; |
| 70 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 71 | public NavigationBarFragmentTest() { |
| 72 | super(NavigationBarFragment.class); |
| 73 | } |
| 74 | |
Siarhei Vishniakou | 6ad0e39 | 2017-06-02 17:20:34 -0700 | [diff] [blame] | 75 | protected void createRootView() { |
| 76 | mView = new NavigationBarFrame(mContext); |
| 77 | } |
| 78 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 79 | @Before |
| 80 | public void setup() { |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 81 | mSysuiContext.putComponent(CommandQueue.class, mock(CommandQueue.class)); |
| 82 | mSysuiContext.putComponent(StatusBar.class, mock(StatusBar.class)); |
| 83 | mSysuiContext.putComponent(Recents.class, mock(Recents.class)); |
| 84 | mSysuiContext.putComponent(Divider.class, mock(Divider.class)); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 85 | injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 86 | WindowManager windowManager = mock(WindowManager.class); |
| 87 | Display defaultDisplay = mContext.getSystemService(WindowManager.class).getDefaultDisplay(); |
| 88 | when(windowManager.getDefaultDisplay()).thenReturn( |
| 89 | defaultDisplay); |
| 90 | mContext.addMockSystemService(Context.WINDOW_SERVICE, windowManager); |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 91 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 92 | mDependency.injectTestDependency(Dependency.BG_LOOPER, Looper.getMainLooper()); |
| 93 | mDependency.injectTestDependency(AccessibilityManagerWrapper.class, mAccessibilityWrapper); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 94 | } |
| 95 | |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 96 | @Test |
| 97 | public void testHomeLongPress() { |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 98 | NavigationBarFragment navigationBarFragment = (NavigationBarFragment) mFragment; |
| 99 | |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 100 | mFragments.dispatchResume(); |
| 101 | processAllMessages(); |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 102 | navigationBarFragment.onHomeLongClick(navigationBarFragment.getView()); |
| 103 | } |
| 104 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 105 | @Override |
| 106 | protected Fragment instantiate(Context context, String className, Bundle arguments) { |
| 107 | DeviceProvisionedController deviceProvisionedController = |
Jason Monk | cfa61ff | 2018-12-21 13:15:26 -0500 | [diff] [blame] | 108 | mock(DeviceProvisionedController.class); |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 109 | assertNotNull(mAccessibilityWrapper); |
| 110 | return new NavigationBarFragment(mAccessibilityWrapper, |
| 111 | deviceProvisionedController, |
| 112 | new MetricsLogger(), |
| 113 | new AssistManager(deviceProvisionedController, mContext), |
| 114 | mOverviewProxyService); |
| 115 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 116 | } |