Commit 8c8798a4 authored by Matt Jones's avatar Matt Jones Committed by Commit Bot

Improve BottomSheetObserver tests

This patch ensures the open and close events are only called a single
time for the tests in BottomSheetObserver.

Change-Id: I98b1dce25be5aa7e55cdcbead90518954b8747d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1857543
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705587}
parent 4cb02fe3
......@@ -91,6 +91,9 @@ public class BottomSheetObserverTest {
*/
private void runCloseEventTest(boolean animationEnabled, boolean peekStateEnabled)
throws TimeoutException {
CallbackHelper hiddenHelper = mObserver.mHiddenCallbackHelper;
int initialHideEvents = hiddenHelper.getCallCount();
mBottomSheetTestRule.setSheetState(SheetState.FULL, false);
mSheetContent.setPeekHeight(peekStateEnabled ? HeightMode.DEFAULT : HeightMode.DISABLED);
......@@ -100,11 +103,17 @@ public class BottomSheetObserverTest {
int initialOpenedCount = mObserver.mOpenedCallbackHelper.getCallCount();
int closedCallbackCount = closedCallbackHelper.getCallCount();
mBottomSheetTestRule.setSheetState(
peekStateEnabled ? SheetState.PEEK : SheetState.HIDDEN, animationEnabled);
int targetState = peekStateEnabled ? SheetState.PEEK : SheetState.HIDDEN;
mBottomSheetTestRule.setSheetState(targetState, animationEnabled);
closedCallbackHelper.waitForCallback(closedCallbackCount, 1);
if (targetState == SheetState.HIDDEN) hiddenHelper.waitForCallback(initialHideEvents, 1);
assertEquals(initialOpenedCount, mObserver.mOpenedCallbackHelper.getCallCount());
assertEquals("Close event should have only been called once.",
closedCallbackCount + 1, closedCallbackHelper.getCallCount());
}
/** Test that the onSheetOpened event is triggered if the sheet is opened without animation. */
......@@ -150,6 +159,8 @@ public class BottomSheetObserverTest {
throws TimeoutException {
mSheetContent.setPeekHeight(peekStateEnabled ? HeightMode.DEFAULT : HeightMode.DISABLED);
CallbackHelper fullCallbackHelper = mObserver.mFullCallbackHelper;
int initialFullCount = fullCallbackHelper.getCallCount();
CallbackHelper openedCallbackHelper = mObserver.mOpenedCallbackHelper;
int openedCallbackCount = openedCallbackHelper.getCallCount();
CallbackHelper closedCallbackHelper = mObserver.mClosedCallbackHelper;
......@@ -166,7 +177,12 @@ public class BottomSheetObserverTest {
}
mBottomSheetTestRule.setSheetState(SheetState.FULL, animationEnabled);
openedCallbackHelper.waitForCallback(openedCallbackCount, 1);
fullCallbackHelper.waitForCallback(initialFullCount, 1);
assertEquals("Open event should have only been called once.",
openedCallbackCount + 1, openedCallbackHelper.getCallCount());
assertEquals(initialClosedCount, closedCallbackHelper.getCallCount());
}
......
......@@ -40,6 +40,12 @@ public class BottomSheetTestRule extends ChromeTabbedActivityTestRule {
/** A {@link CallbackHelper} that can wait for the onSheetContentChanged event. */
public final CallbackHelper mContentChangedCallbackHelper = new CallbackHelper();
/** A {@link CallbackHelper} that can wait for the sheet to be in its full state. */
public final CallbackHelper mFullCallbackHelper = new CallbackHelper();
/** A {@link CallbackHelper} that can wait for the sheet to be hidden. */
public final CallbackHelper mHiddenCallbackHelper = new CallbackHelper();
/** The last value that the onOffsetChanged event sent. */
private float mLastOffsetChangedValue;
......@@ -64,6 +70,15 @@ public class BottomSheetTestRule extends ChromeTabbedActivityTestRule {
mContentChangedCallbackHelper.notifyCalled();
}
@Override
public void onSheetStateChanged(int newState) {
if (newState == BottomSheet.SheetState.HIDDEN) {
mHiddenCallbackHelper.notifyCalled();
} else if (newState == BottomSheet.SheetState.FULL) {
mFullCallbackHelper.notifyCalled();
}
}
/** @return The last value passed in to {@link #onSheetOffsetChanged(float)}. */
public float getLastOffsetChangedValue() {
return mLastOffsetChangedValue;
......
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