Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions CHANGELOG-upstream.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Unified date display in call bubbles
* Explain at "Settings / Chats / Outgoing Media Quality" how to send original quality
* Add a basic sticker picker
* Leave groups and channels before deletion
* Fix: keep original sent timestamp for resent messages
* Fix: make clicking on broadcast member-added messages work always
* Fix: remove notification when a message is deleted by sender
Expand Down
53 changes: 26 additions & 27 deletions src/androidTest/java/com/b44t/messenger/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.test.espresso.NoMatchingViewException;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.ViewInteraction;
import androidx.test.espresso.util.TreeIterables;
import androidx.test.ext.junit.rules.ActivityScenarioRule;

import org.hamcrest.Matcher;
import org.thoughtcrime.securesms.ConversationListActivity;
import org.thoughtcrime.securesms.R;
Expand Down Expand Up @@ -60,10 +58,12 @@ public static void createOfflineAccount() {
}

@NonNull
public static ActivityScenarioRule<ConversationListActivity> getOfflineActivityRule(boolean useExistingChats) {
public static ActivityScenarioRule<ConversationListActivity> getOfflineActivityRule(
boolean useExistingChats) {
Intent intent =
Intent.makeMainActivity(
new ComponentName(getInstrumentation().getTargetContext(), ConversationListActivity.class));
Intent.makeMainActivity(
new ComponentName(
getInstrumentation().getTargetContext(), ConversationListActivity.class));
if (!useExistingChats) {
createOfflineAccount();
}
Expand All @@ -72,18 +72,22 @@ public static ActivityScenarioRule<ConversationListActivity> getOfflineActivityR
}

@NonNull
public static <T extends Activity> ActivityScenarioRule<T> getOnlineActivityRule(Class<T> activityClass) {
public static <T extends Activity> ActivityScenarioRule<T> getOnlineActivityRule(
Class<T> activityClass) {
Context context = getInstrumentation().getTargetContext();
AccountManager.getInstance().beginAccountCreation(context);
prepare();
return new ActivityScenarioRule<>(new Intent(getInstrumentation().getTargetContext(), activityClass));
return new ActivityScenarioRule<>(
new Intent(getInstrumentation().getTargetContext(), activityClass));
}

private static void prepare() {
Prefs.setBooleanPreference(getInstrumentation().getTargetContext(), Prefs.DOZE_ASKED_DIRECTLY, true);
Prefs.setBooleanPreference(
getInstrumentation().getTargetContext(), Prefs.DOZE_ASKED_DIRECTLY, true);
if (!AccessibilityUtil.areAnimationsDisabled(getInstrumentation().getTargetContext())) {
throw new RuntimeException("To run the tests, disable animations at Developer options' " +
"-> 'Window/Transition/Animator animation scale' -> Set all 3 to 'off'");
throw new RuntimeException(
"To run the tests, disable animations at Developer options' "
+ "-> 'Window/Transition/Animator animation scale' -> Set all 3 to 'off'");
}
}

Expand Down Expand Up @@ -116,26 +120,22 @@ public void perform(UiController uiController, View view) {
}

throw new NoMatchingViewException.Builder()
.withRootView(view)
.withViewMatcher(matcher)
.build();
.withRootView(view)
.withViewMatcher(matcher)
.build();
}
};
}

