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 | 25a52b6 | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 25 | import android.support.test.filters.SmallTest; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 26 | import android.testing.AndroidTestingRunner; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 27 | import android.testing.LeakCheck.Tracker; |
Aaron Heuckroth | 96cd93f | 2018-11-20 11:14:40 -0500 | [diff] [blame] | 28 | import android.testing.TestableLooper.RunWithLooper; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 29 | import android.view.Display; |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 30 | import android.view.WindowManager; |
Aaron Heuckroth | 96cd93f | 2018-11-20 11:14:40 -0500 | [diff] [blame] | 31 | import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener; |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 32 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 33 | import com.android.internal.logging.MetricsLogger; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 34 | import com.android.systemui.Dependency; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 35 | import com.android.systemui.SysuiBaseFragmentTest; |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 36 | import com.android.systemui.assist.AssistManager; |
Aaron Heuckroth | 96cd93f | 2018-11-20 11:14:40 -0500 | [diff] [blame] | 37 | import com.android.systemui.recents.OverviewProxyService; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 38 | import com.android.systemui.recents.Recents; |
| 39 | import com.android.systemui.stackdivider.Divider; |
| 40 | import com.android.systemui.statusbar.CommandQueue; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 41 | import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper; |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 42 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 43 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 44 | import org.junit.Before; |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 45 | import org.junit.Test; |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 46 | import org.junit.runner.RunWith; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 47 | |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 48 | @RunWith(AndroidTestingRunner.class) |
Aaron Heuckroth | 96cd93f | 2018-11-20 11:14:40 -0500 | [diff] [blame] | 49 | @RunWithLooper() |
Jason Monk | 25a52b6 | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 50 | @SmallTest |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 51 | public class NavigationBarFragmentTest extends SysuiBaseFragmentTest { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 52 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 53 | private OverviewProxyService mOverviewProxyService = |
| 54 | mDependency.injectMockDependency(OverviewProxyService.class); |
| 55 | private AccessibilityManagerWrapper mAccessibilityWrapper = |
| 56 | new AccessibilityManagerWrapper(mContext) { |
| 57 | Tracker mTracker = mLeakCheck.getTracker("accessibility_manager"); |
| 58 | |
| 59 | @Override |
| 60 | public void addCallback(AccessibilityServicesStateChangeListener listener) { |
| 61 | mTracker.getLeakInfo(listener).addAllocation(new Throwable()); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public void removeCallback(AccessibilityServicesStateChangeListener listener) { |
| 66 | mTracker.getLeakInfo(listener).clearAllocations(); |
| 67 | } |
| 68 | }; |
| 69 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 70 | public NavigationBarFragmentTest() { |
| 71 | super(NavigationBarFragment.class); |
| 72 | } |
| 73 | |
Siarhei Vishniakou | 6ad0e39 | 2017-06-02 17:20:34 -0700 | [diff] [blame] | 74 | protected void createRootView() { |
| 75 | mView = new NavigationBarFrame(mContext); |
| 76 | } |
| 77 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 78 | @Before |
| 79 | public void setup() { |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 80 | mSysuiContext.putComponent(CommandQueue.class, mock(CommandQueue.class)); |
| 81 | mSysuiContext.putComponent(StatusBar.class, mock(StatusBar.class)); |
| 82 | mSysuiContext.putComponent(Recents.class, mock(Recents.class)); |
| 83 | mSysuiContext.putComponent(Divider.class, mock(Divider.class)); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 84 | injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 85 | WindowManager windowManager = mock(WindowManager.class); |
| 86 | Display defaultDisplay = mContext.getSystemService(WindowManager.class).getDefaultDisplay(); |
| 87 | when(windowManager.getDefaultDisplay()).thenReturn( |
| 88 | defaultDisplay); |
| 89 | mContext.addMockSystemService(Context.WINDOW_SERVICE, windowManager); |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 90 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 91 | mDependency.injectTestDependency(Dependency.BG_LOOPER, Looper.getMainLooper()); |
| 92 | mDependency.injectTestDependency(AccessibilityManagerWrapper.class, mAccessibilityWrapper); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 93 | } |
| 94 | |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 95 | @Test |
| 96 | public void testHomeLongPress() { |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 97 | NavigationBarFragment navigationBarFragment = (NavigationBarFragment) mFragment; |
| 98 | |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 99 | mFragments.dispatchResume(); |
| 100 | processAllMessages(); |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 101 | navigationBarFragment.onHomeLongClick(navigationBarFragment.getView()); |
| 102 | } |
| 103 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 104 | @Override |
| 105 | protected Fragment instantiate(Context context, String className, Bundle arguments) { |
| 106 | DeviceProvisionedController deviceProvisionedController = |
Jason Monk | cfa61ff | 2018-12-21 13:15:26 -0500 | [diff] [blame] | 107 | mock(DeviceProvisionedController.class); |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 108 | assertNotNull(mAccessibilityWrapper); |
| 109 | return new NavigationBarFragment(mAccessibilityWrapper, |
| 110 | deviceProvisionedController, |
| 111 | new MetricsLogger(), |
| 112 | new AssistManager(deviceProvisionedController, mContext), |
| 113 | mOverviewProxyService); |
| 114 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 115 | } |