Commit 9c308334 authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Android][Test] Refactor AccountPickerBottomSheetTest with onVisibleView

This CL refactors AccountPickerBottomSheetTest with onVisibleView.

Bug: 1121536
Change-Id: If6385712bf6d6271d77d6ced98e4d2b3cba43f1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485060Reviewed-by: default avatarTanmoy Mollik <triploblastic@chromium.org>
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819294}
parent f88c5a4b
...@@ -29,8 +29,10 @@ import static org.mockito.MockitoAnnotations.initMocks; ...@@ -29,8 +29,10 @@ import static org.mockito.MockitoAnnotations.initMocks;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.view.View; import android.view.View;
import androidx.test.espresso.ViewInteraction;
import androidx.test.filters.MediumTest; import androidx.test.filters.MediumTest;
import org.hamcrest.Matcher;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
...@@ -155,12 +157,8 @@ public class AccountPickerBottomSheetTest { ...@@ -155,12 +157,8 @@ public class AccountPickerBottomSheetTest {
@MediumTest @MediumTest
public void testExpandedSheet() { public void testExpandedSheet() {
buildAndShowExpandedBottomSheet(); buildAndShowExpandedBottomSheet();
// Since PROFILE_DATA1 exists also in the hidden view of the selected account, onVisibleView(withText(PROFILE_DATA1.getAccountName())).check(matches(isDisplayed()));
// withEffectiveVisibility(VISIBLE) is needed here onVisibleView(withText(PROFILE_DATA1.getFullName())).check(matches(isDisplayed()));
onView(allOf(withText(PROFILE_DATA1.getAccountName()), withEffectiveVisibility(VISIBLE)))
.check(matches(isDisplayed()));
onView(allOf(withText(PROFILE_DATA1.getFullName()), withEffectiveVisibility(VISIBLE)))
.check(matches(isDisplayed()));
onView(withText(PROFILE_DATA2.getAccountName())).check(matches(isDisplayed())); onView(withText(PROFILE_DATA2.getAccountName())).check(matches(isDisplayed()));
onView(withText(R.string.signin_add_account_to_device)).check(matches(isDisplayed())); onView(withText(R.string.signin_add_account_to_device)).check(matches(isDisplayed()));
onView(withText(R.string.signin_incognito_button)).check(matches(isDisplayed())); onView(withText(R.string.signin_incognito_button)).check(matches(isDisplayed()));
...@@ -175,12 +173,8 @@ public class AccountPickerBottomSheetTest { ...@@ -175,12 +173,8 @@ public class AccountPickerBottomSheetTest {
public void testExpandedSheetWithIncognitoModeDisabled() { public void testExpandedSheetWithIncognitoModeDisabled() {
IncognitoUtils.setEnabledForTesting(false); IncognitoUtils.setEnabledForTesting(false);
buildAndShowExpandedBottomSheet(); buildAndShowExpandedBottomSheet();
// Since PROFILE_DATA1 exists also in the hidden view of the selected account, onVisibleView(withText(PROFILE_DATA1.getAccountName())).check(matches(isDisplayed()));
// withEffectiveVisibility(VISIBLE) is needed here onVisibleView(withText(PROFILE_DATA1.getFullName())).check(matches(isDisplayed()));
onView(allOf(withText(PROFILE_DATA1.getAccountName()), withEffectiveVisibility(VISIBLE)))
.check(matches(isDisplayed()));
onView(allOf(withText(PROFILE_DATA1.getFullName()), withEffectiveVisibility(VISIBLE)))
.check(matches(isDisplayed()));
onView(withText(PROFILE_DATA2.getAccountName())).check(matches(isDisplayed())); onView(withText(PROFILE_DATA2.getAccountName())).check(matches(isDisplayed()));
onView(withText(R.string.signin_add_account_to_device)).check(matches(isDisplayed())); onView(withText(R.string.signin_add_account_to_device)).check(matches(isDisplayed()));
...@@ -257,10 +251,8 @@ public class AccountPickerBottomSheetTest { ...@@ -257,10 +251,8 @@ public class AccountPickerBottomSheetTest {
onView(withText(R.string.signin_account_picker_bottom_sheet_subtitle)) onView(withText(R.string.signin_account_picker_bottom_sheet_subtitle))
.check(matches(isDisplayed())); .check(matches(isDisplayed()));
onView(withId(R.id.account_picker_horizontal_divider)).check(matches(isDisplayed())); onView(withId(R.id.account_picker_horizontal_divider)).check(matches(isDisplayed()));
onView(allOf(withText(PROFILE_DATA1.getAccountName()), withEffectiveVisibility(VISIBLE))) onVisibleView(withText(PROFILE_DATA1.getAccountName())).check(matches(isDisplayed()));
.check(matches(isDisplayed())); onVisibleView(withText(PROFILE_DATA1.getFullName())).check(matches(isDisplayed()));
onView(allOf(withText(PROFILE_DATA1.getFullName()), withEffectiveVisibility(VISIBLE)))
.check(matches(isDisplayed()));
onView(withText(PROFILE_DATA2.getAccountName())).check(matches(isDisplayed())); onView(withText(PROFILE_DATA2.getAccountName())).check(matches(isDisplayed()));
onView(withText(R.string.signin_add_account_to_device)).check(matches(isDisplayed())); onView(withText(R.string.signin_add_account_to_device)).check(matches(isDisplayed()));
...@@ -328,8 +320,8 @@ public class AccountPickerBottomSheetTest { ...@@ -328,8 +320,8 @@ public class AccountPickerBottomSheetTest {
new ProfileDataSource.ProfileData( new ProfileDataSource.ProfileData(
PROFILE_DATA1.getAccountName(), null, newFullName, newGivenName)); PROFILE_DATA1.getAccountName(), null, newFullName, newGivenName));
}); });
onView(allOf(withText(newFullName), withEffectiveVisibility(VISIBLE))) onVisibleView(withText(PROFILE_DATA1.getAccountName())).check(matches(isDisplayed()));
.check(matches(isDisplayed())); onVisibleView(withText(newFullName)).check(matches(isDisplayed()));
// Check that profile data update when the bottom sheet is expanded won't // Check that profile data update when the bottom sheet is expanded won't
// toggle out any hidden part. // toggle out any hidden part.
onView(withId(R.id.account_picker_selected_account)).check(matches(not(isDisplayed()))); onView(withId(R.id.account_picker_selected_account)).check(matches(not(isDisplayed())));
...@@ -531,8 +523,7 @@ public class AccountPickerBottomSheetTest { ...@@ -531,8 +523,7 @@ public class AccountPickerBottomSheetTest {
@MediumTest @MediumTest
public void testSelectTheSameAccountOnExpandedSheet() { public void testSelectTheSameAccountOnExpandedSheet() {
buildAndShowExpandedBottomSheet(); buildAndShowExpandedBottomSheet();
onView(allOf(withText(PROFILE_DATA1.getAccountName()), withEffectiveVisibility(VISIBLE))) onVisibleView(withText(PROFILE_DATA1.getAccountName())).perform(click());
.perform(click());
checkCollapsedAccountList(PROFILE_DATA1); checkCollapsedAccountList(PROFILE_DATA1);
} }
...@@ -624,15 +615,11 @@ public class AccountPickerBottomSheetTest { ...@@ -624,15 +615,11 @@ public class AccountPickerBottomSheetTest {
} }
private void checkZeroAccountBottomSheet() { private void checkZeroAccountBottomSheet() {
onView(allOf(withText(PROFILE_DATA1.getAccountName()), withEffectiveVisibility(VISIBLE))) onVisibleView(withText(PROFILE_DATA1.getAccountName())).check(doesNotExist());
.check(doesNotExist()); onVisibleView(withText(PROFILE_DATA2.getAccountName())).check(doesNotExist());
onView(allOf(withText(PROFILE_DATA2.getAccountName()), withEffectiveVisibility(VISIBLE)))
.check(doesNotExist());
onView(withId(R.id.account_picker_account_list)).check(matches(not(isDisplayed()))); onView(withId(R.id.account_picker_account_list)).check(matches(not(isDisplayed())));
onView(withId(R.id.account_picker_selected_account)).check(matches(not(isDisplayed()))); onView(withId(R.id.account_picker_selected_account)).check(matches(not(isDisplayed())));
onView(allOf(withText(R.string.signin_add_account_to_device), onVisibleView(withText(R.string.signin_add_account_to_device)).perform(click());
withEffectiveVisibility(VISIBLE)))
.perform(click());
verify(mAccountPickerDelegateMock).addAccount(notNull()); verify(mAccountPickerDelegateMock).addAccount(notNull());
} }
...@@ -643,14 +630,11 @@ public class AccountPickerBottomSheetTest { ...@@ -643,14 +630,11 @@ public class AccountPickerBottomSheetTest {
onView(withText(R.string.signin_account_picker_bottom_sheet_subtitle)) onView(withText(R.string.signin_account_picker_bottom_sheet_subtitle))
.check(matches(isDisplayed())); .check(matches(isDisplayed()));
onView(withId(R.id.account_picker_horizontal_divider)).check(matches(isDisplayed())); onView(withId(R.id.account_picker_horizontal_divider)).check(matches(isDisplayed()));
onView(allOf(withText(profileData.getAccountName()), withEffectiveVisibility(VISIBLE))) onVisibleView(withText(profileData.getAccountName())).check(matches(isDisplayed()));
.check(matches(isDisplayed()));
if (profileData.getFullName() != null) { if (profileData.getFullName() != null) {
onView(allOf(withText(profileData.getFullName()), withEffectiveVisibility(VISIBLE))) onVisibleView(withText(profileData.getFullName())).check(matches(isDisplayed()));
.check(matches(isDisplayed()));
} }
onView(allOf(withId(R.id.account_selection_mark), withEffectiveVisibility(VISIBLE))) onVisibleView(withId(R.id.account_selection_mark)).check(matches(isDisplayed()));
.check(matches(isDisplayed()));
String continueAsText = String continueAsText =
sActivityTestRule.getActivity().getString(R.string.signin_promo_continue_as, sActivityTestRule.getActivity().getString(R.string.signin_promo_continue_as,
profileData.getGivenName() != null ? profileData.getGivenName() profileData.getGivenName() != null ? profileData.getGivenName()
...@@ -680,4 +664,11 @@ public class AccountPickerBottomSheetTest { ...@@ -680,4 +664,11 @@ public class AccountPickerBottomSheetTest {
.getRootUiCoordinatorForTesting() .getRootUiCoordinatorForTesting()
.getBottomSheetController(); .getBottomSheetController();
} }
private static ViewInteraction onVisibleView(Matcher<View> matcher) {
// Some view elements like PROFILE_DATA1 exist in both visible view and hidden view,
// withEffectiveVisibility(VISIBLE) is needed here to get only the visible view of the
// matcher.
return onView(allOf(matcher, withEffectiveVisibility(VISIBLE)));
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment