Merge branch 'master' into v/multi-decrypt

This commit is contained in:
Vincent Breitmoser 2015-06-18 13:19:44 +02:00
commit 0cfbe4ad06
4 changed files with 45 additions and 27 deletions

View File

@ -17,17 +17,18 @@
package org.sufficientlysecure.keychain; package org.sufficientlysecure.keychain;
import android.support.test.InstrumentationRegistry;
import android.content.Intent;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest;
import android.text.method.HideReturnsTransformationMethod; import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod; import android.text.method.PasswordTransformationMethod;
import org.junit.Before; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.sufficientlysecure.keychain.ui.CreateKeyActivity; import org.sufficientlysecure.keychain.ui.MainActivity;
import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.action.ViewActions.click;
@ -47,25 +48,28 @@ import static org.sufficientlysecure.keychain.matcher.EditTextMatchers.withTrans
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@LargeTest @LargeTest
public class CreateKeyActivityTest extends ActivityInstrumentationTestCase2<CreateKeyActivity> { public class CreateKeyActivityTest {
public static final String SAMPLE_NAME = "Sample Name"; public static final String SAMPLE_NAME = "Sample Name";
public static final String SAMPLE_EMAIL = "sample_email@gmail.com"; public static final String SAMPLE_EMAIL = "sample_email@gmail.com";
public static final String SAMPLE_ADDITIONAL_EMAIL = "sample_additional_email@gmail.com"; public static final String SAMPLE_ADDITIONAL_EMAIL = "sample_additional_email@gmail.com";
public static final String SAMPLE_PASSWORD = "sample_password"; public static final String SAMPLE_PASSWORD = "sample_password";
public CreateKeyActivityTest() { @Rule
super(CreateKeyActivity.class); public final ActivityTestRule<MainActivity> mActivity
} = new ActivityTestRule<MainActivity>(MainActivity.class) {
@Override
@Before protected Intent getActivityIntent() {
public void setUp() throws Exception { Intent intent = super.getActivityIntent();
super.setUp(); intent.putExtra(MainActivity.EXTRA_SKIP_FIRST_TIME, true);
injectInstrumentation(InstrumentationRegistry.getInstrumentation()); return intent;
getActivity(); }
} };
public void testCreateMyKey() { public void testCreateMyKey() {
mActivity.getActivity();
// Clicks create my key // Clicks create my key
onView(withId(R.id.create_key_create_key_button)) onView(withId(R.id.create_key_create_key_button))
.perform(click()); .perform(click());

View File

@ -22,6 +22,7 @@ import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.support.annotation.NonNull;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
@ -101,9 +102,9 @@ public abstract class OperationResult implements Parcelable {
} }
public OperationLog getLog() { public OperationLog getLog() {
// If there is only a single entry, and it's a compound one, return that log SubLogEntryParcel singleSubLog = mLog.getSubResultIfSingle();
if (mLog.isSingleCompound()) { if (singleSubLog != null) {
return ((SubLogEntryParcel) mLog.getFirst()).getSubResult().getLog(); return singleSubLog.getSubResult().getLog();
} }
// Otherwse, return our regular log // Otherwse, return our regular log
return mLog; return mLog;
@ -169,9 +170,9 @@ public abstract class OperationResult implements Parcelable {
public static class SubLogEntryParcel extends LogEntryParcel { public static class SubLogEntryParcel extends LogEntryParcel {
OperationResult mSubResult; @NonNull OperationResult mSubResult;
public SubLogEntryParcel(OperationResult subResult, LogType type, int indent, Object... parameters) { public SubLogEntryParcel(@NonNull OperationResult subResult, LogType type, int indent, Object... parameters) {
super(type, indent, parameters); super(type, indent, parameters);
mSubResult = subResult; mSubResult = subResult;
@ -209,6 +210,10 @@ public abstract class OperationResult implements Parcelable {
String logText; String logText;
LogEntryParcel entryParcel = mLog.getLast(); LogEntryParcel entryParcel = mLog.getLast();
if (entryParcel == null) {
Log.e(Constants.TAG, "Tried to show empty log!");
return Notify.create(activity, R.string.error_empty_log, Style.ERROR);
}
// special case: first parameter may be a quantity // special case: first parameter may be a quantity
if (entryParcel.mParameters != null && entryParcel.mParameters.length > 0 if (entryParcel.mParameters != null && entryParcel.mParameters.length > 0
&& entryParcel.mParameters[0] instanceof Integer) { && entryParcel.mParameters[0] instanceof Integer) {
@ -269,7 +274,7 @@ public abstract class OperationResult implements Parcelable {
* mark. * mark.
* *
*/ */
public static enum LogType { public enum LogType {
MSG_INTERNAL_ERROR (LogLevel.ERROR, R.string.msg_internal_error), MSG_INTERNAL_ERROR (LogLevel.ERROR, R.string.msg_internal_error),
MSG_OPERATION_CANCELLED (LogLevel.CANCELLED, R.string.msg_cancelled), MSG_OPERATION_CANCELLED (LogLevel.CANCELLED, R.string.msg_cancelled),
@ -765,7 +770,7 @@ public abstract class OperationResult implements Parcelable {
} }
/** Enumeration of possible log levels. */ /** Enumeration of possible log levels. */
public static enum LogLevel { public enum LogLevel {
DEBUG, DEBUG,
INFO, INFO,
WARN, WARN,
@ -805,8 +810,15 @@ public abstract class OperationResult implements Parcelable {
mParcels.add(new SubLogEntryParcel(subResult, subLog.getFirst().mType, indent, subLog.getFirst().mParameters)); mParcels.add(new SubLogEntryParcel(subResult, subLog.getFirst().mType, indent, subLog.getFirst().mParameters));
} }
boolean isSingleCompound() { public SubLogEntryParcel getSubResultIfSingle() {
return mParcels.size() == 1 && getFirst() instanceof SubLogEntryParcel; if (mParcels.size() != 1) {
return null;
}
LogEntryParcel first = getFirst();
if (first instanceof SubLogEntryParcel) {
return (SubLogEntryParcel) first;
}
return null;
} }
public void clear() { public void clear() {

View File

@ -1332,5 +1332,6 @@
<string name="snack_compression_on">"Compression <b>enabled</b>."</string> <string name="snack_compression_on">"Compression <b>enabled</b>."</string>
<string name="snack_compression_off">"Compression <b>disabled</b>."</string> <string name="snack_compression_off">"Compression <b>disabled</b>."</string>
<string name="error_loading_keys">Error loading keys!</string> <string name="error_loading_keys">Error loading keys!</string>
<string name="error_empty_log">(error, empty log)</string>
</resources> </resources>

View File

@ -151,12 +151,13 @@ see http://help.transifex.net/features/client/index.html#user-client
## Coding Style ## Coding Style
### Code ### Code
* Indentation: 4 spaces, no tabs * Indentation: 4 spaces, no tabs.
* Maximum line width for code and comments: 100 * Maximum line width for code and comments: 100.
* Opening braces don't go on their own line * Opening braces don't go on their own line.
* Field names: Non-public, non-static fields start with m. * Field names: Non-public, non-static fields start with m.
* Acronyms are words: Treat acronyms as words in names, yielding !XmlHttpRequest, getUrl(), etc. * Acronyms are words: Treat acronyms as words in names, yielding !XmlHttpRequest, getUrl(), etc.
* Fully Qualify Imports: Do *not* use wildcard-imports such as ``import foo.*;`` * Fully Qualify Imports: Do *not* use wildcard-imports such as ``import foo.*;``
* Android Studio warnings should be fixed, or suppressed if they are incorrect.
The full coding style can be found at http://source.android.com/source/code-style.html The full coding style can be found at http://source.android.com/source/code-style.html