Loading k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java +2 −1 Original line number Diff line number Diff line Loading @@ -1497,7 +1497,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, message.setUid(mMessageReference.getUid()); } boolean saveRemotely = recipientPresenter.isAllowSavingDraftRemotely(); // TODO more appropriate logic here? not sure boolean saveRemotely = !recipientPresenter.getCurrentCryptoStatus().shouldUsePgpMessageBuilder(); new SaveMessageTask(getApplicationContext(), mAccount, mContacts, mHandler, message, mDraftId, saveRemotely).execute(); if (mFinishAfterDraftSaved) { Loading k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.java +7 −5 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Bundle; import android.support.annotation.VisibleForTesting; import android.util.Log; import android.view.Menu; Loading Loading @@ -384,11 +385,6 @@ public class RecipientPresenter implements PermissionPingCallback { } } public boolean isAllowSavingDraftRemotely() { ComposeCryptoStatus cryptoStatus = getCurrentCryptoStatus(); return cryptoStatus.isEncryptionEnabled() || cryptoStatus.isSigningEnabled(); } @SuppressWarnings("UnusedParameters") public void onToTokenAdded(Recipient recipient) { updateCryptoStatus(); Loading Loading @@ -778,6 +774,12 @@ public class RecipientPresenter implements PermissionPingCallback { } } @VisibleForTesting void setOpenPgpServiceConnection(OpenPgpServiceConnection openPgpServiceConnection, String cryptoProvider) { this.openPgpServiceConnection = openPgpServiceConnection; this.cryptoProvider = cryptoProvider; } public enum CryptoProviderState { UNCONFIGURED, UNINITIALIZED, Loading k9mail/src/test/java/com/fsck/k9/activity/compose/RecipientPresenterTest.java +126 −7 Original line number Diff line number Diff line Loading @@ -6,8 +6,13 @@ import java.util.List; import android.app.LoaderManager; import android.content.Context; import android.content.Intent; import android.os.ParcelFileDescriptor; import com.fsck.k9.Account; import com.fsck.k9.activity.compose.RecipientMvpView.CryptoSpecialModeDisplayType; import com.fsck.k9.activity.compose.RecipientMvpView.CryptoStatusDisplayType; import com.fsck.k9.activity.compose.RecipientPresenter.CryptoMode; import com.fsck.k9.helper.ReplyToParser; import com.fsck.k9.helper.ReplyToParser.ReplyToAddresses; import com.fsck.k9.mail.Address; Loading @@ -18,10 +23,19 @@ import com.fsck.k9.view.RecipientSelectView.Recipient; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.openintents.openpgp.IOpenPgpService2; import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpServiceConnection; import org.openintents.openpgp.util.ShadowOpenPgpAsyncTask; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowApplication; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; Loading @@ -30,19 +44,20 @@ import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) @Config(manifest = "src/main/AndroidManifest.xml", sdk = 21) @Config(manifest = "src/main/AndroidManifest.xml", sdk = 21, shadows = {ShadowOpenPgpAsyncTask.class}) public class RecipientPresenterTest { public static final ReplyToAddresses TO_ADDRESSES = new ReplyToAddresses(Address.parse("to@example.org")); public static final List<Address> ALL_TO_ADDRESSES = Arrays.asList(Address.parse("allTo@example.org")); public static final List<Address> ALL_CC_ADDRESSES = Arrays.asList(Address.parse("allCc@example.org")); private static final ReplyToAddresses TO_ADDRESSES = new ReplyToAddresses(Address.parse("to@example.org")); private static final List<Address> ALL_TO_ADDRESSES = Arrays.asList(Address.parse("allTo@example.org")); private static final List<Address> ALL_CC_ADDRESSES = Arrays.asList(Address.parse("allCc@example.org")); private static final String CRYPTO_PROVIDER = "crypto_provider"; private static final long CRYPTO_KEY_ID = 123L; RecipientPresenter recipientPresenter; private RecipientPresenter recipientPresenter; private ReplyToParser replyToParser; private ComposePgpInlineDecider composePgpInlineDecider; private Account account; private RecipientMvpView recipientMvpView; private LoaderManager loaderManager; @Before Loading @@ -53,7 +68,7 @@ public class RecipientPresenterTest { account = mock(Account.class); composePgpInlineDecider = mock(ComposePgpInlineDecider.class); replyToParser = mock(ReplyToParser.class); loaderManager = mock(LoaderManager.class); LoaderManager loaderManager = mock(LoaderManager.class); recipientPresenter = new RecipientPresenter( context, loaderManager, recipientMvpView, account, composePgpInlineDecider, replyToParser); Loading Loading @@ -92,4 +107,108 @@ public class RecipientPresenterTest { verify(composePgpInlineDecider).shouldReplyInline(message); } @Test public void getCurrentCryptoStatus_withoutCryptoProvider() throws Exception { ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus(); assertEquals(CryptoStatusDisplayType.UNCONFIGURED, status.getCryptoStatusDisplayType()); assertEquals(CryptoSpecialModeDisplayType.NONE, status.getCryptoSpecialModeDisplayType()); assertNull(status.getAttachErrorStateOrNull()); assertFalse(status.isProviderStateOk()); assertFalse(status.shouldUsePgpMessageBuilder()); } @Test public void getCurrentCryptoStatus_withCryptoProvider() throws Exception { setupCryptoProvider(); ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus(); assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType()); assertTrue(status.isProviderStateOk()); assertTrue(status.shouldUsePgpMessageBuilder()); } @Test public void getCurrentCryptoStatus_withOpportunistic() throws Exception { setupCryptoProvider(); recipientPresenter.onCryptoModeChanged(CryptoMode.OPPORTUNISTIC); ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus(); assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType()); assertTrue(status.isProviderStateOk()); assertTrue(status.shouldUsePgpMessageBuilder()); } @Test public void getCurrentCryptoStatus_withModeDisabled() throws Exception { setupCryptoProvider(); recipientPresenter.onCryptoModeChanged(CryptoMode.DISABLE); ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus(); assertEquals(CryptoStatusDisplayType.DISABLED, status.getCryptoStatusDisplayType()); assertTrue(status.isProviderStateOk()); assertFalse(status.shouldUsePgpMessageBuilder()); } @Test public void getCurrentCryptoStatus_withModePrivate() throws Exception { setupCryptoProvider(); recipientPresenter.onCryptoModeChanged(CryptoMode.PRIVATE); ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus(); assertEquals(CryptoStatusDisplayType.PRIVATE_EMPTY, status.getCryptoStatusDisplayType()); assertTrue(status.isProviderStateOk()); assertTrue(status.shouldUsePgpMessageBuilder()); } @Test public void getCurrentCryptoStatus_withModeSignOnly() throws Exception { setupCryptoProvider(); recipientPresenter.onMenuSetSignOnly(true); ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus(); assertEquals(CryptoStatusDisplayType.SIGN_ONLY, status.getCryptoStatusDisplayType()); assertTrue(status.isProviderStateOk()); assertTrue(status.isSigningEnabled()); assertTrue(status.isSignOnly()); } @Test public void getCurrentCryptoStatus_withModeInline() throws Exception { setupCryptoProvider(); recipientPresenter.onMenuSetPgpInline(true); ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus(); assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType()); assertTrue(status.isProviderStateOk()); assertTrue(status.isPgpInlineModeEnabled()); } private void setupCryptoProvider() throws android.os.RemoteException { Account account = mock(Account.class); OpenPgpServiceConnection openPgpServiceConnection = mock(OpenPgpServiceConnection.class); IOpenPgpService2 openPgpService2 = mock(IOpenPgpService2.class); Intent permissionPingIntent = new Intent(); permissionPingIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); when(account.getOpenPgpProvider()).thenReturn(CRYPTO_PROVIDER); when(account.getCryptoKey()).thenReturn(CRYPTO_KEY_ID); when(openPgpServiceConnection.isBound()).thenReturn(true); when(openPgpServiceConnection.getService()).thenReturn(openPgpService2); when(openPgpService2.execute(any(Intent.class), any(ParcelFileDescriptor.class), any(Integer.class))) .thenReturn(permissionPingIntent); Robolectric.getBackgroundThreadScheduler().pause(); recipientPresenter.setOpenPgpServiceConnection(openPgpServiceConnection, CRYPTO_PROVIDER); recipientPresenter.onSwitchAccount(account); recipientPresenter.updateCryptoStatus(); Robolectric.getBackgroundThreadScheduler().runOneTask(); } } k9mail/src/test/java/org/openintents/openpgp/util/ShadowOpenPgpAsyncTask.java 0 → 100644 +25 −0 Original line number Diff line number Diff line package org.openintents.openpgp.util; import java.util.concurrent.Executor; import android.content.Intent; import android.os.AsyncTask; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; import org.robolectric.annotation.RealObject; import org.robolectric.shadows.ShadowAsyncTask; @Implements(OpenPgpApi.OpenPgpAsyncTask.class) public class ShadowOpenPgpAsyncTask extends ShadowAsyncTask<Void, Integer, Intent> { @RealObject private OpenPgpApi.OpenPgpAsyncTask realAsyncTask; @Implementation public AsyncTask<Void, Integer, Intent> executeOnExecutor(Executor executor, Void... params) { return super.execute(params); } } No newline at end of file plugins/openpgp-api-lib/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java +1 −1 Original line number Diff line number Diff line Loading @@ -328,7 +328,7 @@ public class OpenPgpApi { } } private class OpenPgpAsyncTask extends AsyncTask<Void, Integer, Intent> { class OpenPgpAsyncTask extends AsyncTask<Void, Integer, Intent> { Intent data; InputStream is; OutputStream os; Loading Loading
k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java +2 −1 Original line number Diff line number Diff line Loading @@ -1497,7 +1497,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, message.setUid(mMessageReference.getUid()); } boolean saveRemotely = recipientPresenter.isAllowSavingDraftRemotely(); // TODO more appropriate logic here? not sure boolean saveRemotely = !recipientPresenter.getCurrentCryptoStatus().shouldUsePgpMessageBuilder(); new SaveMessageTask(getApplicationContext(), mAccount, mContacts, mHandler, message, mDraftId, saveRemotely).execute(); if (mFinishAfterDraftSaved) { Loading
k9mail/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.java +7 −5 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Bundle; import android.support.annotation.VisibleForTesting; import android.util.Log; import android.view.Menu; Loading Loading @@ -384,11 +385,6 @@ public class RecipientPresenter implements PermissionPingCallback { } } public boolean isAllowSavingDraftRemotely() { ComposeCryptoStatus cryptoStatus = getCurrentCryptoStatus(); return cryptoStatus.isEncryptionEnabled() || cryptoStatus.isSigningEnabled(); } @SuppressWarnings("UnusedParameters") public void onToTokenAdded(Recipient recipient) { updateCryptoStatus(); Loading Loading @@ -778,6 +774,12 @@ public class RecipientPresenter implements PermissionPingCallback { } } @VisibleForTesting void setOpenPgpServiceConnection(OpenPgpServiceConnection openPgpServiceConnection, String cryptoProvider) { this.openPgpServiceConnection = openPgpServiceConnection; this.cryptoProvider = cryptoProvider; } public enum CryptoProviderState { UNCONFIGURED, UNINITIALIZED, Loading
k9mail/src/test/java/com/fsck/k9/activity/compose/RecipientPresenterTest.java +126 −7 Original line number Diff line number Diff line Loading @@ -6,8 +6,13 @@ import java.util.List; import android.app.LoaderManager; import android.content.Context; import android.content.Intent; import android.os.ParcelFileDescriptor; import com.fsck.k9.Account; import com.fsck.k9.activity.compose.RecipientMvpView.CryptoSpecialModeDisplayType; import com.fsck.k9.activity.compose.RecipientMvpView.CryptoStatusDisplayType; import com.fsck.k9.activity.compose.RecipientPresenter.CryptoMode; import com.fsck.k9.helper.ReplyToParser; import com.fsck.k9.helper.ReplyToParser.ReplyToAddresses; import com.fsck.k9.mail.Address; Loading @@ -18,10 +23,19 @@ import com.fsck.k9.view.RecipientSelectView.Recipient; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.openintents.openpgp.IOpenPgpService2; import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpServiceConnection; import org.openintents.openpgp.util.ShadowOpenPgpAsyncTask; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowApplication; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; Loading @@ -30,19 +44,20 @@ import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) @Config(manifest = "src/main/AndroidManifest.xml", sdk = 21) @Config(manifest = "src/main/AndroidManifest.xml", sdk = 21, shadows = {ShadowOpenPgpAsyncTask.class}) public class RecipientPresenterTest { public static final ReplyToAddresses TO_ADDRESSES = new ReplyToAddresses(Address.parse("to@example.org")); public static final List<Address> ALL_TO_ADDRESSES = Arrays.asList(Address.parse("allTo@example.org")); public static final List<Address> ALL_CC_ADDRESSES = Arrays.asList(Address.parse("allCc@example.org")); private static final ReplyToAddresses TO_ADDRESSES = new ReplyToAddresses(Address.parse("to@example.org")); private static final List<Address> ALL_TO_ADDRESSES = Arrays.asList(Address.parse("allTo@example.org")); private static final List<Address> ALL_CC_ADDRESSES = Arrays.asList(Address.parse("allCc@example.org")); private static final String CRYPTO_PROVIDER = "crypto_provider"; private static final long CRYPTO_KEY_ID = 123L; RecipientPresenter recipientPresenter; private RecipientPresenter recipientPresenter; private ReplyToParser replyToParser; private ComposePgpInlineDecider composePgpInlineDecider; private Account account; private RecipientMvpView recipientMvpView; private LoaderManager loaderManager; @Before Loading @@ -53,7 +68,7 @@ public class RecipientPresenterTest { account = mock(Account.class); composePgpInlineDecider = mock(ComposePgpInlineDecider.class); replyToParser = mock(ReplyToParser.class); loaderManager = mock(LoaderManager.class); LoaderManager loaderManager = mock(LoaderManager.class); recipientPresenter = new RecipientPresenter( context, loaderManager, recipientMvpView, account, composePgpInlineDecider, replyToParser); Loading Loading @@ -92,4 +107,108 @@ public class RecipientPresenterTest { verify(composePgpInlineDecider).shouldReplyInline(message); } @Test public void getCurrentCryptoStatus_withoutCryptoProvider() throws Exception { ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus(); assertEquals(CryptoStatusDisplayType.UNCONFIGURED, status.getCryptoStatusDisplayType()); assertEquals(CryptoSpecialModeDisplayType.NONE, status.getCryptoSpecialModeDisplayType()); assertNull(status.getAttachErrorStateOrNull()); assertFalse(status.isProviderStateOk()); assertFalse(status.shouldUsePgpMessageBuilder()); } @Test public void getCurrentCryptoStatus_withCryptoProvider() throws Exception { setupCryptoProvider(); ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus(); assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType()); assertTrue(status.isProviderStateOk()); assertTrue(status.shouldUsePgpMessageBuilder()); } @Test public void getCurrentCryptoStatus_withOpportunistic() throws Exception { setupCryptoProvider(); recipientPresenter.onCryptoModeChanged(CryptoMode.OPPORTUNISTIC); ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus(); assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType()); assertTrue(status.isProviderStateOk()); assertTrue(status.shouldUsePgpMessageBuilder()); } @Test public void getCurrentCryptoStatus_withModeDisabled() throws Exception { setupCryptoProvider(); recipientPresenter.onCryptoModeChanged(CryptoMode.DISABLE); ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus(); assertEquals(CryptoStatusDisplayType.DISABLED, status.getCryptoStatusDisplayType()); assertTrue(status.isProviderStateOk()); assertFalse(status.shouldUsePgpMessageBuilder()); } @Test public void getCurrentCryptoStatus_withModePrivate() throws Exception { setupCryptoProvider(); recipientPresenter.onCryptoModeChanged(CryptoMode.PRIVATE); ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus(); assertEquals(CryptoStatusDisplayType.PRIVATE_EMPTY, status.getCryptoStatusDisplayType()); assertTrue(status.isProviderStateOk()); assertTrue(status.shouldUsePgpMessageBuilder()); } @Test public void getCurrentCryptoStatus_withModeSignOnly() throws Exception { setupCryptoProvider(); recipientPresenter.onMenuSetSignOnly(true); ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus(); assertEquals(CryptoStatusDisplayType.SIGN_ONLY, status.getCryptoStatusDisplayType()); assertTrue(status.isProviderStateOk()); assertTrue(status.isSigningEnabled()); assertTrue(status.isSignOnly()); } @Test public void getCurrentCryptoStatus_withModeInline() throws Exception { setupCryptoProvider(); recipientPresenter.onMenuSetPgpInline(true); ComposeCryptoStatus status = recipientPresenter.getCurrentCryptoStatus(); assertEquals(CryptoStatusDisplayType.OPPORTUNISTIC_EMPTY, status.getCryptoStatusDisplayType()); assertTrue(status.isProviderStateOk()); assertTrue(status.isPgpInlineModeEnabled()); } private void setupCryptoProvider() throws android.os.RemoteException { Account account = mock(Account.class); OpenPgpServiceConnection openPgpServiceConnection = mock(OpenPgpServiceConnection.class); IOpenPgpService2 openPgpService2 = mock(IOpenPgpService2.class); Intent permissionPingIntent = new Intent(); permissionPingIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); when(account.getOpenPgpProvider()).thenReturn(CRYPTO_PROVIDER); when(account.getCryptoKey()).thenReturn(CRYPTO_KEY_ID); when(openPgpServiceConnection.isBound()).thenReturn(true); when(openPgpServiceConnection.getService()).thenReturn(openPgpService2); when(openPgpService2.execute(any(Intent.class), any(ParcelFileDescriptor.class), any(Integer.class))) .thenReturn(permissionPingIntent); Robolectric.getBackgroundThreadScheduler().pause(); recipientPresenter.setOpenPgpServiceConnection(openPgpServiceConnection, CRYPTO_PROVIDER); recipientPresenter.onSwitchAccount(account); recipientPresenter.updateCryptoStatus(); Robolectric.getBackgroundThreadScheduler().runOneTask(); } }
k9mail/src/test/java/org/openintents/openpgp/util/ShadowOpenPgpAsyncTask.java 0 → 100644 +25 −0 Original line number Diff line number Diff line package org.openintents.openpgp.util; import java.util.concurrent.Executor; import android.content.Intent; import android.os.AsyncTask; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; import org.robolectric.annotation.RealObject; import org.robolectric.shadows.ShadowAsyncTask; @Implements(OpenPgpApi.OpenPgpAsyncTask.class) public class ShadowOpenPgpAsyncTask extends ShadowAsyncTask<Void, Integer, Intent> { @RealObject private OpenPgpApi.OpenPgpAsyncTask realAsyncTask; @Implementation public AsyncTask<Void, Integer, Intent> executeOnExecutor(Executor executor, Void... params) { return super.execute(params); } } No newline at end of file
plugins/openpgp-api-lib/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java +1 −1 Original line number Diff line number Diff line Loading @@ -328,7 +328,7 @@ public class OpenPgpApi { } } private class OpenPgpAsyncTask extends AsyncTask<Void, Integer, Intent> { class OpenPgpAsyncTask extends AsyncTask<Void, Integer, Intent> { Intent data; InputStream is; OutputStream os; Loading