am eb56ad18: am 08eb7dd6: Merge "extending timeout to stabilize tests" into ics-mr1

* commit 'eb56ad183af8a9833ff22a22b97f174f05266c58':
  extending timeout to stabilize tests
This commit is contained in:
Tsu Chiang Chuang
2012-02-13 13:45:06 -08:00
committed by Android Git Automerger
2 changed files with 18 additions and 7 deletions

View File

@ -90,6 +90,7 @@ public class BandwidthTest extends InstrumentationTestCase {
*/ */
@LargeTest @LargeTest
public void testWifiDownload() throws Exception { public void testWifiDownload() throws Exception {
mConnectionUtil.wifiTestInit();
assertTrue("Could not connect to wifi!", setDeviceWifiAndAirplaneMode(mSsid)); assertTrue("Could not connect to wifi!", setDeviceWifiAndAirplaneMode(mSsid));
downloadFile(); downloadFile();
} }
@ -143,6 +144,7 @@ public class BandwidthTest extends InstrumentationTestCase {
*/ */
@LargeTest @LargeTest
public void testWifiUpload() throws Exception { public void testWifiUpload() throws Exception {
mConnectionUtil.wifiTestInit();
assertTrue(setDeviceWifiAndAirplaneMode(mSsid)); assertTrue(setDeviceWifiAndAirplaneMode(mSsid));
uploadFile(); uploadFile();
} }
@ -197,6 +199,7 @@ public class BandwidthTest extends InstrumentationTestCase {
*/ */
@LargeTest @LargeTest
public void testWifiDownloadWithDownloadManager() throws Exception { public void testWifiDownloadWithDownloadManager() throws Exception {
mConnectionUtil.wifiTestInit();
assertTrue(setDeviceWifiAndAirplaneMode(mSsid)); assertTrue(setDeviceWifiAndAirplaneMode(mSsid));
downloadFileUsingDownloadManager(); downloadFileUsingDownloadManager();
} }
@ -286,6 +289,8 @@ public class BandwidthTest extends InstrumentationTestCase {
* @return true if we successfully connect to mobile data. * @return true if we successfully connect to mobile data.
*/ */
public boolean hasMobileData() { public boolean hasMobileData() {
assertTrue(mConnectionUtil.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
State.CONNECTED, ConnectionUtil.LONG_TIMEOUT));
assertTrue("Not connected to mobile", mConnectionUtil.isConnectedToMobile()); assertTrue("Not connected to mobile", mConnectionUtil.isConnectedToMobile());
assertFalse("Still connected to wifi.", mConnectionUtil.isConnectedToWifi()); assertFalse("Still connected to wifi.", mConnectionUtil.isConnectedToWifi());
return mConnectionUtil.hasData(); return mConnectionUtil.hasData();

View File

@ -57,7 +57,7 @@ public class ConnectionUtil {
private static final int WAIT_FOR_SCAN_RESULT = 10 * 1000; // 10 seconds private static final int WAIT_FOR_SCAN_RESULT = 10 * 1000; // 10 seconds
private static final int WIFI_SCAN_TIMEOUT = 50 * 1000; private static final int WIFI_SCAN_TIMEOUT = 50 * 1000;
public static final int SHORT_TIMEOUT = 5 * 1000; public static final int SHORT_TIMEOUT = 5 * 1000;
public static final int LONG_TIMEOUT = 10 * 1000; public static final int LONG_TIMEOUT = 120 * 1000; // 2 minutes
private ConnectivityReceiver mConnectivityReceiver = null; private ConnectivityReceiver mConnectivityReceiver = null;
private WifiReceiver mWifiReceiver = null; private WifiReceiver mWifiReceiver = null;
private DownloadReceiver mDownloadReceiver = null; private DownloadReceiver mDownloadReceiver = null;
@ -118,8 +118,14 @@ public class ConnectionUtil {
initializeNetworkStates(); initializeNetworkStates();
mWifiManager.setWifiEnabled(true);
}
/**
* Additional initialization needed for wifi related tests.
*/
public void wifiTestInit() {
mWifiManager.setWifiEnabled(true);
Log.v(LOG_TAG, "Clear Wifi before we start the test."); Log.v(LOG_TAG, "Clear Wifi before we start the test.");
sleep(SHORT_TIMEOUT); sleep(SHORT_TIMEOUT);
removeConfiguredNetworksAndDisableWifi(); removeConfiguredNetworksAndDisableWifi();
@ -146,10 +152,10 @@ public class ConnectionUtil {
Log.v("ConnectivityReceiver", "onReceive() called with " + intent); Log.v("ConnectivityReceiver", "onReceive() called with " + intent);
return; return;
} }
if (intent.hasExtra(ConnectivityManager.EXTRA_NETWORK_INFO)) {
mNetworkInfo = (NetworkInfo) final ConnectivityManager connManager = (ConnectivityManager) context
intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); .getSystemService(Context.CONNECTIVITY_SERVICE);
} mNetworkInfo = connManager.getActiveNetworkInfo();
if (intent.hasExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO)) { if (intent.hasExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO)) {
mOtherNetworkInfo = (NetworkInfo) mOtherNetworkInfo = (NetworkInfo)
@ -525,7 +531,7 @@ public class ConnectionUtil {
/** /**
* Connect to Wi-Fi with the given configuration. * Connect to Wi-Fi with the given configuration.
* @param config * @param config
* @return true if we ar connected to a given * @return true if we are connected to a given AP.
*/ */
public boolean connectToWifiWithConfiguration(WifiConfiguration config) { public boolean connectToWifiWithConfiguration(WifiConfiguration config) {
// The SSID in the configuration is a pure string, need to convert it to a quoted string. // The SSID in the configuration is a pure string, need to convert it to a quoted string.