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

Commit aae30804 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Fix NPVCTest

Fixes: 341163515
Test: atest NotificationPanelViewControllerTest
Flag: test_only
Change-Id: I8709addeae09346f6b16e86d29e67ec23e444733
parent ce6f860b
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -253,6 +253,7 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;

import javax.inject.Inject;
@@ -449,6 +450,9 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
    private final ShadeHeadsUpTrackerImpl mShadeHeadsUpTracker = new ShadeHeadsUpTrackerImpl();
    private final ShadeFoldAnimatorImpl mShadeFoldAnimator = new ShadeFoldAnimatorImpl();

    @VisibleForTesting
    Set<Animator> mTestSetOfAnimatorsUsed;

    private boolean mShowIconsWhenExpanded;
    private int mIndicationBottomPadding;
    private int mAmbientIndicationBottomPadding;
@@ -4149,6 +4153,8 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
    }

    private void setAnimator(ValueAnimator animator) {
        // TODO(b/341163515): Should we clean up the old animator?
        registerAnimatorForTest(animator);
        mHeightAnimator = animator;
        if (animator == null && mPanelUpdateWhenAnimatorEnds) {
            mPanelUpdateWhenAnimatorEnds = false;
@@ -4193,6 +4199,7 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
    private ValueAnimator createHeightAnimator(float targetHeight, float overshootAmount) {
        float startExpansion = mOverExpansion;
        ValueAnimator animator = ValueAnimator.ofFloat(mExpandedHeight, targetHeight);
        registerAnimatorForTest(animator);
        animator.addUpdateListener(
                animation -> {
                    if (overshootAmount > 0.0f
@@ -4210,6 +4217,12 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
        return animator;
    }

    private void registerAnimatorForTest(Animator animator) {
        if (mTestSetOfAnimatorsUsed != null) {
            mTestSetOfAnimatorsUsed.add(animator);
        }
    }

    /** Update the visibility of {@link NotificationPanelView} if necessary. */
    private void updateVisibility() {
        mView.setVisibility(shouldPanelBeVisible() ? VISIBLE : INVISIBLE);
+18 −2
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.animation.Animator;
import android.annotation.IdRes;
import android.content.ContentResolver;
import android.content.res.Configuration;
@@ -207,12 +208,15 @@ import kotlinx.coroutines.test.TestScope;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.stubbing.Answer;

import java.util.HashSet;
import java.util.List;
import java.util.Optional;

@@ -387,9 +391,11 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase {

    protected FragmentHostManager.FragmentListener mFragmentListener;

    @Rule(order = 200)
    public MockitoRule mMockitoRule = MockitoJUnit.rule();

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        mFeatureFlags.set(Flags.LOCKSCREEN_ENABLE_LANDSCAPE, false);
        mFeatureFlags.set(Flags.QS_USER_DETAIL_SHORTCUT, false);

@@ -761,6 +767,9 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase {
                    @Override
                    public void onOpenStarted() {}
                });
        // Create a set to which the class will add all animators used, so that we can
        // verify that they are all stopped.
        mNotificationPanelViewController.mTestSetOfAnimatorsUsed = new HashSet<>();
        ArgumentCaptor<View.OnAttachStateChangeListener> onAttachStateChangeListenerArgumentCaptor =
                ArgumentCaptor.forClass(View.OnAttachStateChangeListener.class);
        verify(mView, atLeast(1)).addOnAttachStateChangeListener(
@@ -822,13 +831,20 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase {

    @After
    public void tearDown() {
        List<Animator> leakedAnimators = null;
        if (mNotificationPanelViewController != null) {
            mNotificationPanelViewController.mBottomAreaShadeAlphaAnimator.cancel();
            mNotificationPanelViewController.cancelHeightAnimator();
            leakedAnimators = mNotificationPanelViewController.mTestSetOfAnimatorsUsed.stream()
                    .filter(Animator::isRunning).toList();
            mNotificationPanelViewController.mTestSetOfAnimatorsUsed.forEach(Animator::cancel);
        }
        if (mMainHandler != null) {
            mMainHandler.removeCallbacksAndMessages(null);
        }
        if (leakedAnimators != null) {
            assertThat(leakedAnimators).isEmpty();
        }
    }

    protected void setBottomPadding(int stackBottom, int lockIconPadding, int indicationPadding,
+1 −0
Original line number Diff line number Diff line
@@ -705,6 +705,7 @@ public class NotificationPanelViewControllerTest extends NotificationPanelViewCo
    }

    @Test
    @Ignore("b/341163515 - fails to clean up animators correctly")
    public void testSwipeWhileLocked_notifiesKeyguardState() {
        mStatusBarStateController.setState(KEYGUARD);