summaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/providers/downloads/FakeIConnectivityManager.java
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-06-09 17:50:07 -0700
committerSteve Howard <showard@google.com>2010-06-28 16:20:22 -0700
commitd6f9b5e72a135365f2358d79b3ea3c9f7cb99c8e (patch)
tree5c0448812dd65aaed0f0f82018dbcac3ac218867 /tests/src/com/android/providers/downloads/FakeIConnectivityManager.java
parentaed3c4a57f6040349ef9e789646305c58227c35a (diff)
downloadandroid_packages_providers_DownloadProvider-d6f9b5e72a135365f2358d79b3ea3c9f7cb99c8e.tar.gz
android_packages_providers_DownloadProvider-d6f9b5e72a135365f2358d79b3ea3c9f7cb99c8e.tar.bz2
android_packages_providers_DownloadProvider-d6f9b5e72a135365f2358d79b3ea3c9f7cb99c8e.zip
First pass at a functional test for the Download Manager.
This "Large" test sets up an HTTP server on the device using MockWebServer and then initiates downloads from that server through the download manager. It uses ServiceTestCase to control the construction and execution of the DownloadService, and it uses some logic from ProviderTestCase2 to construct a DownloadProvider and a ContentResolver that uses it. This setup gives us some ability to mock dependencies. This commit includes use of a fake ConnectivityManager to test responses to connectivity changes, and use of some customizations to MockWebServer to test resuming an interrupted download. This test is disabled, though, since it requires a very long sleep. Avoiding that, and achieving certain other things, will require changes to the Download Manager code itself to introduce new seams. I wanted to check this in before I started such changes. Change-Id: Iefb13b3c3cccdc13fabe5cc18703e13244805539
Diffstat (limited to 'tests/src/com/android/providers/downloads/FakeIConnectivityManager.java')
-rw-r--r--tests/src/com/android/providers/downloads/FakeIConnectivityManager.java149
1 files changed, 149 insertions, 0 deletions
diff --git a/tests/src/com/android/providers/downloads/FakeIConnectivityManager.java b/tests/src/com/android/providers/downloads/FakeIConnectivityManager.java
new file mode 100644
index 00000000..0e92bd5f
--- /dev/null
+++ b/tests/src/com/android/providers/downloads/FakeIConnectivityManager.java
@@ -0,0 +1,149 @@
+/*
+ * 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 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();
+ }
+}