[Settings] Remove failure JUnit test cases
This change removes all the files which have any failure JUnit test case. Bug: 168429329 Test: atest --test-mapping tests/unit:postsubmit Change-Id: I1665565760f9dfc185bf9b8dd871ee106eba5dd5
This commit is contained in:
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.wifi;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class SavedNetworkSettingsTest {
|
||||
|
||||
// Keys used to lookup resources by name (see the resourceId helper method).
|
||||
private static final String STRING = "string";
|
||||
private static final String WIFI_ADD_NETWORK = "wifi_add_network";
|
||||
private static final String WIFI_NETWORK_LABEL = "wifi_ssid";
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Rule
|
||||
public ActivityTestRule<Settings.SavedAccessPointsSettingsActivity> mActivityRule =
|
||||
new ActivityTestRule<>(Settings.SavedAccessPointsSettingsActivity.class, true);
|
||||
|
||||
private int resourceId(String type, String name) {
|
||||
return mContext.getResources().getIdentifier(name, type, mContext.getPackageName());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = InstrumentationRegistry.getTargetContext();
|
||||
}
|
||||
|
||||
private void launchSavedNetworksSettings() {
|
||||
Intent intent = new Intent()
|
||||
.setClassName(mContext.getPackageName(),
|
||||
Settings.SavedAccessPointsSettingsActivity.class.getName())
|
||||
.setPackage(mContext.getPackageName());
|
||||
mActivityRule.launchActivity(intent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchSavedNetworkSettings_shouldHaveAddNetworkField() {
|
||||
launchSavedNetworksSettings();
|
||||
onView(withText(resourceId(STRING, WIFI_ADD_NETWORK))).check(matches(isDisplayed()))
|
||||
.perform(click());
|
||||
onView(withText(resourceId(STRING, WIFI_NETWORK_LABEL))).check(matches(isDisplayed()));
|
||||
}
|
||||
}
|
@@ -1,306 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2017 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.wifi;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isSelected;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withResourceName;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.anything;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.matchers.JUnitMatchers.containsString;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.ims.ImsMmTelManager;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.espresso.NoMatchingViewException;
|
||||
import androidx.test.espresso.ViewInteraction;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.internal.telephony.SubscriptionController;
|
||||
import com.android.settings.testutils.MockedServiceManager;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class WifiCallingSettingUiTest {
|
||||
private static final String SUBSCRIPTION0_NAME = "SUB0";
|
||||
private static final String SUBSCRIPTION1_NAME = "SUB1";
|
||||
private static final String WFC_MODE_TITLE = "Calling preference";
|
||||
private static final String WFC_MODE_WIFI_ONLY = "Wi-Fi only";
|
||||
private static final String WFC_MODE_WIFI_PREFERRED = "Wi-Fi preferred";
|
||||
private static final String WFC_MODE_CELLULAR_PREFERRED = "Mobile preferred";
|
||||
|
||||
private Instrumentation mInstrumentation;
|
||||
private Context mContext;
|
||||
private UiDevice mDevice;
|
||||
@Mock
|
||||
SubscriptionController mSubscriptionController;
|
||||
MockedServiceManager mMockedServiceManager;
|
||||
protected HashMap<Integer, ImsManager> mImsManagerInstances = new HashMap<>();
|
||||
List<SubscriptionInfo> mSils = new ArrayList();
|
||||
@Mock
|
||||
SubscriptionInfo mSubscriptionInfo0;
|
||||
@Mock
|
||||
SubscriptionInfo mSubscriptionInfo1;
|
||||
@Mock
|
||||
ImsManager mImsManager0;
|
||||
@Mock
|
||||
ImsManager mImsManager1;
|
||||
@Mock
|
||||
ImsMmTelManager mImsMmTelManager0;
|
||||
@Mock
|
||||
ImsMmTelManager mImsMmTelManager1;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mInstrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
mContext = mInstrumentation.getTargetContext();
|
||||
mDevice = UiDevice.getInstance(mInstrumentation);
|
||||
|
||||
mMockedServiceManager = new MockedServiceManager();
|
||||
mMockedServiceManager.replaceService("isub", mSubscriptionController);
|
||||
|
||||
mMockedServiceManager.replaceInstance(
|
||||
ImsManager.class, "sImsManagerInstances", null, mImsManagerInstances);
|
||||
mMockedServiceManager.replaceInstance(
|
||||
SubscriptionController.class, "sInstance", null, mSubscriptionController);
|
||||
doReturn(mSubscriptionController)
|
||||
.when(mSubscriptionController).queryLocalInterface(anyString());
|
||||
mImsManagerInstances.put(0, mImsManager0);
|
||||
mImsManagerInstances.put(1, mImsManager1);
|
||||
doReturn(mSils).when(mSubscriptionController).getActiveSubscriptionInfoList(anyString(),
|
||||
nullable(String.class));
|
||||
doReturn(0).when(mSubscriptionController).getPhoneId(0);
|
||||
doReturn(1).when(mSubscriptionController).getPhoneId(1);
|
||||
doReturn(0).when(mSubscriptionInfo0).getSubscriptionId();
|
||||
doReturn(1).when(mSubscriptionInfo1).getSubscriptionId();
|
||||
doReturn(0).when(mSubscriptionInfo0).getSimSlotIndex();
|
||||
doReturn(1).when(mSubscriptionInfo1).getSimSlotIndex();
|
||||
doReturn(SUBSCRIPTION0_NAME).when(mSubscriptionInfo0).getDisplayName();
|
||||
doReturn(SUBSCRIPTION1_NAME).when(mSubscriptionInfo1).getDisplayName();
|
||||
|
||||
doReturn(true).when(mImsManager0).isWfcEnabledByPlatform();
|
||||
doReturn(true).when(mImsManager0).isNonTtyOrTtyOnVolteEnabled();
|
||||
doReturn(true).when(mImsManager1).isWfcEnabledByPlatform();
|
||||
doReturn(true).when(mImsManager1).isNonTtyOrTtyOnVolteEnabled();
|
||||
|
||||
mDevice.wakeUp();
|
||||
mDevice.pressMenu();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
mMockedServiceManager.restoreAllServices();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleSimUi() throws InterruptedException {
|
||||
configureSingleSim();
|
||||
doReturn(true).when(mImsManager0).isWfcEnabledByUser();
|
||||
doReturn(ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED)
|
||||
.when(mImsMmTelManager0).getVoWiFiModeSetting();
|
||||
doReturn(ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED)
|
||||
.when(mImsMmTelManager0).getVoWiFiRoamingModeSetting();
|
||||
|
||||
mInstrumentation.startActivitySync(createActivityIntent());
|
||||
|
||||
checkSingleSimUi();
|
||||
|
||||
try {
|
||||
mDevice.setOrientationLeft();
|
||||
} catch (Exception e) {
|
||||
Assert.fail("Exception " + e);
|
||||
}
|
||||
|
||||
// Re-check after rotation. Fragment should be recreated properly.
|
||||
checkSingleSimUi();
|
||||
|
||||
try {
|
||||
mDevice.setOrientationNatural();
|
||||
} catch (Exception e) {
|
||||
Assert.fail("Exception " + e);
|
||||
}
|
||||
|
||||
// Re-check after rotation. Fragment should be resumed properly.
|
||||
checkSingleSimUi();
|
||||
}
|
||||
|
||||
private void checkSingleSimUi() {
|
||||
assertEquals(false, checkExists(onView(withText(SUBSCRIPTION0_NAME))));
|
||||
assertEquals(false, checkExists(onView(withText(SUBSCRIPTION1_NAME))));
|
||||
assertEquals(true, checkExists(onView(withText(WFC_MODE_TITLE))));
|
||||
assertEquals(true, checkExists(onView(withText(WFC_MODE_WIFI_PREFERRED))));
|
||||
checkSwitchBarStatus(true, true);
|
||||
checkEmptyViewStatus(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoValidSub() throws InterruptedException {
|
||||
configureDualSim();
|
||||
doReturn(false).when(mImsManager0).isWfcEnabledByPlatform();
|
||||
doReturn(false).when(mImsManager0).isNonTtyOrTtyOnVolteEnabled();
|
||||
doReturn(false).when(mImsManager1).isWfcEnabledByPlatform();
|
||||
doReturn(false).when(mImsManager1).isNonTtyOrTtyOnVolteEnabled();
|
||||
doReturn(false).when(mImsManager0).isWfcEnabledByUser();
|
||||
doReturn(ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED)
|
||||
.when(mImsMmTelManager0).getVoWiFiModeSetting();
|
||||
doReturn(ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED)
|
||||
.when(mImsMmTelManager0).getVoWiFiRoamingModeSetting();
|
||||
|
||||
Activity activity = mInstrumentation.startActivitySync(createActivityIntent());
|
||||
|
||||
assertEquals(false, checkExists(onView(withText(SUBSCRIPTION0_NAME))));
|
||||
assertEquals(false, checkExists(onView(withText(SUBSCRIPTION1_NAME))));
|
||||
assertEquals(false, checkExists(onView(withText(WFC_MODE_TITLE))));
|
||||
|
||||
checkSwitchBarStatus(false, false);
|
||||
checkEmptyViewStatus(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWfcDisabled() throws InterruptedException {
|
||||
configureSingleSim();
|
||||
doReturn(false).when(mImsManager0).isWfcEnabledByUser();
|
||||
doReturn(ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED)
|
||||
.when(mImsMmTelManager0).getVoWiFiModeSetting();
|
||||
doReturn(ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED)
|
||||
.when(mImsMmTelManager0).getVoWiFiRoamingModeSetting();
|
||||
|
||||
Activity activity = mInstrumentation.startActivitySync(createActivityIntent());
|
||||
|
||||
assertEquals(false, checkExists(onView(withText(SUBSCRIPTION0_NAME))));
|
||||
assertEquals(false, checkExists(onView(withText(SUBSCRIPTION1_NAME))));
|
||||
assertEquals(false, checkExists(onView(withText(WFC_MODE_TITLE))));
|
||||
|
||||
checkSwitchBarStatus(true, false);
|
||||
checkEmptyViewStatus(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDualSimUi() throws InterruptedException {
|
||||
configureDualSim();
|
||||
doReturn(true).when(mImsManager0).isWfcEnabledByUser();
|
||||
doReturn(false).when(mImsManager1).isWfcEnabledByUser();
|
||||
doReturn(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED)
|
||||
.when(mImsMmTelManager0).getVoWiFiModeSetting();
|
||||
doReturn(ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED)
|
||||
.when(mImsMmTelManager0).getVoWiFiRoamingModeSetting();
|
||||
|
||||
mInstrumentation.startActivitySync(createActivityIntent());
|
||||
|
||||
assertEquals(true, checkExists(onView(withText(SUBSCRIPTION0_NAME))));
|
||||
assertEquals(true, checkExists(onView(withText(SUBSCRIPTION1_NAME))));
|
||||
assertEquals(true, checkExists(onView(withText(WFC_MODE_TITLE))));
|
||||
assertEquals(true, checkExists(onView(withText(WFC_MODE_CELLULAR_PREFERRED))));
|
||||
|
||||
onView(withText(SUBSCRIPTION0_NAME)).check(matches(isSelected()));
|
||||
checkSwitchBarStatus(true, true);
|
||||
checkEmptyViewStatus(false);
|
||||
|
||||
// Switch to SUB1.
|
||||
onView(withText(SUBSCRIPTION1_NAME)).perform(click());
|
||||
|
||||
checkSwitchBarStatus(true, false);
|
||||
checkEmptyViewStatus(true);
|
||||
onView(withText(SUBSCRIPTION1_NAME)).check(matches(isSelected()));
|
||||
}
|
||||
|
||||
private boolean checkExists(ViewInteraction v) {
|
||||
try {
|
||||
v.check(matches(isCompletelyDisplayed()));
|
||||
return true;
|
||||
} catch (NoMatchingViewException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Intent createActivityIntent() {
|
||||
Intent intent = new Intent(mContext,
|
||||
com.android.settings.Settings.WifiCallingSettingsActivity.class);
|
||||
intent.setPackage("com.android.settings");
|
||||
intent.setAction("android.intent.action.MAIN");
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
return intent;
|
||||
}
|
||||
|
||||
private void configureSingleSim() {
|
||||
mSils.clear();
|
||||
mSils.add(mSubscriptionInfo0);
|
||||
}
|
||||
|
||||
private void configureDualSim() {
|
||||
mSils.clear();
|
||||
mSils.add(mSubscriptionInfo0);
|
||||
mSils.add(mSubscriptionInfo1);
|
||||
}
|
||||
|
||||
private void checkSwitchBarStatus(boolean shouldDisplay, boolean statusOn) {
|
||||
if (shouldDisplay) {
|
||||
try {
|
||||
onView(allOf(withResourceName("switch_text"), isCompletelyDisplayed()))
|
||||
.check(matches(withText(containsString(statusOn ? "On" : "Off"))));
|
||||
} catch (Exception e) {
|
||||
Assert.fail("Exception " + e);
|
||||
}
|
||||
} else {
|
||||
onView(allOf(withResourceName("switch_text"), isCompletelyDisplayed()))
|
||||
.check(doesNotExist());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEmptyViewStatus(boolean shouldDisplay) {
|
||||
try {
|
||||
if (!shouldDisplay) {
|
||||
onView(allOf(withResourceName("empty"), isCompletelyDisplayed()))
|
||||
.check(doesNotExist());
|
||||
} else {
|
||||
onView(allOf(withResourceName("empty"), isCompletelyDisplayed()))
|
||||
.check(matches(anything()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Assert.fail("Exception " + e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,248 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.wifi;
|
||||
|
||||
import static androidx.test.InstrumentationRegistry.getInstrumentation;
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.Visibility.VISIBLE;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.Settings.WifiSettingsActivity;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
import com.android.wifitrackerlib.WifiEntry;
|
||||
import com.android.wifitrackerlib.WifiPickerTracker;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class WifiSettingsUiTest {
|
||||
private static final String TEST_SSID = "Test Ssid";
|
||||
private static final String TEST_KEY = "Test Key";
|
||||
|
||||
// Keys used to lookup resources by name (see the resourceId/resourceString helper methods).
|
||||
private static final String STRING = "string";
|
||||
private static final String WIFI_CONFIGURE_SETTINGS_PREFERENCE_TITLE =
|
||||
"wifi_configure_settings_preference_title";
|
||||
private static final String WIFI_SAVED_ACCESS_POINTS_LABEL = "wifi_saved_access_points_label";
|
||||
private static final String WIFI_EMPTY_LIST_WIFI_OFF = "wifi_empty_list_wifi_off";
|
||||
private static final String WIFI_DISPLAY_STATUS_CONNECTED = "wifi_display_status_connected";
|
||||
|
||||
@Mock
|
||||
private WifiPickerTracker mWifiTracker;
|
||||
@Mock
|
||||
private WifiPickerTracker.WifiPickerTrackerCallback mWifiListener;
|
||||
|
||||
private Context mContext;
|
||||
private UiDevice mDevice;
|
||||
|
||||
@Rule
|
||||
public ActivityTestRule<WifiSettingsActivity> mActivityRule =
|
||||
new ActivityTestRule<>(WifiSettingsActivity.class, true);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = InstrumentationRegistry.getTargetContext();
|
||||
mDevice = UiDevice.getInstance(getInstrumentation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get around the problem that directly accessing settings resource id's from
|
||||
* com.android.settings.R via R.(type).(name) (eg R.id.password or
|
||||
* R.string.wifi_configure_settings_preference_title) may not work due to mismatched resource
|
||||
* ids. See b/37714546 and b/63546650.
|
||||
*/
|
||||
private int resourceId(String type, String name) {
|
||||
return mContext.getResources().getIdentifier(name, type, mContext.getPackageName());
|
||||
}
|
||||
|
||||
/** Similar to {@link #resourceId}, but for accessing R.string.<name> values. */
|
||||
private String resourceString(String name) {
|
||||
return mContext.getResources().getString(resourceId(STRING, name));
|
||||
}
|
||||
|
||||
/** Launch the activity via an Intent with a String extra. */
|
||||
private void launchActivity(String extraName, String extraValue) {
|
||||
Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
|
||||
if (extraName != null && extraValue != null) {
|
||||
intent.putExtra(extraName, extraValue);
|
||||
}
|
||||
mActivityRule.launchActivity(intent);
|
||||
|
||||
List<Fragment> fragments =
|
||||
mActivityRule.getActivity().getSupportFragmentManager().getFragments();
|
||||
assertThat(fragments.size()).isEqualTo(1);
|
||||
((WifiSettings) fragments.get(0)).mWifiPickerTracker = mWifiTracker;
|
||||
mWifiListener = (WifiSettings) fragments.get(0);
|
||||
assertThat(mWifiListener).isNotNull();
|
||||
}
|
||||
|
||||
/** Helper to launch the activity with no extra. */
|
||||
private void launchActivity() {
|
||||
launchActivity(null, null);
|
||||
}
|
||||
|
||||
private void setWifiState(int wifiState) {
|
||||
when(mWifiTracker.getWifiState()).thenReturn(wifiState);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchActivityShouldSucceed() {
|
||||
launchActivity();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowWifiPreferences() {
|
||||
launchActivity();
|
||||
|
||||
onView(withText(resourceId(STRING, WIFI_CONFIGURE_SETTINGS_PREFERENCE_TITLE))).check(
|
||||
matches(isDisplayed()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noSavedNetworks_wifiDisabled_shouldNotShowSavedNetworksButton() {
|
||||
setWifiState(WifiManager.WIFI_STATE_DISABLED);
|
||||
when(mWifiTracker.getNumSavedNetworks()).thenReturn(0);
|
||||
|
||||
launchActivity();
|
||||
|
||||
onView(withText(resourceId(STRING, WIFI_SAVED_ACCESS_POINTS_LABEL))).check(
|
||||
doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void savedNetworksExist_shouldShowSavedNetworksButton() {
|
||||
setWifiState(WifiManager.WIFI_STATE_ENABLED);
|
||||
when(mWifiTracker.getNumSavedNetworks()).thenReturn(1);
|
||||
|
||||
launchActivity();
|
||||
mActivityRule.getActivity().getMainThreadHandler()
|
||||
.post(() -> mWifiListener.onNumSavedNetworksChanged());
|
||||
|
||||
onView(allOf(withText(resourceId(STRING, WIFI_SAVED_ACCESS_POINTS_LABEL)),
|
||||
withEffectiveVisibility(VISIBLE))).check(matches(isDisplayed()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onWifiStateChanged_wifiDisabled_seeOffMessage() {
|
||||
setWifiState(WifiManager.WIFI_STATE_DISABLED);
|
||||
|
||||
launchActivity();
|
||||
mActivityRule.getActivity().getMainThreadHandler()
|
||||
.post(() -> mWifiListener.onWifiStateChanged());
|
||||
|
||||
onView(withText(startsWith(resourceString(WIFI_EMPTY_LIST_WIFI_OFF)))).check(
|
||||
matches(isDisplayed()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onWifiStateChanged_wifiEnabled_shouldNotSeeOffMessage() {
|
||||
setWifiState(WifiManager.WIFI_STATE_ENABLED);
|
||||
|
||||
launchActivity();
|
||||
mActivityRule.getActivity().getMainThreadHandler()
|
||||
.post(() -> mWifiListener.onWifiStateChanged());
|
||||
|
||||
onView(withText(startsWith(resourceString(WIFI_EMPTY_LIST_WIFI_OFF)))).check(
|
||||
doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onConnected_shouldSeeConnectedMessage() {
|
||||
setWifiState(WifiManager.WIFI_STATE_ENABLED);
|
||||
final WifiEntry wifiEntry = mock(WifiEntry.class);
|
||||
when(wifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
||||
when(wifiEntry.getSummary(false /* concise */))
|
||||
.thenReturn(resourceString(WIFI_DISPLAY_STATUS_CONNECTED));
|
||||
when(wifiEntry.getKey()).thenReturn(TEST_KEY);
|
||||
when(mWifiTracker.getConnectedWifiEntry()).thenReturn(wifiEntry);
|
||||
|
||||
launchActivity();
|
||||
ThreadUtils.postOnMainThread(() -> mWifiListener.onWifiEntriesChanged());
|
||||
mDevice.waitForIdle();
|
||||
|
||||
onView(withText(resourceString(WIFI_DISPLAY_STATUS_CONNECTED))).check(
|
||||
matches(isDisplayed()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changingSecurityStateOnAp_ShouldNotCauseMultipleListItems() {
|
||||
setWifiState(WifiManager.WIFI_STATE_ENABLED);
|
||||
|
||||
final WifiEntry openWifiEntry = mock(WifiEntry.class);
|
||||
when(openWifiEntry.getTitle()).thenReturn(TEST_SSID);
|
||||
when(openWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_NONE);
|
||||
|
||||
final WifiEntry eapWifiEntry = mock(WifiEntry.class);
|
||||
when(eapWifiEntry.getTitle()).thenReturn(TEST_SSID);
|
||||
when(eapWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
|
||||
|
||||
final WifiEntry wepWifiEntry = mock(WifiEntry.class);
|
||||
when(wepWifiEntry.getTitle()).thenReturn(TEST_SSID);
|
||||
when(wepWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_WEP);
|
||||
|
||||
// Return a different security state each time getWifiEntries is invoked
|
||||
when(mWifiTracker.getWifiEntries())
|
||||
.thenReturn(Lists.newArrayList(openWifiEntry))
|
||||
.thenReturn(Lists.newArrayList(eapWifiEntry))
|
||||
.thenReturn(Lists.newArrayList(wepWifiEntry));
|
||||
|
||||
launchActivity();
|
||||
|
||||
ThreadUtils.postOnMainThread(() -> mWifiListener.onWifiEntriesChanged());
|
||||
mDevice.waitForIdle();
|
||||
onView(withText(TEST_SSID)).check(matches(isDisplayed()));
|
||||
|
||||
ThreadUtils.postOnMainThread(() -> mWifiListener.onWifiEntriesChanged());
|
||||
mDevice.waitForIdle();
|
||||
onView(withText(TEST_SSID)).check(matches(isDisplayed()));
|
||||
|
||||
ThreadUtils.postOnMainThread(() -> mWifiListener.onWifiEntriesChanged());
|
||||
mDevice.waitForIdle();
|
||||
onView(withText(TEST_SSID)).check(matches(isDisplayed()));
|
||||
}
|
||||
}
|
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.wifi.dpp;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
|
||||
import static com.android.settings.wifi.dpp.WifiDppUtils.TAG_FRAGMENT_ADD_DEVICE;
|
||||
import static com.android.settings.wifi.dpp.WifiDppUtils.TAG_FRAGMENT_CHOOSE_SAVED_WIFI_NETWORK;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import android.provider.Settings;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class WifiDppChooseSavedWifiNetworkFragmentTest {
|
||||
// Valid Wi-Fi DPP QR code
|
||||
private static final String VALID_WIFI_DPP_QR_CODE = "DPP:I:SN=4774LH2b4044;M:010203040506;K:"
|
||||
+ "MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;";
|
||||
|
||||
// Keys used to lookup resources by name (see the resourceId/resourceString helper methods).
|
||||
private static final String STRING = "string";
|
||||
private static final String WIFI_DPP_CHOOSE_DIFFERENT_NETWORK =
|
||||
"wifi_dpp_choose_different_network";
|
||||
private static final String CANCEL = "cancel";
|
||||
|
||||
@Rule
|
||||
public final ActivityTestRule<WifiDppConfiguratorActivity> mActivityRule =
|
||||
new ActivityTestRule<>(WifiDppConfiguratorActivity.class, /* initialTouchMode */true,
|
||||
/* launchActivity */ false);
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = InstrumentationRegistry.getTargetContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickCancelButton_configuratorQrCodeScannerIntent_shouldPopBackStack() {
|
||||
final Intent intent =
|
||||
new Intent(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY, "password");
|
||||
final WifiDppConfiguratorActivity hostActivity = mActivityRule.launchActivity(intent);
|
||||
|
||||
// Go to WifiDppChooseSavedWifiNetworkFragment and click the cancel button
|
||||
final FragmentManager fragmentManager = hostActivity.getSupportFragmentManager();
|
||||
final WifiQrCode wifiQrCode = new WifiQrCode(VALID_WIFI_DPP_QR_CODE);
|
||||
hostActivity.runOnUiThread(() ->
|
||||
((WifiDppConfiguratorActivity)hostActivity).onScanWifiDppSuccess(wifiQrCode)
|
||||
);
|
||||
onView(withText(resourceString(WIFI_DPP_CHOOSE_DIFFERENT_NETWORK))).perform(click());
|
||||
onView(withText(resourceString(CANCEL))).perform(click());
|
||||
|
||||
assertThat(fragmentManager.findFragmentByTag(TAG_FRAGMENT_ADD_DEVICE)).isNotNull();
|
||||
assertThat(fragmentManager.findFragmentByTag(TAG_FRAGMENT_CHOOSE_SAVED_WIFI_NETWORK))
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickCancelButton_processWifiDppQrCodeIntent_shouldFinish() {
|
||||
final Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_URI);
|
||||
intent.setData(Uri.parse(VALID_WIFI_DPP_QR_CODE));
|
||||
final WifiDppConfiguratorActivity hostActivity = mActivityRule.launchActivity(intent);
|
||||
|
||||
onView(withText(resourceString(CANCEL))).perform(click());
|
||||
|
||||
assertThat(hostActivity.isFinishing()).isEqualTo(true);
|
||||
}
|
||||
|
||||
private int resourceId(String type, String name) {
|
||||
return mContext.getResources().getIdentifier(name, type, mContext.getPackageName());
|
||||
}
|
||||
|
||||
/** Similar to {@link #resourceId}, but for accessing R.string.<name> values. */
|
||||
private String resourceString(String name) {
|
||||
return mContext.getResources().getString(resourceId(STRING, name));
|
||||
}
|
||||
}
|
@@ -1,183 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.wifi.dpp;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.Settings;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.google.android.setupdesign.GlifLayout;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class WifiDppConfiguratorActivityTest {
|
||||
// Valid Wi-Fi DPP QR code & it's parameters
|
||||
private static final String VALID_WIFI_DPP_QR_CODE = "DPP:I:SN=4774LH2b4044;M:010203040506;K:"
|
||||
+ "MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;";
|
||||
|
||||
@Rule
|
||||
public final ActivityTestRule<WifiDppConfiguratorActivity> mActivityRule =
|
||||
new ActivityTestRule<>(WifiDppConfiguratorActivity.class);
|
||||
|
||||
private UiDevice mDevice;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchActivity_qrCodeScanner_shouldNotAutoFinish() {
|
||||
Intent intent = new Intent(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY, "password");
|
||||
|
||||
mActivityRule.launchActivity(intent);
|
||||
FragmentManager fragmentManager = mActivityRule.getActivity().getSupportFragmentManager();
|
||||
WifiDppQrCodeScannerFragment fragment =
|
||||
(WifiDppQrCodeScannerFragment) fragmentManager.findFragmentByTag(
|
||||
WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER);
|
||||
|
||||
assertThat(fragment.getView() instanceof GlifLayout).isTrue();
|
||||
assertThat(mActivityRule.getActivity().isFinishing()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchActivity_qrCodeGenerator_shouldNotAutoFinish() {
|
||||
Intent intent = new Intent(
|
||||
WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_GENERATOR);
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY, "password");
|
||||
|
||||
mActivityRule.launchActivity(intent);
|
||||
FragmentManager fragmentManager = mActivityRule.getActivity().getSupportFragmentManager();
|
||||
WifiDppQrCodeGeneratorFragment fragment =
|
||||
(WifiDppQrCodeGeneratorFragment) fragmentManager.findFragmentByTag(
|
||||
WifiDppUtils.TAG_FRAGMENT_QR_CODE_GENERATOR);
|
||||
|
||||
assertThat(fragment.getView() instanceof GlifLayout).isTrue();
|
||||
assertThat(mActivityRule.getActivity().isFinishing()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchActivity_chooseSavedWifiNetwork_shouldNotAutoFinish() {
|
||||
final Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_URI);
|
||||
intent.setData(Uri.parse(VALID_WIFI_DPP_QR_CODE));
|
||||
|
||||
mActivityRule.launchActivity(intent);
|
||||
|
||||
assertThat(mActivityRule.getActivity().isFinishing()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActivity_shouldImplementsWifiNetworkConfigRetriever() {
|
||||
WifiDppConfiguratorActivity activity = mActivityRule.getActivity();
|
||||
|
||||
assertThat(activity instanceof WifiNetworkConfig.Retriever).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActivity_shouldImplementsOnScanWifiDppSuccessCallback() {
|
||||
WifiDppConfiguratorActivity activity = mActivityRule.getActivity();
|
||||
|
||||
assertThat(activity instanceof WifiDppQrCodeScannerFragment
|
||||
.OnScanWifiDppSuccessListener).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActivity_shouldImplementsOnClickChooseDifferentNetworkCallback() {
|
||||
WifiDppConfiguratorActivity activity = mActivityRule.getActivity();
|
||||
|
||||
assertThat(activity instanceof WifiDppAddDeviceFragment
|
||||
.OnClickChooseDifferentNetworkListener).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rotateScreen_shouldGetCorrectWifiDppQrCode() {
|
||||
WifiQrCode wifiQrCode = new WifiQrCode(VALID_WIFI_DPP_QR_CODE);
|
||||
Intent intent = new Intent(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY, "password");
|
||||
|
||||
// setWifiDppQrCode and check if getWifiDppQrCode correctly after rotation
|
||||
mActivityRule.launchActivity(intent);
|
||||
mActivityRule.getActivity().setWifiDppQrCode(wifiQrCode);
|
||||
|
||||
try {
|
||||
mDevice.setOrientationLeft();
|
||||
mDevice.setOrientationNatural();
|
||||
mDevice.setOrientationRight();
|
||||
mDevice.setOrientationNatural();
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
WifiQrCode restoredWifiDppQrCode = mActivityRule.getActivity().getWifiDppQrCode();
|
||||
assertThat(restoredWifiDppQrCode).isNotNull();
|
||||
assertThat(restoredWifiDppQrCode.getQrCode()).isEqualTo(VALID_WIFI_DPP_QR_CODE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rotateScreen_shouldGetCorrectWifiNetworkConfig() {
|
||||
final WifiNetworkConfig wifiNetworkConfig = new WifiNetworkConfig("WPA", "WifiSsid",
|
||||
"password", /* hiddenSsid */ false, /* networkId */ 0, /* isHotspot */ true);
|
||||
final Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_URI);
|
||||
intent.setData(Uri.parse(VALID_WIFI_DPP_QR_CODE));
|
||||
|
||||
// setWifiNetworkConfig and check if getWifiNetworkConfig correctly after rotation
|
||||
mActivityRule.launchActivity(intent);
|
||||
mActivityRule.getActivity().setWifiNetworkConfig(wifiNetworkConfig);
|
||||
|
||||
try {
|
||||
mDevice.setOrientationLeft();
|
||||
mDevice.setOrientationNatural();
|
||||
mDevice.setOrientationRight();
|
||||
mDevice.setOrientationNatural();
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
WifiNetworkConfig restoredWifiNetworkConfig =
|
||||
mActivityRule.getActivity().getWifiNetworkConfig();
|
||||
|
||||
assertThat(restoredWifiNetworkConfig).isNotNull();
|
||||
assertThat(restoredWifiNetworkConfig.getSecurity()).isEqualTo("WPA");
|
||||
assertThat(restoredWifiNetworkConfig.getSsid()).isEqualTo("WifiSsid");
|
||||
assertThat(restoredWifiNetworkConfig.getPreSharedKey()).isEqualTo("password");
|
||||
assertThat(restoredWifiNetworkConfig.getHiddenSsid()).isFalse();
|
||||
assertThat(restoredWifiNetworkConfig.getNetworkId()).isEqualTo(0);
|
||||
assertThat(restoredWifiNetworkConfig.isHotspot()).isTrue();
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.wifi.dpp;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class WifiDppEnrolleeActivityTest {
|
||||
@Rule
|
||||
public final ActivityTestRule<WifiDppEnrolleeActivity> mActivityRule =
|
||||
new ActivityTestRule<>(WifiDppEnrolleeActivity.class);
|
||||
|
||||
@Test
|
||||
public void testActivity_shouldImplementsOnScanWifiDppSuccessCallback() {
|
||||
WifiDppEnrolleeActivity activity = mActivityRule.getActivity();
|
||||
|
||||
assertThat(activity instanceof WifiDppQrCodeScannerFragment
|
||||
.OnScanWifiDppSuccessListener).isEqualTo(true);
|
||||
}
|
||||
}
|
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.wifi.dpp;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class WifiDppQrCodeGeneratorFragmentTest {
|
||||
@Rule
|
||||
public final ActivityTestRule<WifiDppConfiguratorActivity> mActivityRule =
|
||||
new ActivityTestRule<>(WifiDppConfiguratorActivity.class, true);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Intent intent =
|
||||
new Intent(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_GENERATOR);
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
|
||||
mActivityRule.launchActivity(intent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rotateScreen_shouldNotCrash() {
|
||||
mActivityRule.getActivity().setRequestedOrientation(
|
||||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
mActivityRule.getActivity().setRequestedOrientation(
|
||||
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
}
|
||||
}
|
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.wifi.dpp;
|
||||
|
||||
import static com.android.settings.wifi.dpp.WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class WifiDppQrCodeScannerFragmentTest {
|
||||
@Rule
|
||||
public final ActivityTestRule<WifiDppConfiguratorActivity> mActivityRule =
|
||||
new ActivityTestRule<>(WifiDppConfiguratorActivity.class, true);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Intent intent = new Intent(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY, "password");
|
||||
mActivityRule.launchActivity(intent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rotateScreen_shouldNotCrash() {
|
||||
mActivityRule.getActivity().setRequestedOrientation(
|
||||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
mActivityRule.getActivity().setRequestedOrientation(
|
||||
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_shouldNotDecodeQrCode() {
|
||||
final WifiDppConfiguratorActivity hostActivity =
|
||||
(WifiDppConfiguratorActivity) mActivityRule.getActivity();
|
||||
final FragmentManager fragmentManager = hostActivity.getSupportFragmentManager();
|
||||
final WifiDppQrCodeScannerFragment scannerFragment =
|
||||
(WifiDppQrCodeScannerFragment) fragmentManager
|
||||
.findFragmentByTag(TAG_FRAGMENT_QR_CODE_SCANNER);
|
||||
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
|
||||
instrumentation.runOnMainSync(() -> {
|
||||
instrumentation.callActivityOnPause(hostActivity);
|
||||
|
||||
assertThat(scannerFragment.isDecodeTaskAlive()).isEqualTo(false);
|
||||
});
|
||||
}
|
||||
}
|
@@ -1,254 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.wifi.dpp;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class WifiQrCodeTest {
|
||||
// Valid Wi-Fi DPP QR code & it's parameters
|
||||
private static final String VALID_WIFI_DPP_QR_CODE = "DPP:I:SN=4774LH2b4044;M:010203040506;K:"
|
||||
+ "MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;";
|
||||
|
||||
private static final String PUBLIC_KEY_OF_VALID_WIFI_DPP_QR_CODE =
|
||||
"MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=";
|
||||
|
||||
private static final String INFORMATION_OF_VALID_WIFI_DPP_QR_CODE =
|
||||
"SN=4774LH2b4044";
|
||||
|
||||
// Valid ZXing reader library's Wi-Fi Network config format & it's parameters
|
||||
private static final String VALID_ZXING_WIFI_QR_CODE_WPA =
|
||||
"WIFI:T:WPA;S:mynetwork;P:mypass;H:true;;";
|
||||
|
||||
// Valid ZXing reader library's Wi-Fi Network config format - security type SAE
|
||||
private static final String VALID_ZXING_WIFI_QR_CODE_SAE =
|
||||
"WIFI:T:SAE;S:mynetwork;P:mypass;H:true;;";
|
||||
|
||||
// Valid ZXing reader library's Wi-Fi Network config format - security type nopass and no password
|
||||
private static final String VALID_ZXING_WIFI_QR_CODE_NOPASS_AND_NO_PASSWORD =
|
||||
"WIFI:T:nopass;S:mynetwork;;";
|
||||
|
||||
// Valid ZXing reader library's Wi-Fi Network config format - no security and no password
|
||||
private static final String VALID_ZXING_WIFI_QR_CODE_NO_SECURITY_AND_NO_PASSWORD =
|
||||
"WIFI:T:;S:mynetwork;P:;H:false;;";
|
||||
|
||||
private static final String SECURITY_OF_VALID_ZXING_WIFI_QR_CODE_WPA = "WPA";
|
||||
private static final String SECURITY_OF_VALID_ZXING_WIFI_QR_CODE_SAE = "SAE";
|
||||
private static final String SECURITY_OF_VALID_ZXING_WIFI_QR_CODE_NOPASS = "nopass";
|
||||
private static final String SSID_OF_VALID_ZXING_WIFI_QR_CODE = "mynetwork";
|
||||
private static final String PASSWORD_OF_VALID_ZXING_WIFI_QR_CODE = "mypass";
|
||||
|
||||
// Valid ZXing reader library's Wi-Fi Network config format - escaped characters
|
||||
private static final String VALID_ZXING_WIFI_QR_CODE_SPECIAL_CHARACTERS =
|
||||
"WIFI:T:WPA;S:mynetwork;P:m\\;y\\:p\\\\a\\,ss;H:true;;";
|
||||
|
||||
private static final String PASSWORD_OF_VALID_ZXING_WIFI_QR_CODE_SPECIAL_CHARACTERS =
|
||||
"m;y:p\\a,ss";
|
||||
|
||||
// Invalid scheme QR code
|
||||
private static final String INVALID_SCHEME_QR_CODE = "BT:T:WPA;S:mynetwork;P:mypass;H:true;;";
|
||||
|
||||
// Invalid Wi-Fi DPP QR code - no public key - case 1
|
||||
private static final String INVALID_WIFI_DPP_QR_CODE_NO_PUBLIC_KEY_1 =
|
||||
"DPP:I:SN=4774LH2b4044;M:010203040506;K:;;";
|
||||
|
||||
// Invalid Wi-Fi DPP QR code - no public key - case 2
|
||||
private static final String INVALID_WIFI_DPP_QR_CODE_NO_PUBLIC_KEY_2 =
|
||||
"DPP:I:SN=4774LH2b4044;M:010203040506;;";
|
||||
|
||||
// Invalid ZXing reader library's Wi-Fi Network config format - no password
|
||||
private static final String INVALID_ZXING_WIFI_QR_CODE_NO_PASSWORD =
|
||||
"WIFI:T:WPA;S:mynetwork;P:;;";
|
||||
|
||||
// Invalid ZXing reader library's Wi-Fi Network config format - no SSID
|
||||
private static final String INVALID_ZXING_WIFI_QR_CODE_NO_SSID =
|
||||
"WIFI:T:WPA;P:mypass;;";
|
||||
|
||||
@Test
|
||||
public void parseValidWifiDppQrCode() {
|
||||
WifiQrCode wifiQrCode = new WifiQrCode(VALID_WIFI_DPP_QR_CODE);
|
||||
|
||||
assertEquals(WifiQrCode.SCHEME_DPP, wifiQrCode.getScheme());
|
||||
assertEquals(PUBLIC_KEY_OF_VALID_WIFI_DPP_QR_CODE, wifiQrCode.getPublicKey());
|
||||
assertEquals(INFORMATION_OF_VALID_WIFI_DPP_QR_CODE, wifiQrCode.getInformation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValidZxingWifiQrCode() {
|
||||
WifiQrCode wifiQrCode = new WifiQrCode(VALID_ZXING_WIFI_QR_CODE_WPA);
|
||||
WifiNetworkConfig config = wifiQrCode.getWifiNetworkConfig();
|
||||
|
||||
assertEquals(WifiQrCode.SCHEME_ZXING_WIFI_NETWORK_CONFIG, wifiQrCode.getScheme());
|
||||
assertNotNull(config);
|
||||
assertEquals(SECURITY_OF_VALID_ZXING_WIFI_QR_CODE_WPA, config.getSecurity());
|
||||
assertEquals(SSID_OF_VALID_ZXING_WIFI_QR_CODE, config.getSsid());
|
||||
assertEquals(PASSWORD_OF_VALID_ZXING_WIFI_QR_CODE, config.getPreSharedKey());
|
||||
assertEquals(true, config.getHiddenSsid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValidZxingWifiQrCodeSae() {
|
||||
WifiQrCode wifiQrCode = new WifiQrCode(VALID_ZXING_WIFI_QR_CODE_SAE);
|
||||
WifiNetworkConfig config = wifiQrCode.getWifiNetworkConfig();
|
||||
|
||||
assertEquals(WifiQrCode.SCHEME_ZXING_WIFI_NETWORK_CONFIG, wifiQrCode.getScheme());
|
||||
assertNotNull(config);
|
||||
assertEquals(SECURITY_OF_VALID_ZXING_WIFI_QR_CODE_SAE, config.getSecurity());
|
||||
assertEquals(SSID_OF_VALID_ZXING_WIFI_QR_CODE, config.getSsid());
|
||||
assertEquals(PASSWORD_OF_VALID_ZXING_WIFI_QR_CODE, config.getPreSharedKey());
|
||||
assertEquals(true, config.getHiddenSsid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValidZxingWifiQrCode_noPass_and_no_password() {
|
||||
WifiQrCode wifiQrCode = new WifiQrCode(VALID_ZXING_WIFI_QR_CODE_NOPASS_AND_NO_PASSWORD);
|
||||
WifiNetworkConfig config = wifiQrCode.getWifiNetworkConfig();
|
||||
|
||||
assertEquals(WifiQrCode.SCHEME_ZXING_WIFI_NETWORK_CONFIG, wifiQrCode.getScheme());
|
||||
assertNotNull(config);
|
||||
assertEquals(SECURITY_OF_VALID_ZXING_WIFI_QR_CODE_NOPASS, config.getSecurity());
|
||||
assertEquals(SSID_OF_VALID_ZXING_WIFI_QR_CODE, config.getSsid());
|
||||
assertNull(config.getPreSharedKey());
|
||||
assertEquals(false, config.getHiddenSsid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValidZxingWifiQrCode_no_security_and_no_password() {
|
||||
WifiQrCode wifiQrCode = new WifiQrCode(VALID_ZXING_WIFI_QR_CODE_NO_SECURITY_AND_NO_PASSWORD);
|
||||
WifiNetworkConfig config = wifiQrCode.getWifiNetworkConfig();
|
||||
|
||||
assertEquals(WifiQrCode.SCHEME_ZXING_WIFI_NETWORK_CONFIG, wifiQrCode.getScheme());
|
||||
assertNotNull(config);
|
||||
assertEquals("", config.getSecurity());
|
||||
assertEquals(SSID_OF_VALID_ZXING_WIFI_QR_CODE, config.getSsid());
|
||||
assertEquals("", config.getPreSharedKey());
|
||||
assertEquals(false, config.getHiddenSsid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValidZxingWifiQrCode_specialCharacters() {
|
||||
WifiQrCode wifiQrCode = new WifiQrCode(VALID_ZXING_WIFI_QR_CODE_SPECIAL_CHARACTERS);
|
||||
WifiNetworkConfig config = wifiQrCode.getWifiNetworkConfig();
|
||||
|
||||
assertEquals(WifiQrCode.SCHEME_ZXING_WIFI_NETWORK_CONFIG, wifiQrCode.getScheme());
|
||||
assertNotNull(config);
|
||||
assertEquals(SECURITY_OF_VALID_ZXING_WIFI_QR_CODE_WPA, config.getSecurity());
|
||||
assertEquals(SSID_OF_VALID_ZXING_WIFI_QR_CODE, config.getSsid());
|
||||
assertEquals(PASSWORD_OF_VALID_ZXING_WIFI_QR_CODE_SPECIAL_CHARACTERS,
|
||||
config.getPreSharedKey());
|
||||
assertEquals(true, config.getHiddenSsid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveBackSlash() {
|
||||
WifiQrCode wifiQrCode = new WifiQrCode(VALID_WIFI_DPP_QR_CODE);
|
||||
|
||||
assertEquals("\\", wifiQrCode.removeBackSlash("\\\\"));
|
||||
assertEquals("ab", wifiQrCode.removeBackSlash("a\\b"));
|
||||
assertEquals("a", wifiQrCode.removeBackSlash("\\a"));
|
||||
assertEquals("\\b", wifiQrCode.removeBackSlash("\\\\b"));
|
||||
assertEquals("c\\", wifiQrCode.removeBackSlash("c\\\\"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseEmptyQrCode_shouldThrowIllegalArgumentException() {
|
||||
try {
|
||||
new WifiQrCode(null);
|
||||
fail("Null QR code");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
try {
|
||||
new WifiQrCode("");
|
||||
fail("Empty string QR code");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
try {
|
||||
new WifiQrCode("DPP:;");
|
||||
fail("Empty content WIFI DPP QR code");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
try {
|
||||
new WifiQrCode("WIFI:;");
|
||||
fail("Empty content ZXing WIFI QR code");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseInvalidSchemeQrCode_shouldThrowIllegalArgumentException() {
|
||||
try {
|
||||
new WifiQrCode(INVALID_SCHEME_QR_CODE);
|
||||
fail("Invalid scheme");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseInvalidWifiDppQrCode_noPublicKey_shouldThrowIllegalArgumentException() {
|
||||
try {
|
||||
new WifiQrCode(INVALID_WIFI_DPP_QR_CODE_NO_PUBLIC_KEY_1);
|
||||
fail("No public key case 1");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
try {
|
||||
new WifiQrCode(INVALID_WIFI_DPP_QR_CODE_NO_PUBLIC_KEY_2);
|
||||
fail("No public key case 2");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseInvalidZxingWifiQrCode_noPassword_shouldThrowIllegalArgumentException() {
|
||||
try {
|
||||
new WifiQrCode(INVALID_ZXING_WIFI_QR_CODE_NO_PASSWORD);
|
||||
fail("No password");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseInvalidZxingWifiQrCode_noSsid_shouldThrowIllegalArgumentException() {
|
||||
try {
|
||||
new WifiQrCode(INVALID_ZXING_WIFI_QR_CODE_NO_SSID);
|
||||
fail("No SSID");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,396 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.wifi.tether;
|
||||
|
||||
import static android.net.TetheringConstants.EXTRA_ADD_TETHER_TYPE;
|
||||
import static android.net.TetheringConstants.EXTRA_PROVISION_CALLBACK;
|
||||
import static android.net.TetheringConstants.EXTRA_RUN_PROVISION;
|
||||
import static android.net.TetheringManager.TETHERING_BLUETOOTH;
|
||||
import static android.net.TetheringManager.TETHERING_INVALID;
|
||||
import static android.net.TetheringManager.TETHERING_USB;
|
||||
import static android.net.TetheringManager.TETHERING_WIFI;
|
||||
import static android.net.TetheringManager.TETHER_ERROR_NO_ERROR;
|
||||
import static android.net.TetheringManager.TETHER_ERROR_PROVISIONING_FAILED;
|
||||
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
||||
import static com.android.settings.wifi.tether.TetherService.EXTRA_TETHER_PROVISIONING_RESPONSE;
|
||||
import static com.android.settings.wifi.tether.TetherService.EXTRA_TETHER_SILENT_PROVISIONING_ACTION;
|
||||
import static com.android.settings.wifi.tether.TetherService.EXTRA_TETHER_SUBID;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.usage.UsageStatsManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.TetheringManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.ResultReceiver;
|
||||
import android.os.SystemClock;
|
||||
import android.test.ServiceTestCase;
|
||||
import android.util.Log;
|
||||
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TetherServiceTest extends ServiceTestCase<TetherService> {
|
||||
|
||||
private static final String TAG = "TetherServiceTest";
|
||||
private static final String FAKE_PACKAGE_NAME = "com.some.package.name";
|
||||
private static final String ENTITLEMENT_PACKAGE_NAME = "com.some.entitlement.name";
|
||||
private static final String TEST_RESPONSE_ACTION = "testProvisioningResponseAction";
|
||||
private static final String TEST_NO_UI_ACTION = "testNoUiProvisioningRequestAction";
|
||||
private static final int BOGUS_RECEIVER_RESULT = -5;
|
||||
private static final int MS_PER_HOUR = 60 * 60 * 1000;
|
||||
private static final int SHORT_TIMEOUT = 100;
|
||||
private static final int PROVISION_TIMEOUT = 1000;
|
||||
|
||||
private TetherService mService;
|
||||
private MockTetherServiceWrapper mWrapper;
|
||||
int mLastReceiverResultCode = BOGUS_RECEIVER_RESULT;
|
||||
private int mLastTetherRequestType = TETHERING_INVALID;
|
||||
private int mProvisionResponse = BOGUS_RECEIVER_RESULT;
|
||||
private ProvisionReceiver mProvisionReceiver;
|
||||
private Receiver mResultReceiver;
|
||||
|
||||
@Mock private TetheringManager mTetheringManager;
|
||||
@Mock private PackageManager mPackageManager;
|
||||
@Mock private WifiManager mWifiManager;
|
||||
@Mock private SharedPreferences mPrefs;
|
||||
@Mock private Editor mPrefEditor;
|
||||
@Captor private ArgumentCaptor<PendingIntent> mPiCaptor;
|
||||
@Captor private ArgumentCaptor<String> mStoredTypes;
|
||||
|
||||
public TetherServiceTest() {
|
||||
super(TetherService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = new TestContextWrapper(getContext());
|
||||
setContext(mContext);
|
||||
|
||||
mResultReceiver = new Receiver(this);
|
||||
mLastReceiverResultCode = BOGUS_RECEIVER_RESULT;
|
||||
mProvisionResponse = Activity.RESULT_OK;
|
||||
mProvisionReceiver = new ProvisionReceiver();
|
||||
IntentFilter filter = new IntentFilter(TEST_NO_UI_ACTION);
|
||||
filter.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
mContext.registerReceiver(mProvisionReceiver, filter);
|
||||
|
||||
final String CURRENT_TYPES = "currentTethers";
|
||||
when(mPrefs.getString(CURRENT_TYPES, "")).thenReturn("");
|
||||
when(mPrefs.edit()).thenReturn(mPrefEditor);
|
||||
when(mPrefEditor.putString(eq(CURRENT_TYPES), mStoredTypes.capture())).thenReturn(
|
||||
mPrefEditor);
|
||||
mWrapper = new MockTetherServiceWrapper(mContext);
|
||||
|
||||
ResolveInfo systemAppResolveInfo = new ResolveInfo();
|
||||
ActivityInfo systemActivityInfo = new ActivityInfo();
|
||||
systemActivityInfo.packageName = ENTITLEMENT_PACKAGE_NAME;
|
||||
ApplicationInfo systemAppInfo = new ApplicationInfo();
|
||||
systemAppInfo.flags |= ApplicationInfo.FLAG_SYSTEM;
|
||||
systemActivityInfo.applicationInfo = systemAppInfo;
|
||||
systemAppResolveInfo.activityInfo = systemActivityInfo;
|
||||
|
||||
ResolveInfo nonSystemResolveInfo = new ResolveInfo();
|
||||
ActivityInfo nonSystemActivityInfo = new ActivityInfo();
|
||||
nonSystemActivityInfo.packageName = FAKE_PACKAGE_NAME;
|
||||
nonSystemActivityInfo.applicationInfo = new ApplicationInfo();
|
||||
nonSystemResolveInfo.activityInfo = nonSystemActivityInfo;
|
||||
|
||||
List<ResolveInfo> resolvers = new ArrayList();
|
||||
resolvers.add(nonSystemResolveInfo);
|
||||
resolvers.add(systemAppResolveInfo);
|
||||
when(mPackageManager.queryBroadcastReceivers(
|
||||
any(Intent.class), eq(PackageManager.MATCH_ALL))).thenReturn(resolvers);
|
||||
setupService();
|
||||
getService().setTetherServiceWrapper(mWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
mContext.unregisterReceiver(mProvisionReceiver);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testStartForProvision() {
|
||||
runProvisioningForType(TETHERING_WIFI);
|
||||
|
||||
assertTrue(waitForProvisionRequest(TETHERING_WIFI));
|
||||
assertTrue(waitForProvisionResponse(TETHER_ERROR_NO_ERROR));
|
||||
}
|
||||
|
||||
public void testStartKeepsProvisionAppActive() {
|
||||
runProvisioningForType(TETHERING_WIFI);
|
||||
|
||||
assertTrue(waitForProvisionRequest(TETHERING_WIFI));
|
||||
assertTrue(waitForProvisionResponse(TETHER_ERROR_NO_ERROR));
|
||||
assertFalse(mWrapper.isAppInactive(ENTITLEMENT_PACKAGE_NAME));
|
||||
// Non-system handler of the intent action should stay idle.
|
||||
assertTrue(mWrapper.isAppInactive(FAKE_PACKAGE_NAME));
|
||||
}
|
||||
|
||||
public void testStartMultiple() {
|
||||
runProvisioningForType(TETHERING_WIFI);
|
||||
|
||||
assertTrue(waitForProvisionRequest(TETHERING_WIFI));
|
||||
assertTrue(waitForProvisionResponse(TETHER_ERROR_NO_ERROR));
|
||||
|
||||
runProvisioningForType(TETHERING_USB);
|
||||
|
||||
assertTrue(waitForProvisionRequest(TETHERING_USB));
|
||||
assertTrue(waitForProvisionResponse(TETHER_ERROR_NO_ERROR));
|
||||
|
||||
runProvisioningForType(TETHERING_BLUETOOTH);
|
||||
|
||||
assertTrue(waitForProvisionRequest(TETHERING_BLUETOOTH));
|
||||
assertTrue(waitForProvisionResponse(TETHER_ERROR_NO_ERROR));
|
||||
}
|
||||
|
||||
public void testPersistTypes() {
|
||||
runProvisioningForType(TETHERING_WIFI);
|
||||
|
||||
waitForProvisionRequest(TETHERING_WIFI);
|
||||
waitForProvisionResponse(TETHER_ERROR_NO_ERROR);
|
||||
|
||||
runProvisioningForType(TETHERING_BLUETOOTH);
|
||||
|
||||
waitForProvisionRequest(TETHERING_BLUETOOTH);
|
||||
waitForProvisionResponse(TETHER_ERROR_NO_ERROR);
|
||||
|
||||
shutdownService();
|
||||
assertEquals(TETHERING_WIFI + "," + TETHERING_BLUETOOTH, mStoredTypes.getValue());
|
||||
}
|
||||
|
||||
public void testFailureStopsTethering_Wifi() {
|
||||
mProvisionResponse = Activity.RESULT_CANCELED;
|
||||
|
||||
runProvisioningForType(TETHERING_WIFI);
|
||||
|
||||
assertTrue(waitForProvisionRequest(TETHERING_WIFI));
|
||||
assertTrue(waitForProvisionResponse(TETHER_ERROR_PROVISIONING_FAILED));
|
||||
|
||||
verify(mTetheringManager).stopTethering(TETHERING_WIFI);
|
||||
}
|
||||
|
||||
public void testFailureStopsTethering_Usb() {
|
||||
mProvisionResponse = Activity.RESULT_CANCELED;
|
||||
|
||||
runProvisioningForType(TETHERING_USB);
|
||||
|
||||
assertTrue(waitForProvisionRequest(TETHERING_USB));
|
||||
assertTrue(waitForProvisionResponse(TETHER_ERROR_PROVISIONING_FAILED));
|
||||
|
||||
verify(mTetheringManager).stopTethering(TETHERING_USB);
|
||||
}
|
||||
|
||||
public void testIgnoreOutdatedRequest() {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(EXTRA_ADD_TETHER_TYPE, TETHERING_WIFI);
|
||||
intent.putExtra(EXTRA_RUN_PROVISION, true);
|
||||
intent.putExtra(EXTRA_TETHER_SILENT_PROVISIONING_ACTION, TEST_NO_UI_ACTION);
|
||||
intent.putExtra(EXTRA_PROVISION_CALLBACK, mResultReceiver);
|
||||
intent.putExtra(EXTRA_TETHER_SUBID, 1 /* Tested subId number */);
|
||||
intent.putExtra(EXTRA_TETHER_PROVISIONING_RESPONSE, TEST_RESPONSE_ACTION);
|
||||
startService(intent);
|
||||
|
||||
SystemClock.sleep(PROVISION_TIMEOUT);
|
||||
assertEquals(TETHERING_INVALID, mLastTetherRequestType);
|
||||
assertTrue(mWrapper.isAppInactive(ENTITLEMENT_PACKAGE_NAME));
|
||||
assertTrue(mWrapper.isAppInactive(FAKE_PACKAGE_NAME));
|
||||
}
|
||||
|
||||
private void runProvisioningForType(int type) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(EXTRA_ADD_TETHER_TYPE, type);
|
||||
intent.putExtra(EXTRA_RUN_PROVISION, true);
|
||||
intent.putExtra(EXTRA_TETHER_SILENT_PROVISIONING_ACTION, TEST_NO_UI_ACTION);
|
||||
intent.putExtra(EXTRA_PROVISION_CALLBACK, mResultReceiver);
|
||||
intent.putExtra(EXTRA_TETHER_SUBID, INVALID_SUBSCRIPTION_ID);
|
||||
intent.putExtra(EXTRA_TETHER_PROVISIONING_RESPONSE, TEST_RESPONSE_ACTION);
|
||||
startService(intent);
|
||||
}
|
||||
|
||||
private boolean waitForAppInactive(UsageStatsManager usageStatsManager, String packageName) {
|
||||
long startTime = SystemClock.uptimeMillis();
|
||||
while (true) {
|
||||
if (usageStatsManager.isAppInactive(packageName)) {
|
||||
return true;
|
||||
}
|
||||
if ((SystemClock.uptimeMillis() - startTime) > PROVISION_TIMEOUT) {
|
||||
return false;
|
||||
}
|
||||
SystemClock.sleep(SHORT_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean waitForProvisionRequest(int expectedType) {
|
||||
long startTime = SystemClock.uptimeMillis();
|
||||
while (true) {
|
||||
if (mLastTetherRequestType == expectedType) {
|
||||
mLastTetherRequestType = TETHERING_INVALID;
|
||||
return true;
|
||||
}
|
||||
if ((SystemClock.uptimeMillis() - startTime) > PROVISION_TIMEOUT) {
|
||||
Log.v(TAG, String.format(
|
||||
"waitForProvisionRequest timeout: expected=%d, actual=%d",
|
||||
expectedType, mLastTetherRequestType));
|
||||
return false;
|
||||
}
|
||||
SystemClock.sleep(SHORT_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean waitForProvisionResponse(int expectedValue) {
|
||||
long startTime = SystemClock.uptimeMillis();
|
||||
while (true) {
|
||||
if (mLastReceiverResultCode == expectedValue) {
|
||||
mLastReceiverResultCode = BOGUS_RECEIVER_RESULT;
|
||||
return true;
|
||||
}
|
||||
if ((SystemClock.uptimeMillis() - startTime) > PROVISION_TIMEOUT) {
|
||||
Log.v(TAG, String.format(
|
||||
"waitForProvisionResponse timeout: expected=%d, actual=%d",
|
||||
expectedValue, mLastReceiverResultCode));
|
||||
return false;
|
||||
}
|
||||
SystemClock.sleep(SHORT_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
private class TestContextWrapper extends ContextWrapper {
|
||||
|
||||
public TestContextWrapper(Context base) {
|
||||
super(base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SharedPreferences getSharedPreferences(String name, int mode) {
|
||||
// Stub out prefs to control the persisted tether type list.
|
||||
if (name == "tetherPrefs") {
|
||||
return mPrefs;
|
||||
}
|
||||
return super.getSharedPreferences(name, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageManager getPackageManager() {
|
||||
return mPackageManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSystemService(String name) {
|
||||
if (TETHERING_SERVICE.equals(name)) {
|
||||
return mTetheringManager;
|
||||
} else if (WIFI_SERVICE.equals(name)) {
|
||||
return mWifiManager;
|
||||
}
|
||||
|
||||
return super.getSystemService(name);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class Receiver extends ResultReceiver {
|
||||
final WeakReference<TetherServiceTest> mTest;
|
||||
|
||||
Receiver(TetherServiceTest test) {
|
||||
super(null);
|
||||
mTest = new WeakReference<TetherServiceTest>(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onReceiveResult(int resultCode, Bundle resultData) {
|
||||
TetherServiceTest test = mTest.get();
|
||||
if (test != null) {
|
||||
test.mLastReceiverResultCode = resultCode;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stubs out the provisioning app receiver.
|
||||
*/
|
||||
private class ProvisionReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
mLastTetherRequestType = intent.getIntExtra("TETHER_TYPE", TETHERING_INVALID);
|
||||
sendResponse(mProvisionResponse, context);
|
||||
}
|
||||
|
||||
private void sendResponse(int response, Context context) {
|
||||
Intent responseIntent = new Intent(TEST_RESPONSE_ACTION);
|
||||
responseIntent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
|
||||
responseIntent.putExtra(TetherService.EXTRA_RESULT, response);
|
||||
context.sendBroadcast(
|
||||
responseIntent, android.Manifest.permission.TETHER_PRIVILEGED);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MockTetherServiceWrapper
|
||||
extends TetherService.TetherServiceWrapper {
|
||||
private final Set<String> mActivePackages;
|
||||
|
||||
MockTetherServiceWrapper(Context context) {
|
||||
super(context);
|
||||
mActivePackages = new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
void setAppInactive(String packageName, boolean isInactive) {
|
||||
if (!isInactive) {
|
||||
mActivePackages.add(packageName);
|
||||
} else {
|
||||
mActivePackages.remove(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
boolean isAppInactive(String packageName) {
|
||||
return !mActivePackages.contains(packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
int getActiveDataSubscriptionId() {
|
||||
return INVALID_SUBSCRIPTION_ID;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.wifi.tether;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Intent;
|
||||
import android.support.test.uiautomator.By;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
import android.support.test.uiautomator.UiObject2;
|
||||
import android.support.test.uiautomator.Until;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class WifiTetherSettingsTest {
|
||||
|
||||
private static final long TIMEOUT = 2000L;
|
||||
|
||||
private Instrumentation mInstrumentation;
|
||||
private Intent mTetherActivityIntent;
|
||||
private UiDevice mDevice;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mInstrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
mDevice = UiDevice.getInstance(mInstrumentation);
|
||||
mTetherActivityIntent = new Intent()
|
||||
.setClassName(mInstrumentation.getTargetContext().getPackageName(),
|
||||
Settings.TetherSettingsActivity.class.getName())
|
||||
.setPackage(mInstrumentation.getTargetContext().getPackageName())
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
mDevice.pressHome();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchTetherSettings_shouldHaveAllFields() {
|
||||
launchWifiTetherActivity();
|
||||
onView(withText("Hotspot name")).check(matches(isDisplayed()));
|
||||
onView(withText("Hotspot password")).check(matches(isDisplayed()));
|
||||
}
|
||||
|
||||
private void launchWifiTetherActivity() {
|
||||
mInstrumentation.startActivitySync(mTetherActivityIntent);
|
||||
onView(withText("Wi‑Fi hotspot")).perform();
|
||||
UiObject2 item = mDevice.wait(Until.findObject(By.text("Wi‑Fi hotspot")), TIMEOUT);
|
||||
item.click();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user