/**
* Perform action of implicitly waiting for a certain view.
* This differs from EspressoExtensions.searchFor in that,
* upon failure to locate an element, it will fetch a new root view
* in which to traverse searching for our @param match
* Perform action of implicitly waiting for a certain view. This differs from
* EspressoExtensions.searchFor in that, upon failure to locate an element, it will fetch a new
* root view in which to traverse searching for our @param match
*
* @param viewMatcher ViewMatcher used to find our view
*/
public static ViewInteraction waitForView(
Matcher<View> viewMatcher,
int waitMillis,
int waitMillisPerTry
) {
Matcher<View> viewMatcher, int waitMillis, int waitMillisPerTry) {

// Derive the max tries
int maxTries = (int) (waitMillis / waitMillisPerTry);
Expand Down Expand Up @@ -164,12 +164,11 @@ public static ViewInteraction waitForView(
}

/**
* Normally, you would do
* onView(withId(R.id.send_button)).perform(click());
* to send the draft message. However, in order to change the send button to the attach button
* while there is no draft, the send button is made invisible and the attach button is made
* visible instead. This confuses the test framework.<br/><br/>
*
* Normally, you would do onView(withId(R.id.send_button)).perform(click()); to send the draft
* message. However, in order to change the send button to the attach button while there is no
* draft, the send button is made invisible and the attach button is made visible instead. This
* confuses the test framework.<br>
* <br>
* So, this is a workaround for pressing the send button.
*/
public static void pressSend() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
import static androidx.test.espresso.matcher.ViewMatchers.withText;

import android.util.Log;

import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;

import com.b44t.messenger.TestUtils;

import org.junit.After;
import org.junit.Ignore;
import org.junit.Rule;
Expand All @@ -34,18 +31,19 @@ public class EnterChatsBenchmark {
// ==============================================================================================
// Set this to true if you already have at least 10 chats on your existing DeltaChat installation
// and want to traverse through them instead of 10 newly created chats
private final static boolean USE_EXISTING_CHATS = false;
private static final boolean USE_EXISTING_CHATS = false;
// ==============================================================================================
private final static int GO_THROUGH_ALL_CHATS_N_TIMES = 8;
private static final int GO_THROUGH_ALL_CHATS_N_TIMES = 8;

// ==============================================================================================
// PLEASE BACKUP YOUR ACCOUNT BEFORE RUNNING THIS!
// ==============================================================================================

private final static String TAG = EnterChatsBenchmark.class.getSimpleName();
private static final String TAG = EnterChatsBenchmark.class.getSimpleName();

@Rule
public ActivityScenarioRule<ConversationListActivity> activityRule = TestUtils.getOfflineActivityRule(USE_EXISTING_CHATS);
public ActivityScenarioRule<ConversationListActivity> activityRule =
TestUtils.getOfflineActivityRule(USE_EXISTING_CHATS);

@Test
public void createAndEnter10FilledChats() {
Expand All @@ -55,7 +53,9 @@ public void createAndEnter10FilledChats() {
for (int i = 0; i < GO_THROUGH_ALL_CHATS_N_TIMES; i++) {
times[i] = "" + timeGoToNChats(10); // 10 group chats were created
}
Log.i(TAG, "MEASURED RESULTS (Benchmark) - Going thorough all 10 chats: " + String.join(",", times));
Log.i(
TAG,
"MEASURED RESULTS (Benchmark) - Going thorough all 10 chats: " + String.join(",", times));
}

@Test
Expand All @@ -66,13 +66,17 @@ public void createAndEnterEmptyChats() {
for (int i = 0; i < GO_THROUGH_ALL_CHATS_N_TIMES; i++) {
times[i] = "" + timeGoToNChats(1);
}
Log.i(TAG, "MEASURED RESULTS (Benchmark) - Entering and leaving 1 empty chat: " + String.join(",", times));
Log.i(
TAG,
"MEASURED RESULTS (Benchmark) - Entering and leaving 1 empty chat: "
+ String.join(",", times));
}

@Test
public void enterFilledChat() {
if (!USE_EXISTING_CHATS) {
createChatAndGoBack("Group #1", true, "Hello!", "Some links: https://testrun.org", "And a command: /help");
createChatAndGoBack(
"Group #1", true, "Hello!", "Some links: https://testrun.org", "And a command: /help");
}

String[] times = new String[50];
Expand All @@ -82,7 +86,18 @@ public void enterFilledChat() {
long end = System.currentTimeMillis();
long diff = end - start;
pressBack();
Log.i(TAG, "Measured (Benchmark) " + (i+1) + "/" + times.length + ": Entering 1 filled chat took " + diff + "ms " + "(going back took " + (System.currentTimeMillis() - end) + "ms)");
Log.i(
TAG,
"Measured (Benchmark) "
+ (i + 1)
+ "/"
+ times.length
+ ": Entering 1 filled chat took "
+ diff
+ "ms "
+ "(going back took "
+ (System.currentTimeMillis() - end)
+ "ms)");

times[i] = "" + diff;
}
Expand All @@ -91,16 +106,37 @@ public void enterFilledChat() {

private void create10Chats(boolean fillWithMsgs) {
if (!USE_EXISTING_CHATS) {
createChatAndGoBack("Group #1", fillWithMsgs, "Hello!", "Some links: https://testrun.org", "And a command: /help");
createChatAndGoBack("Group #2", fillWithMsgs, "example.org, alice@example.org", "aaaaaaa", "bbbbbb");
createChatAndGoBack("Group #3", fillWithMsgs, repeat("Some string ", 600), repeat("Another string", 200), "Hi!!!");
createChatAndGoBack(
"Group #1",
fillWithMsgs,
"Hello!",
"Some links: https://testrun.org",
"And a command: /help");
createChatAndGoBack(
"Group #2", fillWithMsgs, "example.org, alice@example.org", "aaaaaaa", "bbbbbb");
createChatAndGoBack(
"Group #3",
fillWithMsgs,
repeat("Some string ", 600),
repeat("Another string", 200),
"Hi!!!");
createChatAndGoBack("Group #4", fillWithMsgs, "xyzabc", "Hi!!!!", "Let's meet!");
createChatAndGoBack("Group #5", fillWithMsgs, repeat("aaaa", 40), "bbbbbbbbbbbbbbbbbb", "ccccccccccccccc");
createChatAndGoBack("Group #6", fillWithMsgs, "aaaaaaaaaaa", repeat("Hi! ", 1000), "bbbbbbbbbb");
createChatAndGoBack("Group #7", fillWithMsgs, repeat("abcdefg ", 500), repeat("xxxxx", 100), "yrrrrrrrrrrrrr");
createChatAndGoBack("Group #8", fillWithMsgs, "and a number: 037362/384756", "ccccc", "Nice!");
createChatAndGoBack("Group #9", fillWithMsgs, "ddddddddddddddddd", "zuuuuuuuuuuuuuuuu", "ccccc");
createChatAndGoBack("Group #10", fillWithMsgs, repeat("xxxxxxyyyyy", 100), repeat("String!!", 10), "abcd");
createChatAndGoBack(
"Group #5", fillWithMsgs, repeat("aaaa", 40), "bbbbbbbbbbbbbbbbbb", "ccccccccccccccc");
createChatAndGoBack(
"Group #6", fillWithMsgs, "aaaaaaaaaaa", repeat("Hi! ", 1000), "bbbbbbbbbb");
createChatAndGoBack(
"Group #7",
fillWithMsgs,
repeat("abcdefg ", 500),
repeat("xxxxx", 100),
"yrrrrrrrrrrrrr");
createChatAndGoBack(
"Group #8", fillWithMsgs, "and a number: 037362/384756", "ccccc", "Nice!");
createChatAndGoBack(
"Group #9", fillWithMsgs, "ddddddddddddddddd", "zuuuuuuuuuuuuuuuu", "ccccc");
createChatAndGoBack(
"Group #10", fillWithMsgs, repeat("xxxxxxyyyyy", 100), repeat("String!!", 10), "abcd");
}
}

Expand Down Expand Up @@ -130,10 +166,10 @@ private void createChatAndGoBack(String groupName, boolean fillWithMsgs, String.
onView(withContentDescription(R.string.group_create_button)).perform(click());

if (fillWithMsgs) {
for (String t: texts) {
for (String t : texts) {
sendText(t);
}
for (String t: texts) {
for (String t : texts) {
sendText(t);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;

import com.b44t.messenger.DcContact;
import com.b44t.messenger.DcContext;
import com.b44t.messenger.TestUtils;

import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand All @@ -29,8 +28,6 @@
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.connect.DcHelper;

import java.util.concurrent.TimeUnit;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class ForwardingTest {
Expand All @@ -43,18 +40,22 @@ public static void beforeClass() {
}

@Rule
public final ActivityScenarioRule<ConversationListActivity> activityRule = TestUtils.getOfflineActivityRule(false);
public final ActivityScenarioRule<ConversationListActivity> activityRule =
TestUtils.getOfflineActivityRule(false);

@Before
public void createChats() {
DcContext dcContext = DcHelper.getContext(getInstrumentation().getTargetContext());
dcContext.createChatByContactId(DcContact.DC_CONTACT_ID_SELF);
// Disable bcc_self so that DC doesn't try to send messages to the server.
// If we didn't do this, messages would stay in DC_STATE_OUT_PENDING forever.
// The thing is, DC_STATE_OUT_PENDING show a rotating circle animation, and Espresso doesn't work
// The thing is, DC_STATE_OUT_PENDING show a rotating circle animation, and Espresso doesn't
// work
// with animations, and the tests would hang and never finish.
dcContext.setConfig("bcc_self", "0");
activityRule.getScenario().onActivity(a -> createdGroupId = DcHelper.getContext(a).createGroupChat( "group"));
activityRule
.getScenario()
.onActivity(a -> createdGroupId = DcHelper.getContext(a).createGroupChat("group"));
}

@After
Expand All @@ -68,7 +69,8 @@ public void testSimpleForwarding() {
// The group is at position 0, self chat is at position 1, device talk is at position 2
onView(withId(R.id.list)).perform(RecyclerViewActions.actionOnItemAtPosition(2, click()));
onView(withId(R.id.title)).check(matches(withText(R.string.device_talk)));
onView(withId(android.R.id.list)).perform(RecyclerViewActions.actionOnItemAtPosition(0, longClick()));
onView(withId(android.R.id.list))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, longClick()));
onView(withId(R.id.menu_context_forward)).perform(click());
// Send it to self chat (which is sorted to the top because we're forwarding)
onView(withId(R.id.list)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
Expand All @@ -77,18 +79,21 @@ public void testSimpleForwarding() {

pressBack();

onView(withId(R.id.toolbar_title)).check(matches(withText(R.string.connectivity_not_connected)));
onView(withId(R.id.toolbar_title))
.check(matches(withText(R.string.connectivity_not_connected)));
// Self chat moved up because we sent a message there
onView(withId(R.id.list)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
onView(withId(R.id.title)).check(matches(withText(R.string.saved_messages)));
onView(withId(android.R.id.list)).perform(RecyclerViewActions.actionOnItemAtPosition(0, longClick()));
onView(withId(android.R.id.list))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, longClick()));
onView(withId(R.id.menu_context_forward)).perform(click());
// Send it to the group
onView(withId(R.id.list)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click()));
onView(withText(android.R.string.ok)).perform(click());
onView(withId(R.id.title)).check(matches(withText("group")));

pressBack();
onView(withId(R.id.toolbar_title)).check(matches(withText(R.string.connectivity_not_connected)));
onView(withId(R.id.toolbar_title))
.check(matches(withText(R.string.connectivity_not_connected)));
}
}
Loading
Loading