1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.systemui;
18 
19 import static org.mockito.ArgumentMatchers.any;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.when;
22 
23 import android.content.Context;
24 import android.testing.AndroidTestingRunner;
25 import android.testing.TestableLooper;
26 import android.testing.TestableLooper.RunWithLooper;
27 
28 import androidx.core.animation.ObjectAnimator;
29 import androidx.test.annotation.UiThreadTest;
30 import androidx.test.filters.SmallTest;
31 
32 import com.android.keyguard.KeyguardUpdateMonitor;
33 import com.android.systemui.animation.AnimatorTestRule;
34 import com.android.systemui.flags.FakeFeatureFlags;
35 import com.android.systemui.statusbar.NotificationMediaManager;
36 import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
37 import com.android.systemui.statusbar.notification.row.NotificationTestHelper;
38 
39 import org.junit.Before;
40 import org.junit.Rule;
41 import org.junit.Test;
42 import org.junit.runner.RunWith;
43 
44 @SmallTest
45 @RunWith(AndroidTestingRunner.class)
46 @RunWithLooper
47 public class ExpandHelperTest extends SysuiTestCase {
48 
49     @Rule
50     public final AnimatorTestRule mAnimatorTestRule = new AnimatorTestRule(this);
51 
52     private final FakeFeatureFlags mFeatureFlags = new FakeFeatureFlags();
53     private ExpandableNotificationRow mRow;
54     private ExpandHelper mExpandHelper;
55     private ExpandHelper.Callback mCallback;
56 
57     @Before
setUp()58     public void setUp() throws Exception {
59         mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
60         mDependency.injectMockDependency(NotificationMediaManager.class);
61         allowTestableLooperAsMainThread();
62         Context context = getContext();
63         NotificationTestHelper helper = new NotificationTestHelper(
64                 mContext,
65                 mDependency,
66                 TestableLooper.get(this),
67                 mFeatureFlags);
68         mRow = helper.createRow();
69         mCallback = mock(ExpandHelper.Callback.class);
70         mExpandHelper = new ExpandHelper(context, mCallback, 10, 100);
71     }
72 
73     @Test
74     @UiThreadTest
testAnimationDoesntClearViewIfNewExpansionStarted()75     public void testAnimationDoesntClearViewIfNewExpansionStarted() {
76         when(mCallback.getMaxExpandHeight(any())).thenReturn(100);
77         mExpandHelper.startExpanding(mRow, 0);
78         mExpandHelper.finishExpanding(false, 0);
79         mExpandHelper.startExpanding(mRow, 0);
80         ObjectAnimator scaleAnimation = mExpandHelper.getScaleAnimation();
81         scaleAnimation.end();
82         mExpandHelper.updateExpansion();
83     }
84 
85 }
86