summaryrefslogtreecommitdiffstats
path: root/tests/src/com/android
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-07-19 10:58:58 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-07-19 10:58:58 -0700
commit1aa26989047495ff58d3e2598d3f9549465cbb65 (patch)
tree78826ba7ac8cd747f1fa695eb7d747f78e958920 /tests/src/com/android
parentabb997df34680a8b2b733acbc2313991226c69d6 (diff)
parentaf28400b74de05862b470412a5c92f68e99f59f8 (diff)
downloadandroid_packages_providers_DownloadProvider-1aa26989047495ff58d3e2598d3f9549465cbb65.tar.gz
android_packages_providers_DownloadProvider-1aa26989047495ff58d3e2598d3f9549465cbb65.tar.bz2
android_packages_providers_DownloadProvider-1aa26989047495ff58d3e2598d3f9549465cbb65.zip
Merge "Introduce a seam to ConnectivityManager and TelephonyManager" into gingerbread
Diffstat (limited to 'tests/src/com/android')
-rw-r--r--tests/src/com/android/providers/downloads/AbstractDownloadManagerFunctionalTest.java6
-rw-r--r--tests/src/com/android/providers/downloads/DownloadManagerFunctionalTest.java31
-rw-r--r--tests/src/com/android/providers/downloads/FakeIConnectivityManager.java153
-rw-r--r--tests/src/com/android/providers/downloads/FakeSystemFacade.java20
4 files changed, 46 insertions, 164 deletions
diff --git a/tests/src/com/android/providers/downloads/AbstractDownloadManagerFunctionalTest.java b/tests/src/com/android/providers/downloads/AbstractDownloadManagerFunctionalTest.java
index 06dd52af..326d9fff 100644
--- a/tests/src/com/android/providers/downloads/AbstractDownloadManagerFunctionalTest.java
+++ b/tests/src/com/android/providers/downloads/AbstractDownloadManagerFunctionalTest.java
@@ -21,7 +21,6 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
-import android.net.ConnectivityManager;
import android.provider.Downloads;
import android.test.MoreAsserts;
import android.test.RenamingDelegatingContext;
@@ -77,7 +76,6 @@ public abstract class AbstractDownloadManagerFunctionalTest extends
private ContentResolver mResolver;
boolean mHasServiceBeenStarted = false;
- FakeIConnectivityManager mFakeIConnectivityManager;
public TestContext(Context realContext) {
super(realContext, FILENAME_PREFIX);
@@ -86,7 +84,6 @@ public abstract class AbstractDownloadManagerFunctionalTest extends
Context.NOTIFICATION_SERVICE,
Context.POWER_SERVICE,
}));
- mFakeIConnectivityManager = new FakeIConnectivityManager();
}
public void setResolver(ContentResolver resolver) {
@@ -107,9 +104,6 @@ public abstract class AbstractDownloadManagerFunctionalTest extends
*/
@Override
public Object getSystemService(String name) {
- if (name.equals(Context.CONNECTIVITY_SERVICE)) {
- return new ConnectivityManager(mFakeIConnectivityManager);
- }
if (mAllowedSystemServices.contains(name)) {
return mRealContext.getSystemService(name);
}
diff --git a/tests/src/com/android/providers/downloads/DownloadManagerFunctionalTest.java b/tests/src/com/android/providers/downloads/DownloadManagerFunctionalTest.java
index 7de90de5..3cd9cf58 100644
--- a/tests/src/com/android/providers/downloads/DownloadManagerFunctionalTest.java
+++ b/tests/src/com/android/providers/downloads/DownloadManagerFunctionalTest.java
@@ -18,7 +18,7 @@ package com.android.providers.downloads;
import android.content.ContentValues;
import android.database.Cursor;
-import android.net.NetworkInfo;
+import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Environment;
import android.provider.Downloads;
@@ -102,12 +102,35 @@ public class DownloadManagerFunctionalTest extends AbstractDownloadManagerFuncti
Uri downloadUri = requestDownload("/path");
// without connectivity, download immediately pauses
- mTestContext.mFakeIConnectivityManager.setNetworkState(NetworkInfo.State.DISCONNECTED);
+ mSystemFacade.mActiveNetworkType = null;
startService(null);
- super.waitForDownloadToStop(getStatusReader(downloadUri), Downloads.STATUS_RUNNING_PAUSED);
+ waitForDownloadToStop(getStatusReader(downloadUri), Downloads.STATUS_RUNNING_PAUSED);
// connecting should start the download
- mTestContext.mFakeIConnectivityManager.setNetworkState(NetworkInfo.State.CONNECTED);
+ mSystemFacade.mActiveNetworkType = ConnectivityManager.TYPE_WIFI;
+ runUntilStatus(downloadUri, Downloads.STATUS_SUCCESS);
+ }
+
+ public void testRoaming() throws Exception {
+ mSystemFacade.mActiveNetworkType = ConnectivityManager.TYPE_MOBILE;
+ mSystemFacade.mIsRoaming = true;
+
+ // for a normal download, roaming is fine
+ enqueueResponse(HTTP_OK, FILE_CONTENT);
+ Uri downloadUri = requestDownload("/path");
+ startService(null);
+ runUntilStatus(downloadUri, Downloads.STATUS_SUCCESS);
+
+ // when roaming is disallowed, the download should pause...
+ downloadUri = requestDownload("/path");
+ updateDownload(downloadUri, Downloads.COLUMN_DESTINATION,
+ Integer.toString(Downloads.DESTINATION_CACHE_PARTITION_NOROAMING));
+ startService(null);
+ waitForDownloadToStop(getStatusReader(downloadUri), Downloads.STATUS_RUNNING_PAUSED);
+
+ // ...and pick up when we're off roaming
+ enqueueResponse(HTTP_OK, FILE_CONTENT);
+ mSystemFacade.mIsRoaming = false;
runUntilStatus(downloadUri, Downloads.STATUS_SUCCESS);
}
diff --git a/tests/src/com/android/providers/downloads/FakeIConnectivityManager.java b/tests/src/com/android/providers/downloads/FakeIConnectivityManager.java
deleted file mode 100644
index 424411f8..00000000
--- a/tests/src/com/android/providers/downloads/FakeIConnectivityManager.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (C) 2010 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.providers.downloads;
-
-import android.net.ConnectivityManager;
-import android.net.IConnectivityManager;
-import android.net.NetworkInfo;
-import android.net.NetworkInfo.State;
-import android.os.IBinder;
-import android.os.RemoteException;
-
-class FakeIConnectivityManager implements IConnectivityManager {
- private static class MockNetworkInfo extends NetworkInfo {
- private State mState;
-
- @SuppressWarnings("deprecation")
- public MockNetworkInfo(State state) {
- super(0);
- mState = state;
- }
-
- @Override
- public State getState() {
- return mState;
- }
-
- @Override
- public int getType() {
- return ConnectivityManager.TYPE_MOBILE;
- }
- }
-
- private State mCurrentState = State.CONNECTED;
-
- public void setNetworkState(State state) {
- mCurrentState = state;
- }
-
- public IBinder asBinder() {
- throw new UnsupportedOperationException();
- }
-
- public NetworkInfo getActiveNetworkInfo() throws RemoteException {
- return new MockNetworkInfo(mCurrentState);
- }
-
- public NetworkInfo[] getAllNetworkInfo() throws RemoteException {
- return new NetworkInfo[] {getActiveNetworkInfo()};
- }
-
- public boolean getBackgroundDataSetting() throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public int getLastTetherError(String iface) throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public boolean getMobileDataEnabled() throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public NetworkInfo getNetworkInfo(int networkType) throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public int getNetworkPreference() throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public String[] getTetherableIfaces() throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public String[] getTetherableUsbRegexs() throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public String[] getTetherableWifiRegexs() throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public String[] getTetheredIfaces() throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public String[] getTetheringErroredIfaces() throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public boolean isTetheringSupported() throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public void requestNetworkTransitionWakelock(String forWhom) {
- throw new UnsupportedOperationException();
- }
-
- public boolean requestRouteToHost(int networkType, int hostAddress) throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public void setBackgroundDataSetting(boolean allowBackgroundData) throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public void setMobileDataEnabled(boolean enabled) throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public void setNetworkPreference(int pref) throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public boolean setRadio(int networkType, boolean turnOn) throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public boolean setRadios(boolean onOff) throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public int startUsingNetworkFeature(int networkType, String feature, IBinder binder)
- throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public int stopUsingNetworkFeature(int networkType, String feature) throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public int tether(String iface) throws RemoteException {
- throw new UnsupportedOperationException();
- }
-
- public int untether(String iface) throws RemoteException {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/tests/src/com/android/providers/downloads/FakeSystemFacade.java b/tests/src/com/android/providers/downloads/FakeSystemFacade.java
index b75e663a..c48f815d 100644
--- a/tests/src/com/android/providers/downloads/FakeSystemFacade.java
+++ b/tests/src/com/android/providers/downloads/FakeSystemFacade.java
@@ -1,7 +1,13 @@
package com.android.providers.downloads;
+import android.net.ConnectivityManager;
+
+import java.util.BitSet;
+
public class FakeSystemFacade implements SystemFacade {
- private long mTimeMillis = 0;
+ long mTimeMillis = 0;
+ Integer mActiveNetworkType = ConnectivityManager.TYPE_WIFI;
+ boolean mIsRoaming = false;
void incrementTimeMillis(long delta) {
mTimeMillis += delta;
@@ -10,4 +16,16 @@ public class FakeSystemFacade implements SystemFacade {
public long currentTimeMillis() {
return mTimeMillis;
}
+
+ public BitSet getConnectedNetworkTypes() {
+ BitSet connectedTypes = new BitSet();
+ if (mActiveNetworkType != null) {
+ connectedTypes.set(mActiveNetworkType);
+ }
+ return connectedTypes;
+ }
+
+ public boolean isNetworkRoaming() {
+ return mIsRoaming;
+ }
}