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.flags.Flags;
36 import com.android.systemui.statusbar.NotificationMediaManager;
37 import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
38 import com.android.systemui.statusbar.notification.row.NotificationTestHelper;
39 
40 import org.junit.Before;
41 import org.junit.Rule;
42 import org.junit.Test;
43 import org.junit.runner.RunWith;
44 
45 @SmallTest
46 @RunWith(AndroidTestingRunner.class)
47 @RunWithLooper
48 public class ExpandHelperTest extends SysuiTestCase {
49 
50     @Rule
51     public final AnimatorTestRule mAnimatorTestRule = new AnimatorTestRule();
52 
53     private final FakeFeatureFlags mFeatureFlags = new FakeFeatureFlags();
54     private ExpandableNotificationRow mRow;
55     private ExpandHelper mExpandHelper;
56     private ExpandHelper.Callback mCallback;
57 
58     @Before
setUp()59     public void setUp() throws Exception {
60         mFeatureFlags.setDefault(Flags.NOTIFICATION_INLINE_REPLY_ANIMATION);
61         mDependency.injectMockDependency(KeyguardUpdateMonitor.class);
62         mDependency.injectMockDependency(NotificationMediaManager.class);
63         allowTestableLooperAsMainThread();
64         Context context = getContext();
65         NotificationTestHelper helper = new NotificationTestHelper(
66                 mContext,
67                 mDependency,
68                 TestableLooper.get(this),
69                 mFeatureFlags);
70         mRow = helper.createRow();
71         mCallback = mock(ExpandHelper.Callback.class);
72         mExpandHelper = new ExpandHelper(context, mCallback, 10, 100);
73     }
74 
75     @Test
76     @UiThreadTest
testAnimationDoesntClearViewIfNewExpansionStarted()77     public void testAnimationDoesntClearViewIfNewExpansionStarted() {
78         when(mCallback.getMaxExpandHeight(any())).thenReturn(100);
79         mExpandHelper.startExpanding(mRow, 0);
80         mExpandHelper.finishExpanding(false, 0);
81         mExpandHelper.startExpanding(mRow, 0);
82         ObjectAnimator scaleAnimation = mExpandHelper.getScaleAnimation();
83         scaleAnimation.end();
84         mExpandHelper.updateExpansion();
85     }
86 
87 }
88