[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,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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user