blob: a2a20a9538fcb137a486a5bc79bab548add83ca9 [file] [log] [blame]
Fabian Kozynskia48d2d02019-02-27 11:36:02 -05001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.systemui.qs;
18
19import static org.mockito.ArgumentMatchers.anyInt;
20import static org.mockito.Mockito.mock;
21import static org.mockito.Mockito.when;
22
Fabian Kozynskibeeec062019-09-24 10:34:00 -040023import android.os.Handler;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050024import android.telephony.SubscriptionManager;
25import android.testing.AndroidTestingRunner;
26import android.testing.TestableLooper;
27import android.view.LayoutInflater;
28
29import androidx.test.filters.SmallTest;
30
31import com.android.keyguard.CarrierTextController;
Fabian Kozynskibeeec062019-09-24 10:34:00 -040032import com.android.systemui.Dependency;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050033import com.android.systemui.R;
34import com.android.systemui.statusbar.policy.NetworkController;
35import com.android.systemui.utils.leaks.LeakCheckedTest;
36
37import org.junit.Before;
38import org.junit.Test;
39import org.junit.runner.RunWith;
40import org.mockito.Mockito;
41import org.mockito.invocation.InvocationOnMock;
42import org.mockito.stubbing.Answer;
43
44@RunWith(AndroidTestingRunner.class)
45@TestableLooper.RunWithLooper
46@SmallTest
47public class QSCarrierGroupTest extends LeakCheckedTest {
48
49 private QSCarrierGroup mCarrierGroup;
Fabian Kozynskibeeec062019-09-24 10:34:00 -040050 private CarrierTextController.CarrierTextCallback mCallback;
51 private TestableLooper mTestableLooper;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050052
53 @Before
54 public void setup() throws Exception {
55 injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES);
Fabian Kozynskibeeec062019-09-24 10:34:00 -040056 mTestableLooper = TestableLooper.get(this);
57 mDependency.injectTestDependency(
58 Dependency.BG_HANDLER, new Handler(mTestableLooper.getLooper()));
59 mDependency.injectTestDependency(Dependency.MAIN_LOOPER, mTestableLooper.getLooper());
60 mTestableLooper.runWithLooper(
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050061 () -> mCarrierGroup = (QSCarrierGroup) LayoutInflater.from(mContext).inflate(
62 R.layout.qs_carrier_group, null));
Fabian Kozynskibeeec062019-09-24 10:34:00 -040063 mCallback = mCarrierGroup.getCallback();
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050064 }
65
66 @Test // throws no Exception
67 public void testUpdateCarrierText_sameLengths() {
68 QSCarrierGroup spiedCarrierGroup = Mockito.spy(mCarrierGroup);
69 when(spiedCarrierGroup.getSlotIndex(anyInt())).thenAnswer(
70 new Answer<Integer>() {
71 @Override
72 public Integer answer(InvocationOnMock invocationOnMock) throws Throwable {
73 return invocationOnMock.getArgument(0);
74 }
75 });
76
77 // listOfCarriers length 1, subscriptionIds length 1, anySims false
78 CarrierTextController.CarrierTextCallbackInfo
79 c1 = new CarrierTextController.CarrierTextCallbackInfo(
80 "",
81 new CharSequence[]{""},
82 false,
83 new int[]{0});
Fabian Kozynskibeeec062019-09-24 10:34:00 -040084 mCallback.updateCarrierInfo(c1);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050085
86 // listOfCarriers length 1, subscriptionIds length 1, anySims true
87 CarrierTextController.CarrierTextCallbackInfo
88 c2 = new CarrierTextController.CarrierTextCallbackInfo(
89 "",
90 new CharSequence[]{""},
91 true,
92 new int[]{0});
Fabian Kozynskibeeec062019-09-24 10:34:00 -040093 mCallback.updateCarrierInfo(c2);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050094
95 // listOfCarriers length 2, subscriptionIds length 2, anySims false
96 CarrierTextController.CarrierTextCallbackInfo
97 c3 = new CarrierTextController.CarrierTextCallbackInfo(
98 "",
99 new CharSequence[]{"", ""},
100 false,
101 new int[]{0, 1});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400102 mCallback.updateCarrierInfo(c3);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500103
104 // listOfCarriers length 2, subscriptionIds length 2, anySims true
105 CarrierTextController.CarrierTextCallbackInfo
106 c4 = new CarrierTextController.CarrierTextCallbackInfo(
107 "",
108 new CharSequence[]{"", ""},
109 true,
110 new int[]{0, 1});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400111 mCallback.updateCarrierInfo(c4);
112
113 mTestableLooper.processAllMessages();
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500114 }
115
116 @Test // throws no Exception
117 public void testUpdateCarrierText_differentLength() {
118 QSCarrierGroup spiedCarrierGroup = Mockito.spy(mCarrierGroup);
119 when(spiedCarrierGroup.getSlotIndex(anyInt())).thenAnswer(
120 new Answer<Integer>() {
121 @Override
122 public Integer answer(InvocationOnMock invocationOnMock) throws Throwable {
123 return invocationOnMock.getArgument(0);
124 }
125 });
126
127 // listOfCarriers length 2, subscriptionIds length 1, anySims false
128 CarrierTextController.CarrierTextCallbackInfo
129 c1 = new CarrierTextController.CarrierTextCallbackInfo(
130 "",
131 new CharSequence[]{"", ""},
132 false,
133 new int[]{0});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400134 mCallback.updateCarrierInfo(c1);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500135
136 // listOfCarriers length 2, subscriptionIds length 1, anySims true
137 CarrierTextController.CarrierTextCallbackInfo
138 c2 = new CarrierTextController.CarrierTextCallbackInfo(
139 "",
140 new CharSequence[]{"", ""},
141 true,
142 new int[]{0});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400143 mCallback.updateCarrierInfo(c2);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500144
145 // listOfCarriers length 1, subscriptionIds length 2, anySims false
146 CarrierTextController.CarrierTextCallbackInfo
147 c3 = new CarrierTextController.CarrierTextCallbackInfo(
148 "",
149 new CharSequence[]{""},
150 false,
151 new int[]{0, 1});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400152 mCallback.updateCarrierInfo(c3);
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500153
154 // listOfCarriers length 1, subscriptionIds length 2, anySims true
155 CarrierTextController.CarrierTextCallbackInfo
156 c4 = new CarrierTextController.CarrierTextCallbackInfo(
157 "",
158 new CharSequence[]{""},
159 true,
160 new int[]{0, 1});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400161 mCallback.updateCarrierInfo(c4);
162 mTestableLooper.processAllMessages();
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500163 }
164
165 @Test // throws no Exception
166 public void testUpdateCarrierText_invalidSim() {
167 QSCarrierGroup spiedCarrierGroup = Mockito.spy(mCarrierGroup);
168 when(spiedCarrierGroup.getSlotIndex(anyInt())).thenReturn(
169 SubscriptionManager.INVALID_SIM_SLOT_INDEX);
170 CarrierTextController.CarrierTextCallbackInfo
171 c4 = new CarrierTextController.CarrierTextCallbackInfo(
172 "",
173 new CharSequence[]{"", ""},
174 true,
175 new int[]{0, 1});
Fabian Kozynskibeeec062019-09-24 10:34:00 -0400176 mCallback.updateCarrierInfo(c4);
177 mTestableLooper.processAllMessages();
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500178 }
179
180 @Test // throws no Exception
181 public void testSetMobileDataIndicators_invalidSim() {
182 QSCarrierGroup spiedCarrierGroup = Mockito.spy(mCarrierGroup);
183 when(spiedCarrierGroup.getSlotIndex(anyInt())).thenReturn(
184 SubscriptionManager.INVALID_SIM_SLOT_INDEX);
185 spiedCarrierGroup.setMobileDataIndicators(
186 mock(NetworkController.IconState.class),
187 mock(NetworkController.IconState.class),
188 0, 0, true, true, "", "", true, 0, true);
189 }
190}