diff options
author | Weng Su <wengsu@google.com> | 2021-05-26 11:43:49 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-05-26 11:43:49 +0000 |
commit | 59f7b677fe104bcbc9615eaa2f2abba060d29343 (patch) | |
tree | b09c8fbeb5476e8fa8379977336e3270f6d8bbb0 /tests/unit | |
parent | 5b24943b0694dc9efe518d1df6b8175db504f936 (diff) | |
parent | 7b8c367d4f811d3d7a7ba4d2cc2edb14c15f5359 (diff) | |
download | Settings-59f7b677fe104bcbc9615eaa2f2abba060d29343.tar.gz |
Merge "[Provider model] Add "Turn off/on Wi-Fi" link to Internet Panel" into sc-dev
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/src/com/android/settings/network/TurnOnWifiSliceTest.java | 85 | ||||
-rw-r--r-- | tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java | 115 |
2 files changed, 44 insertions, 156 deletions
diff --git a/tests/unit/src/com/android/settings/network/TurnOnWifiSliceTest.java b/tests/unit/src/com/android/settings/network/TurnOnWifiSliceTest.java deleted file mode 100644 index befa655ce97..00000000000 --- a/tests/unit/src/com/android/settings/network/TurnOnWifiSliceTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.network; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import android.content.Context; -import android.content.Intent; -import android.net.wifi.WifiManager; - -import androidx.slice.SliceProvider; -import androidx.slice.widget.SliceLiveData; -import androidx.test.core.app.ApplicationProvider; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; - -@RunWith(AndroidJUnit4.class) -public class TurnOnWifiSliceTest { - - @Rule - public MockitoRule mMocks = MockitoJUnit.rule(); - @Mock - private WifiManager mWifiManager; - - private Context mContext; - private TurnOnWifiSlice mSlice; - - @Before - public void setUp() { - mContext = spy(ApplicationProvider.getApplicationContext()); - when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager); - - // Set-up specs for SliceMetadata. - SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS); - mSlice = new TurnOnWifiSlice(mContext); - } - - @Test - public void getSlice_wifiEnabled_shouldBeNull() { - when(mWifiManager.isWifiEnabled()).thenReturn(true); - - assertThat(mSlice.getSlice()).isNull(); - } - - @Test - public void getSlice_wifiDisabled_shouldBeNotNull() { - when(mWifiManager.isWifiEnabled()).thenReturn(false); - - assertThat(mSlice.getSlice()).isNotNull(); - } - - @Test - public void onNotifyChange_shouldSetWifiEnabled() { - Intent intent = mSlice.getIntent(); - - mSlice.onNotifyChange(intent); - - verify(mWifiManager).setWifiEnabled(true); - } -} diff --git a/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java b/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java index 150c99e2945..e475e6fe1db 100644 --- a/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java +++ b/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java @@ -34,6 +34,7 @@ import android.net.wifi.ScanResult; import android.net.wifi.WifiManager; import android.os.Handler; +import androidx.fragment.app.FragmentActivity; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; @@ -61,19 +62,22 @@ public class InternetConnectivityPanelTest { ApplicationProvider.getApplicationContext(), "provider_internet_settings"); public static final String TITLE_APM = ResourcesUtils.getResourcesString( ApplicationProvider.getApplicationContext(), "airplane_mode"); - public static final String SUBTITLE_WIFI_IS_TURNED_ON = ResourcesUtils.getResourcesString( - ApplicationProvider.getApplicationContext(), "wifi_is_turned_on_subtitle"); + public static final String SUBTITLE_TEXT_WIFI_IS_OFF = + ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(), + "wifi_is_off"); public static final String SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT = ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(), "tap_a_network_to_connect"); - public static final String BUTTON_SETTINGS = ResourcesUtils.getResourcesString( - ApplicationProvider.getApplicationContext(), "settings_button"); public static final String SUBTITLE_NON_CARRIER_NETWORK_UNAVAILABLE = ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(), "non_carrier_network_unavailable"); public static final String SUBTITLE_ALL_NETWORK_UNAVAILABLE = ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(), "all_network_unavailable"); + public static final String BUTTON_TURN_ON_WIFI = ResourcesUtils.getResourcesString( + ApplicationProvider.getApplicationContext(), "turn_on_wifi"); + public static final String BUTTON_TURN_OFF_WIFI = ResourcesUtils.getResourcesString( + ApplicationProvider.getApplicationContext(), "turn_off_wifi"); @Rule public final MockitoRule mMocks = MockitoJUnit.rule(); @@ -87,6 +91,8 @@ public class InternetConnectivityPanelTest { private WifiManager mWifiManager; @Mock private ProviderModelSliceHelper mProviderModelSliceHelper; + @Mock + private FragmentActivity mPanelActivity; private Context mContext; private InternetConnectivityPanel mPanel; @@ -128,13 +134,21 @@ public class InternetConnectivityPanelTest { } @Test - public void getSubTitle_apmOnWifiOn_shouldWifiIsTurnedOn() { + public void getSubTitle_apmOnWifiOn_shouldBeNull() { doReturn(true).when(mInternetUpdater).isAirplaneModeOn(); doReturn(true).when(mInternetUpdater).isWifiEnabled(); + assertThat(mPanel.getSubTitle()).isNull(); + } + + @Test + public void getSubTitle_apmOffWifiOff_wifiIsOn() { + doReturn(false).when(mInternetUpdater).isAirplaneModeOn(); + doReturn(false).when(mInternetUpdater).isWifiEnabled(); + mPanel.updatePanelTitle(); - assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_WIFI_IS_TURNED_ON); + assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_TEXT_WIFI_IS_OFF); } @Test @@ -190,26 +204,17 @@ public class InternetConnectivityPanelTest { } @Test - public void getCustomizedButtonTitle_apmOff_shouldBeSettings() { - doReturn(false).when(mInternetUpdater).isAirplaneModeOn(); - - assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS); - } - - @Test - public void getCustomizedButtonTitle_apmOnWifiOff_shouldBeNull() { - doReturn(true).when(mInternetUpdater).isAirplaneModeOn(); + public void getCustomizedButtonTitle_wifiOff_turnOnWifi() { doReturn(false).when(mInternetUpdater).isWifiEnabled(); - assertThat(mPanel.getCustomizedButtonTitle()).isNull(); + assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_TURN_ON_WIFI); } @Test - public void getCustomizedButtonTitle_apmOnWifiOn_shouldBeSettings() { - doReturn(true).when(mInternetUpdater).isAirplaneModeOn(); + public void getCustomizedButtonTitle_wifiOn_turnOffWifi() { doReturn(true).when(mInternetUpdater).isWifiEnabled(); - assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS); + assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_TURN_OFF_WIFI); } @Test @@ -227,92 +232,60 @@ public class InternetConnectivityPanelTest { public void getSlices_providerModelEnabled_containsNecessarySlices() { List<Uri> uris = mPanel.getSlices(); - assertThat(uris).containsExactly( - CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI, - CustomSliceRegistry.TURN_ON_WIFI_SLICE_URI); + assertThat(uris).containsExactly(CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI); } @Test - public void getSeeMoreIntent_notNull() { - assertThat(mPanel.getSeeMoreIntent()).isNotNull(); + public void getSeeMoreIntent_shouldBeNull() { + assertThat(mPanel.getSeeMoreIntent()).isNull(); } @Test - public void onAirplaneModeOn_apmOff_onTitleChanged() { - doReturn(false).when(mInternetUpdater).isAirplaneModeOn(); - clearInvocations(mPanelContentCallback); + public void onClickCustomizedButton_wifiOn_setWifiOff() { + doReturn(true).when(mInternetUpdater).isWifiEnabled(); - mPanel.onAirplaneModeChanged(false); + mPanel.onClickCustomizedButton(mPanelActivity); - verify(mPanelContentCallback).onTitleChanged(); + verify(mWifiManager).setWifiEnabled(false); } @Test - public void onAirplaneModeOn_apmOnWifiOff_onTitleChanged() { - doReturn(true).when(mInternetUpdater).isAirplaneModeOn(); + public void onClickCustomizedButton_wifiOff_setWifiOn() { doReturn(false).when(mInternetUpdater).isWifiEnabled(); - clearInvocations(mPanelContentCallback); - mPanel.onAirplaneModeChanged(true); + mPanel.onClickCustomizedButton(mPanelActivity); - verify(mPanelContentCallback).onTitleChanged(); + verify(mWifiManager).setWifiEnabled(true); } @Test - public void onAirplaneModeOn_apmOnWifiOn_onHeaderChanged() { - doReturn(true).when(mInternetUpdater).isAirplaneModeOn(); - doReturn(true).when(mInternetUpdater).isWifiEnabled(); - clearInvocations(mPanelContentCallback); - - mPanel.onAirplaneModeChanged(true); + public void onClickCustomizedButton_shouldNotFinishActivity() { + mPanel.onClickCustomizedButton(mPanelActivity); - verify(mPanelContentCallback).onHeaderChanged(); + verify(mPanelActivity, never()).finish(); } @Test - public void onAirplaneModeOn_onCustomizedButtonStateChanged() { - doReturn(true).when(mInternetUpdater).isAirplaneModeOn(); + public void updatePanelTitle_onHeaderChanged() { clearInvocations(mPanelContentCallback); - mPanel.onAirplaneModeChanged(true); - - verify(mPanelContentCallback).onCustomizedButtonStateChanged(); - } - - @Test - public void onWifiEnabledChanged_apmOff_onTitleChanged() { - doReturn(false).when(mInternetUpdater).isAirplaneModeOn(); - clearInvocations(mPanelContentCallback); - - mPanel.onWifiEnabledChanged(false); + mPanel.updatePanelTitle(); - verify(mPanelContentCallback).onTitleChanged(); + verify(mPanelContentCallback).onHeaderChanged(); } @Test - public void onWifiEnabledChanged_apmOnWifiOff_onTitleChanged() { - doReturn(true).when(mInternetUpdater).isAirplaneModeOn(); + public void onWifiEnabledChanged_wifiOff_onCustomizedButtonStateChanged() { doReturn(false).when(mInternetUpdater).isWifiEnabled(); clearInvocations(mPanelContentCallback); - mPanel.onWifiEnabledChanged(true); - - verify(mPanelContentCallback).onTitleChanged(); - } - - @Test - public void onWifiEnabledChanged_apmOnWifiOn_onHeaderChanged() { - doReturn(true).when(mInternetUpdater).isAirplaneModeOn(); - doReturn(true).when(mInternetUpdater).isWifiEnabled(); - clearInvocations(mPanelContentCallback); - - mPanel.onWifiEnabledChanged(true); + mPanel.onWifiEnabledChanged(false); - verify(mPanelContentCallback).onHeaderChanged(); + verify(mPanelContentCallback).onCustomizedButtonStateChanged(); } @Test - public void onWifiEnabledChanged_onCustomizedButtonStateChanged() { + public void onWifiEnabledChanged_wifiOn_onCustomizedButtonStateChanged() { doReturn(true).when(mInternetUpdater).isWifiEnabled(); clearInvocations(mPanelContentCallback); |