Search in sources :

Example 1 with PackageInstaller

use of android.content.pm.PackageInstaller in project robolectric by robolectric.

the class ShadowPackageInstallerTest method registerSessionCallback_sessionFails.

@Test
public void registerSessionCallback_sessionFails() throws Exception {
    PackageInstaller.SessionCallback mockCallback = mock(PackageInstaller.SessionCallback.class);
    packageInstaller.registerSessionCallback(mockCallback, new Handler());
    int sessionId = packageInstaller.createSession(createSessionParams("packageName"));
    verify(mockCallback).onCreated(sessionId);
    PackageInstaller.Session session = packageInstaller.openSession(sessionId);
    OutputStream outputStream = session.openWrite("filename", 0, 0);
    outputStream.close();
    session.commit(new IntentSender(ReflectionHelpers.createNullProxy(IIntentSender.class)));
    shadowOf(packageInstaller).setSessionFails(sessionId);
    verify(mockCallback).onFinished(sessionId, false);
}
Also used : OutputStream(java.io.OutputStream) PackageInstaller(android.content.pm.PackageInstaller) Handler(android.os.Handler) IIntentSender(android.content.IIntentSender) IntentSender(android.content.IntentSender) Test(org.junit.Test)

Example 2 with PackageInstaller

use of android.content.pm.PackageInstaller in project robolectric by robolectric.

the class ShadowPackageInstallerTest method registerSessionCallback_sessionSucceeds.

@Test
public void registerSessionCallback_sessionSucceeds() throws Exception {
    PackageInstaller.SessionCallback mockCallback = mock(PackageInstaller.SessionCallback.class);
    packageInstaller.registerSessionCallback(mockCallback, new Handler());
    int sessionId = packageInstaller.createSession(createSessionParams("packageName"));
    verify(mockCallback).onCreated(sessionId);
    PackageInstaller.Session session = packageInstaller.openSession(sessionId);
    OutputStream outputStream = session.openWrite("filename", 0, 0);
    outputStream.close();
    session.commit(new IntentSender(ReflectionHelpers.createNullProxy(IIntentSender.class)));
    shadowOf(packageInstaller).setSessionProgress(sessionId, 50.0f);
    verify(mockCallback).onProgressChanged(sessionId, 50.0f);
    shadowOf(packageInstaller).setSessionSucceeds(sessionId);
    verify(mockCallback).onFinished(sessionId, true);
}
Also used : OutputStream(java.io.OutputStream) PackageInstaller(android.content.pm.PackageInstaller) Handler(android.os.Handler) IIntentSender(android.content.IIntentSender) IntentSender(android.content.IntentSender) Test(org.junit.Test)

Aggregations

IIntentSender (android.content.IIntentSender)2 IntentSender (android.content.IntentSender)2 PackageInstaller (android.content.pm.PackageInstaller)2 Handler (android.os.Handler)2 OutputStream (java.io.OutputStream)2 Test (org.junit.Test)2