Fix WifiSummaryUpdaterTest issues for registerReceiver security design
- Security team add new interface to Context.registerReceiver() with a third parameter for new security design. - The new interface might have some issues in the test environment. - Spy the registerReceiver() and unregisterReceiver() to avoid unexpected issues. Bug: 214938188 Test: manual test make RunSettingsRoboTests ROBOTEST_FILTER=WifiSummaryUpdaterTest Change-Id: Ibd1c5c1f7b4309ad5079f33bb232f249c6bd997f
This commit is contained in:
@@ -19,7 +19,11 @@ package com.android.settings.wifi;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -34,7 +38,6 @@ import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
|
||||
import com.android.settingslib.wifi.WifiStatusTracker;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -54,15 +57,18 @@ public class WifiSummaryUpdaterTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
|
||||
doReturn(mock(Intent.class)).when(mContext).registerReceiver(any(), any(), anyInt());
|
||||
doNothing().when(mContext).unregisterReceiver(any(BroadcastReceiver.class));
|
||||
|
||||
mSummaryUpdater = new WifiSummaryUpdater(mContext, mListener, mWifiTracker);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void register_true_shouldRegisterListenerAndTracker() {
|
||||
mSummaryUpdater.register(true);
|
||||
|
||||
verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class));
|
||||
verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class),
|
||||
anyInt());
|
||||
verify(mWifiTracker).setListening(true);
|
||||
}
|
||||
|
||||
@@ -75,7 +81,6 @@ public class WifiSummaryUpdaterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void register_false_shouldUnregisterListenerAndTracker() {
|
||||
mSummaryUpdater.register(true);
|
||||
mSummaryUpdater.register(false);
|
||||
|
Reference in New Issue
Block a user