diff options
Diffstat (limited to 'test-runner/android')
4 files changed, 50 insertions, 14 deletions
diff --git a/test-runner/android/test/IsolatedContext.java b/test-runner/android/test/IsolatedContext.java index 2866666..03d95b7 100644 --- a/test-runner/android/test/IsolatedContext.java +++ b/test-runner/android/test/IsolatedContext.java @@ -2,6 +2,8 @@ package android.test; import com.google.android.collect.Lists; +import android.accounts.AccountManager; +import android.accounts.OnAccountsUpdatedListener; import android.content.ContextWrapper; import android.content.ContentResolver; import android.content.Intent; @@ -11,6 +13,8 @@ import android.content.BroadcastReceiver; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.net.Uri; +import android.os.Handler; +import android.os.Looper; import java.util.List; @@ -21,6 +25,7 @@ import java.util.List; public class IsolatedContext extends ContextWrapper { private ContentResolver mResolver; + private final MockAccountManager mMockAccountManager; private List<Intent> mBroadcastIntents = Lists.newArrayList(); @@ -28,6 +33,7 @@ public class IsolatedContext extends ContextWrapper { ContentResolver resolver, Context targetContext) { super(targetContext); mResolver = resolver; + mMockAccountManager = new MockAccountManager(); } /** Returns the list of intents that were broadcast since the last call to this method. */ @@ -78,8 +84,21 @@ public class IsolatedContext extends ContextWrapper { @Override public Object getSystemService(String name) { - // No services exist in this context. + if (Context.ACCOUNT_SERVICE.equals(name)) { + return mMockAccountManager; + } + // No other services exist in this context. return null; } + private class MockAccountManager extends AccountManager { + public MockAccountManager() { + super(IsolatedContext.this, null /* IAccountManager */, null /* handler */); + } + + public void addOnAccountsUpdatedListener(OnAccountsUpdatedListener listener, + Handler handler, boolean updateImmediately) { + // do nothing + } + } } diff --git a/test-runner/android/test/SyncBaseInstrumentation.java b/test-runner/android/test/SyncBaseInstrumentation.java index 772d75c..bf9e783 100644 --- a/test-runner/android/test/SyncBaseInstrumentation.java +++ b/test-runner/android/test/SyncBaseInstrumentation.java @@ -22,6 +22,7 @@ import android.os.Bundle; import android.os.RemoteException; import android.os.SystemClock; import android.net.Uri; +import android.accounts.Account; /** * If you would like to test sync a single provider with an @@ -47,7 +48,8 @@ public class SyncBaseInstrumentation extends InstrumentationTestCase { protected void syncProvider(Uri uri, String account, String authority) throws Exception { Bundle extras = new Bundle(); extras.putBoolean(ContentResolver.SYNC_EXTRAS_FORCE, true); - extras.putString(ContentResolver.SYNC_EXTRAS_ACCOUNT, account); + Account account1 = new Account(account, "com.google.GAIA"); + extras.putParcelable(ContentResolver.SYNC_EXTRAS_ACCOUNT, account1); mContentResolver.startSync(uri, extras); long startTimeInMillis = SystemClock.elapsedRealtime(); @@ -64,7 +66,7 @@ public class SyncBaseInstrumentation extends InstrumentationTestCase { break; } - if (isSyncActive(account, authority)) { + if (isSyncActive(account1, authority)) { counter = 0; continue; } @@ -85,7 +87,7 @@ public class SyncBaseInstrumentation extends InstrumentationTestCase { * entry is in either the Pending or Active tables. * @return */ - private boolean isSyncActive(String account, String authority) { + private boolean isSyncActive(Account account, String authority) { try { return ContentResolver.getContentService().isSyncActive(account, authority); diff --git a/test-runner/android/test/mock/MockContentProvider.java b/test-runner/android/test/mock/MockContentProvider.java index d04fc44..74f86d8 100644 --- a/test-runner/android/test/mock/MockContentProvider.java +++ b/test-runner/android/test/mock/MockContentProvider.java @@ -18,7 +18,11 @@ package android.test.mock; import android.content.ContentValues; import android.content.IContentProvider; -import android.content.ISyncAdapter; +import android.content.Entity; +import android.content.EntityIterator; +import android.content.ContentProviderResult; +import android.content.ContentProviderOperation; +import android.content.OperationApplicationException; import android.content.res.AssetFileDescriptor; import android.database.Cursor; import android.database.CursorWindow; @@ -30,6 +34,7 @@ import android.os.IBinder; import android.os.ParcelFileDescriptor; import java.io.FileNotFoundException; +import java.util.ArrayList; /** * Mock implementation of IContentProvider that does nothing. All methods are non-functional and @@ -48,6 +53,10 @@ public class MockContentProvider implements IContentProvider { return 0; } + public Uri insertEntity(Uri uri, Entity entities) throws RemoteException { + throw new UnsupportedOperationException("unimplemented mock method"); + } + @SuppressWarnings("unused") public IBulkCursor bulkQuery(Uri url, String[] projection, String selection, String[] selectionArgs, String sortOrder, IContentObserver observer, @@ -62,11 +71,6 @@ public class MockContentProvider implements IContentProvider { } @SuppressWarnings("unused") - public ISyncAdapter getSyncAdapter() throws RemoteException { - throw new UnsupportedOperationException("unimplemented mock method"); - } - - @SuppressWarnings("unused") public String getType(Uri url) throws RemoteException { throw new UnsupportedOperationException("unimplemented mock method"); } @@ -87,19 +91,33 @@ public class MockContentProvider implements IContentProvider { throws FileNotFoundException { throw new UnsupportedOperationException("unimplemented mock method"); } - + + public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) + throws RemoteException, OperationApplicationException { + throw new UnsupportedOperationException("unimplemented mock method"); + } + @SuppressWarnings("unused") public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs, String sortOrder) throws RemoteException { throw new UnsupportedOperationException("unimplemented mock method"); } + public EntityIterator queryEntities(Uri url, String selection, String[] selectionArgs, + String sortOrder) throws RemoteException { + throw new UnsupportedOperationException("unimplemented mock method"); + } + @SuppressWarnings("unused") public int update(Uri url, ContentValues values, String selection, String[] selectionArgs) throws RemoteException { throw new UnsupportedOperationException("unimplemented mock method"); } + public int updateEntity(Uri uri, Entity entity) throws RemoteException { + throw new UnsupportedOperationException("unimplemented mock method"); + } + public IBinder asBinder() { throw new UnsupportedOperationException("unimplemented mock method"); } diff --git a/test-runner/android/test/mock/MockPackageManager.java b/test-runner/android/test/mock/MockPackageManager.java index d5cd6ef..63a177e 100644 --- a/test-runner/android/test/mock/MockPackageManager.java +++ b/test-runner/android/test/mock/MockPackageManager.java @@ -292,9 +292,6 @@ public class MockPackageManager extends PackageManager { throw new UnsupportedOperationException(); } - /** - * @hide - to match hiding in superclass - */ @Override public String getInstallerPackageName(String packageName) { throw new UnsupportedOperationException(); |