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