diff options
author | Eric Rowe <erowe@google.com> | 2014-09-09 19:25:55 -0700 |
---|---|---|
committer | Eric Rowe <erowe@google.com> | 2014-09-09 19:25:55 -0700 |
commit | 86e15557c52e2847d2adc8495a281dcf0239506e (patch) | |
tree | bac02331fbaf242a3707318f56a0273c8c012a96 /core | |
parent | f5031e549472d1d813fa39b6b2973cd20c1b1120 (diff) | |
download | frameworks_base-86e15557c52e2847d2adc8495a281dcf0239506e.zip frameworks_base-86e15557c52e2847d2adc8495a281dcf0239506e.tar.gz frameworks_base-86e15557c52e2847d2adc8495a281dcf0239506e.tar.bz2 |
Allow protected wifi in connectivity tests
Change-Id: I31285572f90bfb46cc28fb04e79cb9b407477a7d
Diffstat (limited to 'core')
3 files changed, 47 insertions, 28 deletions
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java index 77e1c53..80d5668 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java @@ -322,8 +322,13 @@ public class ConnectivityManagerTestBase extends InstrumentationTestCase { * If the device is already associated with a WiFi, disconnect and forget it, * We don't verify whether the connection is successful or not, leave this to the test */ - protected boolean connectToWifi(String knownSSID) { - WifiConfiguration config = WifiConfigurationHelper.createOpenConfig(knownSSID); + protected boolean connectToWifi(String ssid, String password) { + WifiConfiguration config; + if (password == null) { + config = WifiConfigurationHelper.createOpenConfig(ssid); + } else { + config = WifiConfigurationHelper.createPskConfig(ssid, password); + } return connectToWifiWithConfiguration(config); } diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestRunner.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestRunner.java index b94306a..b6eb674 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestRunner.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestRunner.java @@ -35,8 +35,9 @@ import junit.framework.TestSuite; */ public class ConnectivityManagerTestRunner extends InstrumentationTestRunner { - public boolean mWifiOnlyFlag = false; - public String mTestSsid = null; + public boolean mWifiOnly = false; + public String mSsid = null; + public String mPassword = null; @Override public TestSuite getAllTests() { @@ -54,13 +55,29 @@ public class ConnectivityManagerTestRunner extends InstrumentationTestRunner { @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); - String testSSID = (String) icicle.get("ssid"); - if (testSSID != null) { - mTestSsid = testSSID; + String ssid = icicle.getString("ssid"); + if (ssid != null) { + mSsid = ssid; + } + String password = (String) icicle.get("password"); + if (password != null) { + mPassword = password; } String wifiOnlyFlag = (String) icicle.get("wifi-only"); if (wifiOnlyFlag != null) { - mWifiOnlyFlag = true; + mWifiOnly = true; } } + + public String getWifiSsid() { + return mSsid; + } + + public String getWifiPassword() { + return mPassword; + } + + public boolean isWifiOnly() { + return mWifiOnly; + } } diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java index b280106..d5051df 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java @@ -33,7 +33,8 @@ public class ConnectivityManagerMobileTest extends ConnectivityManagerTestBase super(ConnectivityManagerMobileTest.class.getSimpleName()); } - private String mTestAccessPoint; + private String mSsid; + private String mPassword; private boolean mWifiOnlyFlag; @Override @@ -41,8 +42,9 @@ public class ConnectivityManagerMobileTest extends ConnectivityManagerTestBase super.setUp(); ConnectivityManagerTestRunner mRunner = (ConnectivityManagerTestRunner)getInstrumentation(); - mTestAccessPoint = mRunner.mTestSsid; - mWifiOnlyFlag = mRunner.mWifiOnlyFlag; + mSsid = mRunner.getWifiSsid(); + mPassword = mRunner.getWifiPassword(); + mWifiOnlyFlag = mRunner.isWifiOnly(); // Each test case will start with cellular connection if (Settings.Global.getInt(getInstrumentation().getContext().getContentResolver(), @@ -120,11 +122,10 @@ public class ConnectivityManagerMobileTest extends ConnectivityManagerTestBase // Test case 2: test connection to a given AP @LargeTest public void testConnectToWifi() { - assertNotNull("SSID is null", mTestAccessPoint); + assertNotNull("SSID is null", mSsid); // assert that we are able to connect to the ap - assertTrue("failed to connect to " + mTestAccessPoint, - connectToWifi(mTestAccessPoint)); + assertTrue("failed to connect to " + mSsid, connectToWifi(mSsid, mPassword)); // assert that WifiManager reports correct state assertTrue("wifi not enabled", waitForWifiState( WifiManager.WIFI_STATE_ENABLED, LONG_TIMEOUT)); @@ -144,14 +145,14 @@ public class ConnectivityManagerMobileTest extends ConnectivityManagerTestBase // Test case 3: connect & reconnect to Wifi with known AP @LargeTest public void testConnectToWifWithKnownAP() { - assertNotNull("SSID is null", mTestAccessPoint); + assertNotNull("SSID is null", mSsid); // enable WiFi assertTrue("failed to enable wifi", enableWifi()); // wait for wifi enable assertTrue("wifi not enabled", waitForWifiState( WifiManager.WIFI_STATE_ENABLED, LONG_TIMEOUT)); // Connect to AP - assertTrue("failed to connect to " + mTestAccessPoint, connectToWifi(mTestAccessPoint)); + assertTrue("failed to connect to " + mSsid, connectToWifi(mSsid, mPassword)); // verify wifi connected as reported by ConnectivityManager assertTrue("wifi not connected", waitForNetworkState( ConnectivityManager.TYPE_WIFI, State.CONNECTED, WIFI_CONNECTION_TIMEOUT)); @@ -191,7 +192,7 @@ public class ConnectivityManagerMobileTest extends ConnectivityManagerTestBase // Test case 4: test disconnect and clear wifi settings @LargeTest public void testDisconnectWifi() { - assertNotNull("SSID is null", mTestAccessPoint); + assertNotNull("SSID is null", mSsid); // enable WiFi assertTrue("failed to enable wifi", enableWifi()); @@ -199,8 +200,7 @@ public class ConnectivityManagerMobileTest extends ConnectivityManagerTestBase assertTrue("wifi not enabled", waitForWifiState( WifiManager.WIFI_STATE_ENABLED, LONG_TIMEOUT)); // connect to Wifi - assertTrue("failed to connect to " + mTestAccessPoint, - connectToWifi(mTestAccessPoint)); + assertTrue("failed to connect to " + mSsid, connectToWifi(mSsid, mPassword)); assertTrue("wifi not connected", waitForNetworkState( ConnectivityManager.TYPE_WIFI, State.CONNECTED, WIFI_CONNECTION_TIMEOUT)); @@ -257,7 +257,7 @@ public class ConnectivityManagerMobileTest extends ConnectivityManagerTestBase // Test case 6: test connectivity with airplane mode on but wifi enabled @LargeTest public void testDataConnectionOverAMWithWifi() { - assertNotNull("SSID is null", mTestAccessPoint); + assertNotNull("SSID is null", mSsid); // enable airplane mode mCm.setAirplaneMode(true); // assert there is active network connection after airplane mode disabled @@ -265,8 +265,7 @@ public class ConnectivityManagerMobileTest extends ConnectivityManagerTestBase waitUntilNoActiveNetworkConnection(LONG_TIMEOUT)); // connect to Wifi - assertTrue("failed to connect to " + mTestAccessPoint, - connectToWifi(mTestAccessPoint)); + assertTrue("failed to connect to " + mSsid, connectToWifi(mSsid, mPassword)); assertTrue("wifi not connected", waitForNetworkState( ConnectivityManager.TYPE_WIFI, State.CONNECTED, WIFI_CONNECTION_TIMEOUT)); // verify that connection actually works @@ -280,15 +279,14 @@ public class ConnectivityManagerMobileTest extends ConnectivityManagerTestBase @LargeTest public void testDataConnectionWithWifiToAMToWifi () { // connect to mTestAccessPoint - assertNotNull("SSID is null", mTestAccessPoint); + assertNotNull("SSID is null", mSsid); // enable WiFi assertTrue("failed to enable wifi", enableWifi()); // wait for wifi enable assertTrue("wifi not enabled", waitForWifiState( WifiManager.WIFI_STATE_ENABLED, LONG_TIMEOUT)); // connect to Wifi - assertTrue("failed to connect to " + mTestAccessPoint, - connectToWifi(mTestAccessPoint)); + assertTrue("failed to connect to " + mSsid, connectToWifi(mSsid, mPassword)); assertTrue("wifi not connected", waitForNetworkState( ConnectivityManager.TYPE_WIFI, State.CONNECTED, WIFI_CONNECTION_TIMEOUT)); @@ -313,15 +311,14 @@ public class ConnectivityManagerMobileTest extends ConnectivityManagerTestBase // Test case 8: test wifi state change while connecting/disconnecting to/from an AP @LargeTest public void testWifiStateChange () { - assertNotNull("SSID is null", mTestAccessPoint); + assertNotNull("SSID is null", mSsid); // enable WiFi assertTrue("failed to enable wifi", enableWifi()); // wait for wifi enable assertTrue("wifi not enabled", waitForWifiState( WifiManager.WIFI_STATE_ENABLED, LONG_TIMEOUT)); // connect to Wifi - assertTrue("failed to connect to " + mTestAccessPoint, - connectToWifi(mTestAccessPoint)); + assertTrue("failed to connect to " + mSsid, connectToWifi(mSsid, mPassword)); assertTrue("wifi not connected", waitForNetworkState( ConnectivityManager.TYPE_WIFI, State.CONNECTED, WIFI_CONNECTION_TIMEOUT)); assertNotNull("not associated with any AP", mWifiManager.getConnectionInfo().getBSSID()); |