Search in sources :

Example 51 with MockContentResolver

use of android.test.mock.MockContentResolver in project platform_frameworks_base by android.

the class TestContext method testSyncableMigration.

@SmallTest
public void testSyncableMigration() throws Exception {
    final Account account = new Account("acc", "type");
    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=\"acc\" authority=\"other1\" />\n" + "<authority id=\"1\" account=\"acc\" type=\"type\" authority=\"other2\" />\n" + "<authority id=\"2\" account=\"acc\" type=\"type\" syncable=\"false\"" + " authority=\"other3\" />\n" + "<authority id=\"3\" account=\"acc\" type=\"type\" syncable=\"true\"" + " authority=\"other4\" />\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(-1, engine.getIsSyncable(account, 0, "other1"));
    assertEquals(1, engine.getIsSyncable(account, 0, "other2"));
    assertEquals(0, engine.getIsSyncable(account, 0, "other3"));
    assertEquals(1, engine.getIsSyncable(account, 0, "other4"));
}
Also used : Account(android.accounts.Account) AtomicFile(com.android.internal.os.AtomicFile) FileOutputStream(java.io.FileOutputStream) MockContentResolver(android.test.mock.MockContentResolver) File(java.io.File) AtomicFile(com.android.internal.os.AtomicFile) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 52 with MockContentResolver

use of android.test.mock.MockContentResolver in project platform_frameworks_base by android.

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);
}
Also used : Account(android.accounts.Account) MockContentResolver(android.test.mock.MockContentResolver)

Example 53 with MockContentResolver

use of android.test.mock.MockContentResolver in project platform_frameworks_base by android.

the class TestContext method testListenForTicklesParsing.

@MediumTest
public void testListenForTicklesParsing() throws Exception {
    byte[] accountsFileData = ("<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n" + "<accounts>\n" + "<listenForTickles user=\"0\" enabled=\"false\" />" + "<listenForTickles user=\"1\" enabled=\"true\" />" + "<authority id=\"0\" user=\"0\" account=\"account1\" type=\"type1\" authority=\"auth1\" />\n" + "<authority id=\"1\" user=\"1\" account=\"account1\" type=\"type1\" authority=\"auth1\" />\n" + "</accounts>\n").getBytes();
    MockContentResolver mockResolver = new MockContentResolver();
    final TestContext testContext = new TestContext(mockResolver, getContext());
    File syncDir = getSyncDir();
    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.getMasterSyncAutomatically(0));
    assertEquals(true, engine.getMasterSyncAutomatically(1));
    assertEquals(true, engine.getMasterSyncAutomatically(2));
}
Also used : AtomicFile(com.android.internal.os.AtomicFile) FileOutputStream(java.io.FileOutputStream) MockContentResolver(android.test.mock.MockContentResolver) File(java.io.File) AtomicFile(com.android.internal.os.AtomicFile) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 54 with MockContentResolver

use of android.test.mock.MockContentResolver in project android_frameworks_base by DirtyUnicorns.

the class FakeSettingsProviderTest method setUp.

@Override
public void setUp() throws Exception {
    mCr = new MockContentResolver();
    mCr.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
}
Also used : MockContentResolver(android.test.mock.MockContentResolver)

Example 55 with MockContentResolver

use of android.test.mock.MockContentResolver in project android_frameworks_base by DirtyUnicorns.

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()));
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle) ComponentName(android.content.ComponentName) MockContentResolver(android.test.mock.MockContentResolver)

Aggregations

MockContentResolver (android.test.mock.MockContentResolver)79 Account (android.accounts.Account)22 MockContext (android.test.mock.MockContext)17 AtomicFile (com.android.internal.os.AtomicFile)16 File (java.io.File)16 FileOutputStream (java.io.FileOutputStream)16 Context (android.content.Context)13 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 ContextWrapper (android.content.ContextWrapper)10 Bundle (android.os.Bundle)8 Before (org.junit.Before)8 ContentResolver (android.content.ContentResolver)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 ComponentName (android.content.ComponentName)4 MockContentProvider (com.android.contacts.common.test.mocks.MockContentProvider)4 PeriodicSync (android.content.PeriodicSync)3 ProviderInfo (android.content.pm.ProviderInfo)3 IsolatedContext (android.test.IsolatedContext)3 Uri (android.net.Uri)2 RemoteException (android.os.RemoteException)2