use of android.test.mock.MockContentResolver in project android_frameworks_base by ParanoidAndroid.
the class TestContext method testAuthorityPersistence.
@LargeTest
public void testAuthorityPersistence() throws Exception {
final Account account1 = new Account("a@example.com", "example.type");
final Account account2 = new Account("b@example.com", "example.type.2");
final String authority1 = "testprovider1";
final String authority2 = "testprovider2";
final Bundle extras1 = new Bundle();
extras1.putString("a", "1");
final Bundle extras2 = new Bundle();
extras2.putString("a", "2");
extras2.putLong("b", 2);
extras2.putInt("c", 1);
extras2.putBoolean("d", true);
extras2.putDouble("e", 1.2);
extras2.putFloat("f", 4.5f);
extras2.putParcelable("g", account1);
final int period1 = 200;
final int period2 = 1000;
PeriodicSync sync1 = new PeriodicSync(account1, authority1, extras1, period1);
PeriodicSync sync2 = new PeriodicSync(account1, authority1, extras2, period1);
PeriodicSync sync3 = new PeriodicSync(account1, authority2, extras1, period1);
PeriodicSync sync4 = new PeriodicSync(account1, authority2, extras2, period2);
PeriodicSync sync5 = new PeriodicSync(account2, authority1, extras1, period1);
MockContentResolver mockResolver = new MockContentResolver();
SyncStorageEngine engine = SyncStorageEngine.newTestInstance(new TestContext(mockResolver, getContext()));
removePeriodicSyncs(engine, account1, 0, authority1);
removePeriodicSyncs(engine, account2, 0, authority1);
removePeriodicSyncs(engine, account1, 0, authority2);
removePeriodicSyncs(engine, account2, 0, authority2);
engine.setMasterSyncAutomatically(false, 0);
engine.setIsSyncable(account1, 0, authority1, 1);
engine.setSyncAutomatically(account1, 0, authority1, true);
engine.setIsSyncable(account2, 0, authority1, 1);
engine.setSyncAutomatically(account2, 0, authority1, true);
engine.setIsSyncable(account1, 0, authority2, 1);
engine.setSyncAutomatically(account1, 0, authority2, false);
engine.setIsSyncable(account2, 0, authority2, 0);
engine.setSyncAutomatically(account2, 0, authority2, true);
engine.addPeriodicSync(sync1.account, 0, sync1.authority, sync1.extras, sync1.period);
engine.addPeriodicSync(sync2.account, 0, sync2.authority, sync2.extras, sync2.period);
engine.addPeriodicSync(sync3.account, 0, sync3.authority, sync3.extras, sync3.period);
engine.addPeriodicSync(sync4.account, 0, sync4.authority, sync4.extras, sync4.period);
engine.addPeriodicSync(sync5.account, 0, sync5.authority, sync5.extras, sync5.period);
engine.writeAllState();
engine.clearAndReadState();
List<PeriodicSync> syncs = engine.getPeriodicSyncs(account1, 0, authority1);
assertEquals(2, syncs.size());
assertEquals(sync1, syncs.get(0));
assertEquals(sync2, syncs.get(1));
syncs = engine.getPeriodicSyncs(account1, 0, authority2);
assertEquals(2, syncs.size());
assertEquals(sync3, syncs.get(0));
assertEquals(sync4, syncs.get(1));
syncs = engine.getPeriodicSyncs(account2, 0, authority1);
assertEquals(1, syncs.size());
assertEquals(sync5, syncs.get(0));
assertEquals(true, engine.getSyncAutomatically(account1, 0, authority1));
assertEquals(true, engine.getSyncAutomatically(account2, 0, authority1));
assertEquals(false, engine.getSyncAutomatically(account1, 0, authority2));
assertEquals(true, engine.getSyncAutomatically(account2, 0, authority2));
assertEquals(1, engine.getIsSyncable(account1, 0, authority1));
assertEquals(1, engine.getIsSyncable(account2, 0, authority1));
assertEquals(1, engine.getIsSyncable(account1, 0, authority2));
assertEquals(0, engine.getIsSyncable(account2, 0, authority2));
}
use of android.test.mock.MockContentResolver in project android_frameworks_base by ResurrectionRemix.
the class TestContext method setUp.
@Override
public void setUp() {
account1 = new Account("a@example.com", "example.type");
account2 = new Account("b@example.com", "example.type");
syncService1 = new ComponentName("com.example", "SyncService");
// Default bundle.
defaultBundle = new Bundle();
defaultBundle.putInt("int_key", 0);
defaultBundle.putString("string_key", "hello");
// Set up storage engine.
mockResolver = new MockContentResolver();
engine = SyncStorageEngine.newTestInstance(new TestContext(mockResolver, getContext()));
}
use of android.test.mock.MockContentResolver in project android_frameworks_base by ResurrectionRemix.
the class TestContext method testAuthorityRenaming.
@MediumTest
public void testAuthorityRenaming() throws Exception {
final Account account1 = new Account("acc1", "type1");
final Account account2 = new Account("acc2", "type2");
final String authorityContacts = "contacts";
final String authorityCalendar = "calendar";
final String authorityOther = "other";
final String authorityContactsNew = "com.android.contacts";
final String authorityCalendarNew = "com.android.calendar";
MockContentResolver mockResolver = new MockContentResolver();
final TestContext testContext = new TestContext(mockResolver, getContext());
byte[] accountsFileData = ("<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n" + "<accounts>\n" + "<authority id=\"0\" account=\"acc1\" type=\"type1\" authority=\"contacts\" />\n" + "<authority id=\"1\" account=\"acc1\" type=\"type1\" authority=\"calendar\" />\n" + "<authority id=\"2\" account=\"acc1\" type=\"type1\" authority=\"other\" />\n" + "<authority id=\"3\" account=\"acc2\" type=\"type2\" authority=\"contacts\" />\n" + "<authority id=\"4\" account=\"acc2\" type=\"type2\" authority=\"calendar\" />\n" + "<authority id=\"5\" account=\"acc2\" type=\"type2\" authority=\"other\" />\n" + "<authority id=\"6\" account=\"acc2\" type=\"type2\" enabled=\"false\"" + " authority=\"com.android.calendar\" />\n" + "<authority id=\"7\" account=\"acc2\" type=\"type2\" enabled=\"false\"" + " authority=\"com.android.contacts\" />\n" + "</accounts>\n").getBytes();
File syncDir = new File(new File(testContext.getFilesDir(), "system"), "sync");
syncDir.mkdirs();
AtomicFile accountInfoFile = new AtomicFile(new File(syncDir, "accounts.xml"));
FileOutputStream fos = accountInfoFile.startWrite();
fos.write(accountsFileData);
accountInfoFile.finishWrite(fos);
SyncStorageEngine engine = SyncStorageEngine.newTestInstance(testContext);
assertEquals(false, engine.getSyncAutomatically(account1, 0, authorityContacts));
assertEquals(false, engine.getSyncAutomatically(account1, 0, authorityCalendar));
assertEquals(true, engine.getSyncAutomatically(account1, 0, authorityOther));
assertEquals(true, engine.getSyncAutomatically(account1, 0, authorityContactsNew));
assertEquals(true, engine.getSyncAutomatically(account1, 0, authorityCalendarNew));
assertEquals(false, engine.getSyncAutomatically(account2, 0, authorityContacts));
assertEquals(false, engine.getSyncAutomatically(account2, 0, authorityCalendar));
assertEquals(true, engine.getSyncAutomatically(account2, 0, authorityOther));
assertEquals(false, engine.getSyncAutomatically(account2, 0, authorityContactsNew));
assertEquals(false, engine.getSyncAutomatically(account2, 0, authorityCalendarNew));
}
use of android.test.mock.MockContentResolver in project android_frameworks_base by ResurrectionRemix.
the class ProviderTestCase method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
mResolver = new MockContentResolver();
final String filenamePrefix = "test.";
RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(// The context that most methods are delegated to
new MockContext(), // The context that file methods are delegated to
getInstrumentation().getTargetContext(), filenamePrefix);
mProviderContext = new IsolatedContext(mResolver, targetContextWrapper);
mProvider = ProviderTestCase2.createProviderForTest(mProviderContext, mProviderClass, mProviderAuthority);
mResolver.addProvider(mProviderAuthority, getProvider());
}
use of android.test.mock.MockContentResolver in project android_frameworks_base by ResurrectionRemix.
the class ProviderTestCase method newResolverWithContentProviderFromSql.
public static <T extends ContentProvider> ContentResolver newResolverWithContentProviderFromSql(Context targetContext, Class<T> providerClass, String authority, String databaseName, int databaseVersion, String sql) throws IllegalAccessException, InstantiationException {
final String filenamePrefix = "test.";
MockContentResolver resolver = new MockContentResolver();
RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(// The context that most methods are delegated to
new MockContext(), // The context that file methods are delegated to
targetContext, filenamePrefix);
Context context = new IsolatedContext(resolver, targetContextWrapper);
DatabaseUtils.createDbFromSqlStatements(context, databaseName, databaseVersion, sql);
T provider = ProviderTestCase2.createProviderForTest(context, providerClass, authority);
resolver.addProvider(authority, provider);
return resolver;
}
Aggregations