Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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.qs; |
| 16 | |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 17 | import static org.junit.Assert.assertEquals; |
Jason Monk | 64b214e | 2017-03-27 13:40:59 -0400 | [diff] [blame] | 18 | import static org.junit.Assert.assertTrue; |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 19 | import static org.mockito.Mockito.mock; |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 20 | |
Jason Monk | 48f85be | 2018-12-19 15:16:44 -0500 | [diff] [blame] | 21 | import android.app.Fragment; |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 22 | import android.content.Context; |
Jason Monk | 48f85be | 2018-12-19 15:16:44 -0500 | [diff] [blame] | 23 | import android.os.Bundle; |
Jason Monk | 5d57720 | 2018-12-26 15:43:06 -0500 | [diff] [blame] | 24 | import android.os.Handler; |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 25 | import android.os.Looper; |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 26 | import android.testing.AndroidTestingRunner; |
| 27 | import android.testing.LayoutInflaterBuilder; |
| 28 | import android.testing.TestableLooper; |
| 29 | import android.testing.TestableLooper.RunWithLooper; |
| 30 | import android.view.View; |
| 31 | import android.widget.FrameLayout; |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 32 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 33 | import androidx.test.filters.SmallTest; |
| 34 | |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 35 | import com.android.internal.logging.MetricsLogger; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 36 | import com.android.keyguard.CarrierText; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 37 | import com.android.systemui.Dependency; |
Fabian Kozynski | 00d494d | 2019-04-04 09:53:50 -0400 | [diff] [blame] | 38 | import com.android.systemui.DumpController; |
Jason Monk | 89377bb | 2016-12-08 15:29:34 -0500 | [diff] [blame] | 39 | import com.android.systemui.R; |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 40 | import com.android.systemui.SystemUIFactory; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 41 | import com.android.systemui.SysuiBaseFragmentTest; |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 42 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Jason Monk | 5d57720 | 2018-12-26 15:43:06 -0500 | [diff] [blame] | 43 | import com.android.systemui.qs.tileimpl.QSFactoryImpl; |
Jason Monk | 30b64fa | 2018-12-27 13:19:34 -0500 | [diff] [blame] | 44 | import com.android.systemui.shared.plugins.PluginManager; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 45 | import com.android.systemui.statusbar.CommandQueue; |
Jason Monk | a26641f | 2018-12-27 14:20:53 -0500 | [diff] [blame] | 46 | import com.android.systemui.statusbar.phone.AutoTileManager; |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 47 | import com.android.systemui.statusbar.phone.StatusBarIconController; |
Jason Monk | 1660a27 | 2017-04-28 15:53:59 -0400 | [diff] [blame] | 48 | import com.android.systemui.statusbar.policy.Clock; |
Jason Monk | eeff95b | 2018-12-21 12:54:37 -0500 | [diff] [blame] | 49 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Jason Monk | 48f85be | 2018-12-19 15:16:44 -0500 | [diff] [blame] | 50 | import com.android.systemui.statusbar.policy.RemoteInputQuickSettingsDisabler; |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 51 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
Jason Monk | 30b64fa | 2018-12-27 13:19:34 -0500 | [diff] [blame] | 52 | import com.android.systemui.tuner.TunerService; |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 53 | import com.android.systemui.util.InjectionInflationController; |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 54 | |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 55 | import org.junit.Before; |
Geoffrey Pitsch | 351a321 | 2017-05-22 15:20:20 -0400 | [diff] [blame] | 56 | import org.junit.Ignore; |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 57 | import org.junit.Test; |
| 58 | import org.junit.runner.RunWith; |
| 59 | |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 60 | @RunWith(AndroidTestingRunner.class) |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 61 | @RunWithLooper |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 62 | @SmallTest |
Julien Desprez | 7e8798c1b | 2019-02-08 20:12:28 +0000 | [diff] [blame] | 63 | @Ignore |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 64 | public class QSFragmentTest extends SysuiBaseFragmentTest { |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 65 | |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 66 | private MetricsLogger mMockMetricsLogger; |
| 67 | |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 68 | public QSFragmentTest() { |
| 69 | super(QSFragment.class); |
Jason Monk | 48f85be | 2018-12-19 15:16:44 -0500 | [diff] [blame] | 70 | injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 73 | @Before |
Alison Cichowlas | 5d7d959 | 2018-07-17 15:30:28 -0400 | [diff] [blame] | 74 | @Ignore("failing") |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 75 | public void addLeakCheckDependencies() { |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 76 | mMockMetricsLogger = mDependency.injectMockDependency(MetricsLogger.class); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 77 | mContext.addMockSystemService(Context.LAYOUT_INFLATER_SERVICE, |
| 78 | new LayoutInflaterBuilder(mContext) |
| 79 | .replace("com.android.systemui.statusbar.policy.SplitClockView", |
| 80 | FrameLayout.class) |
| 81 | .replace("TextClock", View.class) |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 82 | .replace(CarrierText.class, View.class) |
Jason Monk | 1660a27 | 2017-04-28 15:53:59 -0400 | [diff] [blame] | 83 | .replace(Clock.class, View.class) |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 84 | .build()); |
| 85 | |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 86 | mDependency.injectTestDependency(Dependency.BG_LOOPER, |
| 87 | TestableLooper.get(this).getLooper()); |
| 88 | mDependency.injectMockDependency(UserSwitcherController.class); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 89 | } |
| 90 | |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 91 | @Test |
Alison Cichowlas | 5d7d959 | 2018-07-17 15:30:28 -0400 | [diff] [blame] | 92 | @Ignore("failing") |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 93 | public void testListening() { |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 94 | assertEquals(Looper.myLooper(), Looper.getMainLooper()); |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 95 | QSFragment qs = (QSFragment) mFragment; |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 96 | mFragments.dispatchResume(); |
| 97 | processAllMessages(); |
Jason Monk | 5d57720 | 2018-12-26 15:43:06 -0500 | [diff] [blame] | 98 | QSTileHost host = new QSTileHost(mContext, mock(StatusBarIconController.class), |
Jason Monk | 30b64fa | 2018-12-27 13:19:34 -0500 | [diff] [blame] | 99 | mock(QSFactoryImpl.class), new Handler(), Looper.myLooper(), |
Jason Monk | a26641f | 2018-12-27 14:20:53 -0500 | [diff] [blame] | 100 | mock(PluginManager.class), mock(TunerService.class), |
Fabian Kozynski | 00d494d | 2019-04-04 09:53:50 -0400 | [diff] [blame] | 101 | () -> mock(AutoTileManager.class), mock(DumpController.class)); |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 102 | qs.setHost(host); |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 103 | |
| 104 | qs.setListening(true); |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 105 | processAllMessages(); |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 106 | |
| 107 | qs.setListening(false); |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 108 | processAllMessages(); |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 109 | |
Jason Monk | 89377bb | 2016-12-08 15:29:34 -0500 | [diff] [blame] | 110 | // Manually push header through detach so it can handle standard cleanup it does on |
| 111 | // removed from window. |
| 112 | ((QuickStatusBarHeader) qs.getView().findViewById(R.id.header)).onDetachedFromWindow(); |
| 113 | |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 114 | host.destroy(); |
Jason Monk | 28d5d22 | 2017-02-02 13:08:31 -0500 | [diff] [blame] | 115 | processAllMessages(); |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 116 | } |
Jason Monk | 64b214e | 2017-03-27 13:40:59 -0400 | [diff] [blame] | 117 | |
| 118 | @Test |
Alison Cichowlas | 5d7d959 | 2018-07-17 15:30:28 -0400 | [diff] [blame] | 119 | @Ignore("failing") |
Jason Monk | 64b214e | 2017-03-27 13:40:59 -0400 | [diff] [blame] | 120 | public void testSaveState() { |
| 121 | QSFragment qs = (QSFragment) mFragment; |
| 122 | |
| 123 | mFragments.dispatchResume(); |
| 124 | processAllMessages(); |
| 125 | |
| 126 | qs.setListening(true); |
| 127 | qs.setExpanded(true); |
| 128 | processAllMessages(); |
| 129 | recreateFragment(); |
| 130 | processAllMessages(); |
| 131 | |
| 132 | // Get the reference to the new fragment. |
| 133 | qs = (QSFragment) mFragment; |
| 134 | assertTrue(qs.isListening()); |
| 135 | assertTrue(qs.isExpanded()); |
| 136 | } |
Jason Monk | 48f85be | 2018-12-19 15:16:44 -0500 | [diff] [blame] | 137 | |
| 138 | @Override |
| 139 | protected Fragment instantiate(Context context, String className, Bundle arguments) { |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 140 | CommandQueue commandQueue = new CommandQueue(context); |
Jason Monk | eeff95b | 2018-12-21 12:54:37 -0500 | [diff] [blame] | 141 | return new QSFragment( |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 142 | new RemoteInputQuickSettingsDisabler(context, mock(ConfigurationController.class), |
| 143 | commandQueue), |
Jason Monk | 8966d99 | 2018-12-20 14:16:29 -0500 | [diff] [blame] | 144 | new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent()), |
Jason Monk | 5d57720 | 2018-12-26 15:43:06 -0500 | [diff] [blame] | 145 | context, |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 146 | mock(QSTileHost.class), |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 147 | mock(StatusBarStateController.class), |
| 148 | commandQueue); |
Jason Monk | 48f85be | 2018-12-19 15:16:44 -0500 | [diff] [blame] | 149 | } |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 150 | } |