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

View File

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

View File

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

View File

@ -151,12 +151,13 @@ see http://help.transifex.net/features/client/index.html#user-client
## Coding Style
### Code
* Indentation: 4 spaces, no tabs
* Maximum line width for code and comments: 100
* Opening braces don't go on their own line
* Indentation: 4 spaces, no tabs.
* Maximum line width for code and comments: 100.
* Opening braces don't go on their own line.
* Field names: Non-public, non-static fields start with m.
* 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.*;``
* 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