blob: 374a73c1d451584a2437d43320cd812be735132f [file] [log] [blame]
Jason Monkcd74f692017-03-27 11:17:04 -04001/*
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
15package com.android.systemui.qs;
16
17import static org.mockito.ArgumentMatchers.any;
18import static org.mockito.ArgumentMatchers.anyBoolean;
Fabian Kozynskibf6fef32019-02-04 09:21:38 -050019import static org.mockito.ArgumentMatchers.anyInt;
20import static org.mockito.Mockito.mock;
Jason Monkcd74f692017-03-27 11:17:04 -040021import static org.mockito.Mockito.never;
22import static org.mockito.Mockito.verify;
23import static org.mockito.Mockito.when;
24
Jason Monkfba8faf2017-05-23 10:42:59 -040025import android.support.test.filters.SmallTest;
Fabian Kozynskibf6fef32019-02-04 09:21:38 -050026import android.telephony.SubscriptionManager;
Jason Monkcd74f692017-03-27 11:17:04 -040027import android.testing.AndroidTestingRunner;
28import android.testing.TestableLooper;
29import android.testing.TestableLooper.RunWithLooper;
30import android.view.LayoutInflater;
31import android.view.View;
32
Fabian Kozynskibf6fef32019-02-04 09:21:38 -050033import com.android.keyguard.CarrierTextController.CarrierTextCallbackInfo;
Jason Monkcd74f692017-03-27 11:17:04 -040034import com.android.systemui.R;
35import com.android.systemui.R.id;
36import com.android.systemui.plugins.ActivityStarter;
37import com.android.systemui.statusbar.policy.DeviceProvisionedController;
Fabian Kozynskibf6fef32019-02-04 09:21:38 -050038import com.android.systemui.statusbar.policy.NetworkController;
Jason Monkcd74f692017-03-27 11:17:04 -040039import com.android.systemui.utils.leaks.LeakCheckedTest;
40
41import org.junit.Before;
Geoffrey Pitsch351a3212017-05-22 15:20:20 -040042import org.junit.Ignore;
Jason Monkcd74f692017-03-27 11:17:04 -040043import org.junit.Test;
44import org.junit.runner.RunWith;
Fabian Kozynskibf6fef32019-02-04 09:21:38 -050045import org.mockito.Mockito;
46import org.mockito.invocation.InvocationOnMock;
47import org.mockito.stubbing.Answer;
Jason Monkcd74f692017-03-27 11:17:04 -040048
49@RunWith(AndroidTestingRunner.class)
50@RunWithLooper
Jason Monkfba8faf2017-05-23 10:42:59 -040051@SmallTest
Anthony Chen54daefe2017-04-07 17:19:54 -070052public class QSFooterImplTest extends LeakCheckedTest {
Jason Monkcd74f692017-03-27 11:17:04 -040053
Anthony Chen54daefe2017-04-07 17:19:54 -070054 private QSFooterImpl mFooter;
Jason Monkcd74f692017-03-27 11:17:04 -040055 private ActivityStarter mActivityStarter;
56 private DeviceProvisionedController mDeviceProvisionedController;
57
58 @Before
59 public void setup() throws Exception {
60 injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES);
61 mActivityStarter = mDependency.injectMockDependency(ActivityStarter.class);
62 mDeviceProvisionedController = mDependency.injectMockDependency(
63 DeviceProvisionedController.class);
Anthony Chen54daefe2017-04-07 17:19:54 -070064 TestableLooper.get(this).runWithLooper(
65 () -> mFooter = (QSFooterImpl) LayoutInflater.from(mContext).inflate(
66 R.layout.qs_footer_impl, null));
Jason Monkcd74f692017-03-27 11:17:04 -040067 }
68
69 @Test
Alison Cichowlas5d7d9592018-07-17 15:30:28 -040070 @Ignore("failing")
Jason Monkcd74f692017-03-27 11:17:04 -040071 public void testSettings_UserNotSetup() {
72 View settingsButton = mFooter.findViewById(id.settings_button);
73 when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(false);
74
75 mFooter.onClick(settingsButton);
76 // Verify Settings wasn't launched.
77 verify(mActivityStarter, never()).startActivity(any(), anyBoolean());
78 }
Fabian Kozynskibf6fef32019-02-04 09:21:38 -050079
80 @Test // throws no Exception
81 public void testUpdateCarrierText_sameLengts() {
82 QSFooterImpl spiedFooter = Mockito.spy(mFooter);
83 when(spiedFooter.getSlotIndex(anyInt())).thenAnswer(
84 new Answer<Integer>() {
85 @Override
86 public Integer answer(InvocationOnMock invocationOnMock) throws Throwable {
87 return invocationOnMock.getArgument(0);
88 }
89 });
90
91 // listOfCarriers length 1, subscriptionIds length 1, anySims false
92 CarrierTextCallbackInfo c1 = new CarrierTextCallbackInfo(
93 "",
94 new CharSequence[]{""},
95 false,
96 new int[]{0});
97 spiedFooter.updateCarrierInfo(c1);
98
99 // listOfCarriers length 1, subscriptionIds length 1, anySims true
100 CarrierTextCallbackInfo c2 = new CarrierTextCallbackInfo(
101 "",
102 new CharSequence[]{""},
103 true,
104 new int[]{0});
105 spiedFooter.updateCarrierInfo(c2);
106
107 // listOfCarriers length 2, subscriptionIds length 2, anySims false
108 CarrierTextCallbackInfo c3 = new CarrierTextCallbackInfo(
109 "",
110 new CharSequence[]{"", ""},
111 false,
112 new int[]{0, 1});
113 spiedFooter.updateCarrierInfo(c3);
114
115 // listOfCarriers length 2, subscriptionIds length 2, anySims true
116 CarrierTextCallbackInfo c4 = new CarrierTextCallbackInfo(
117 "",
118 new CharSequence[]{"", ""},
119 true,
120 new int[]{0, 1});
121 spiedFooter.updateCarrierInfo(c4);
122 }
123
124 @Test // throws no Exception
125 public void testUpdateCarrierText_differentLength() {
126 QSFooterImpl spiedFooter = Mockito.spy(mFooter);
127 when(spiedFooter.getSlotIndex(anyInt())).thenAnswer(
128 new Answer<Integer>() {
129 @Override
130 public Integer answer(InvocationOnMock invocationOnMock) throws Throwable {
131 return invocationOnMock.getArgument(0);
132 }
133 });
134
135 // listOfCarriers length 2, subscriptionIds length 1, anySims false
136 CarrierTextCallbackInfo c1 = new CarrierTextCallbackInfo(
137 "",
138 new CharSequence[]{"", ""},
139 false,
140 new int[]{0});
141 spiedFooter.updateCarrierInfo(c1);
142
143 // listOfCarriers length 2, subscriptionIds length 1, anySims true
144 CarrierTextCallbackInfo c2 = new CarrierTextCallbackInfo(
145 "",
146 new CharSequence[]{"", ""},
147 true,
148 new int[]{0});
149 spiedFooter.updateCarrierInfo(c2);
150
151 // listOfCarriers length 1, subscriptionIds length 2, anySims false
152 CarrierTextCallbackInfo c3 = new CarrierTextCallbackInfo(
153 "",
154 new CharSequence[]{""},
155 false,
156 new int[]{0, 1});
157 spiedFooter.updateCarrierInfo(c3);
158
159 // listOfCarriers length 1, subscriptionIds length 2, anySims true
160 CarrierTextCallbackInfo c4 = new CarrierTextCallbackInfo(
161 "",
162 new CharSequence[]{""},
163 true,
164 new int[]{0, 1});
165 spiedFooter.updateCarrierInfo(c4);
166 }
167
168 @Test // throws no Exception
169 public void testUpdateCarrierText_invalidSim() {
170 QSFooterImpl spiedFooter = Mockito.spy(mFooter);
171 when(spiedFooter.getSlotIndex(anyInt())).thenReturn(
172 SubscriptionManager.INVALID_SIM_SLOT_INDEX);
173 CarrierTextCallbackInfo c4 = new CarrierTextCallbackInfo(
174 "",
175 new CharSequence[]{"", ""},
176 true,
177 new int[]{0, 1});
178 spiedFooter.updateCarrierInfo(c4);
179 }
180
181 @Test // throws no Exception
182 public void testSetMobileDataIndicators_invalidSim() {
183 QSFooterImpl spiedFooter = Mockito.spy(mFooter);
184 when(spiedFooter.getSlotIndex(anyInt())).thenReturn(
185 SubscriptionManager.INVALID_SIM_SLOT_INDEX);
186 spiedFooter.setMobileDataIndicators(
187 mock(NetworkController.IconState.class),
188 mock(NetworkController.IconState.class),
189 0, 0, true, true, "", "", true, 0, true);
190 }
191
Jason Monkcd74f692017-03-27 11:17:04 -0400192}