use of android.test.mock.MockContentResolver in project android_frameworks_base by crdroidandroid.
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 crdroidandroid.
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 crdroidandroid.
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 crdroidandroid.
the class TestContext method testPurgeActiveSync.
/**
* Test that we handle the case of a history row being old enough to purge before the
* corresponding sync is finished. This can happen if the clock changes while we are syncing.
*
*/
// TODO: this test causes AidlTest to fail. Omit for now
// @SmallTest
public void testPurgeActiveSync() throws Exception {
final Account account = new Account("a@example.com", "example.type");
final String authority = "testprovider";
MockContentResolver mockResolver = new MockContentResolver();
SyncStorageEngine engine = SyncStorageEngine.newTestInstance(new TestContext(mockResolver, getContext()));
long time0 = 1000;
SyncOperation op = new SyncOperation(account, 0, 0, "foo", SyncOperation.REASON_PERIODIC, SyncStorageEngine.SOURCE_LOCAL, authority, Bundle.EMPTY, true);
long historyId = engine.insertStartSyncEvent(op, time0);
long time1 = time0 + SyncStorageEngine.MILLIS_IN_4WEEKS * 2;
engine.stopSyncEvent(historyId, time1 - time0, "yay", 0, 0);
}
use of android.test.mock.MockContentResolver in project platform_frameworks_base by android.
the class IpManagerTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
when(mContext.getResources()).thenReturn(mResources);
when(mResources.getInteger(R.integer.config_networkAvoidBadWifi)).thenReturn(DEFAULT_AVOIDBADWIFI_CONFIG_VALUE);
mContentResolver = new MockContentResolver();
mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
when(mContext.getContentResolver()).thenReturn(mContentResolver);
}
Aggregations