Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a74aa47b authored by Peter Kalauskas's avatar Peter Kalauskas Committed by Android (Google) Code Review
Browse files

Merge "Add tests for shouldAnimate and onDoneButtonClicked" into sc-dev

parents 07121903 7daee103
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.TextView;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.Dependency;
import com.android.systemui.Dependency;
@@ -57,7 +58,8 @@ public class QSDetail extends LinearLayout {
    private ViewGroup mDetailContent;
    private ViewGroup mDetailContent;
    protected TextView mDetailSettingsButton;
    protected TextView mDetailSettingsButton;
    protected TextView mDetailDoneButton;
    protected TextView mDetailDoneButton;
    private QSDetailClipper mClipper;
    @VisibleForTesting
    QSDetailClipper mClipper;
    private DetailAdapter mDetailAdapter;
    private DetailAdapter mDetailAdapter;
    private QSPanelController mQsPanelController;
    private QSPanelController mQsPanelController;


+59 −0
Original line number Original line Diff line number Diff line
@@ -20,7 +20,9 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;


@@ -75,6 +77,7 @@ public class QSDetailTest extends SysuiTestCase {
        mQsPanelController = mock(QSPanelController.class);
        mQsPanelController = mock(QSPanelController.class);
        mQuickHeader = mock(QuickStatusBarHeader.class);
        mQuickHeader = mock(QuickStatusBarHeader.class);
        mQsDetail.setQsPanel(mQsPanelController, mQuickHeader, mock(QSFooter.class));
        mQsDetail.setQsPanel(mQsPanelController, mQuickHeader, mock(QSFooter.class));
        mQsDetail.mClipper = mock(QSDetailClipper.class);


        mMockDetailAdapter = mock(DetailAdapter.class);
        mMockDetailAdapter = mock(DetailAdapter.class);
        when(mMockDetailAdapter.createDetailView(any(), any(), any()))
        when(mMockDetailAdapter.createDetailView(any(), any(), any()))
@@ -114,6 +117,62 @@ public class QSDetailTest extends SysuiTestCase {
        assertEquals(QSUserSwitcherEvent.QS_USER_DETAIL_CLOSE.getId(), mUiEventLogger.eventId(0));
        assertEquals(QSUserSwitcherEvent.QS_USER_DETAIL_CLOSE.getId(), mUiEventLogger.eventId(0));
    }
    }


    @Test
    public void testShowDetail_ShouldAnimate() {
        mTestableLooper.processAllMessages();

        when(mMockDetailAdapter.shouldAnimate()).thenReturn(true);
        mQsDetail.setFullyExpanded(true);

        mQsDetail.handleShowingDetail(mMockDetailAdapter, 0, 0, false);
        verify(mQsDetail.mClipper).updateCircularClip(eq(true) /* animate */, anyInt(), anyInt(),
                eq(true) /* in */, any());
        clearInvocations(mQsDetail.mClipper);

        mQsDetail.handleShowingDetail(null, 0, 0, false);
        verify(mQsDetail.mClipper).updateCircularClip(eq(true) /* animate */, anyInt(), anyInt(),
                eq(false) /* in */, any());
    }

    @Test
    public void testShowDetail_ShouldNotAnimate() {
        mTestableLooper.processAllMessages();

        when(mMockDetailAdapter.shouldAnimate()).thenReturn(false);
        mQsDetail.setFullyExpanded(true);

        mQsDetail.handleShowingDetail(mMockDetailAdapter, 0, 0, false);
        verify(mQsDetail.mClipper).updateCircularClip(eq(false) /* animate */, anyInt(), anyInt(),
                eq(true) /* in */, any());
        clearInvocations(mQsDetail.mClipper);

        mQsDetail.handleShowingDetail(null, 0, 0, false);
        verify(mQsDetail.mClipper).updateCircularClip(eq(false) /* animate */, anyInt(), anyInt(),
                eq(false) /* in */, any());
    }

    @Test
    public void testDoneButton_CloseDetailPanel() {
        mTestableLooper.processAllMessages();

        when(mMockDetailAdapter.onDoneButtonClicked()).thenReturn(false);

        mQsDetail.handleShowingDetail(mMockDetailAdapter, 0, 0, false);
        mQsDetail.requireViewById(android.R.id.button1).performClick();
        verify(mQsPanelController).closeDetail();
    }

    @Test
    public void testDoneButton_KeepDetailPanelOpen() {
        mTestableLooper.processAllMessages();

        when(mMockDetailAdapter.onDoneButtonClicked()).thenReturn(true);

        mQsDetail.handleShowingDetail(mMockDetailAdapter, 0, 0, false);
        mQsDetail.requireViewById(android.R.id.button1).performClick();
        verify(mQsPanelController, never()).closeDetail();
    }

    @Test
    @Test
    public void testMoreSettingsButton() {
    public void testMoreSettingsButton() {
        mTestableLooper.processAllMessages();
        mTestableLooper.processAllMessages();