Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 14 | * limitations under the License. |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
| 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 21 | |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 22 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
| 23 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verifyZeroInteractions; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 24 | import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 25 | |
Tadashi G. Takaoka | 82eb7a5 | 2019-03-26 18:22:01 +0900 | [diff] [blame] | 26 | import static org.junit.Assert.assertFalse; |
| 27 | import static org.junit.Assert.assertTrue; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 28 | |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 29 | import android.platform.test.annotations.Presubmit; |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 30 | |
Wale Ogunwale | 8e85aee | 2019-04-30 15:55:05 -0700 | [diff] [blame] | 31 | import androidx.test.filters.FlakyTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 32 | import androidx.test.filters.SmallTest; |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 33 | |
| 34 | import org.junit.Before; |
| 35 | import org.junit.Test; |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 36 | import org.mockito.Mock; |
| 37 | import org.mockito.MockitoAnnotations; |
| 38 | |
| 39 | /** |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 40 | * Tests for the {@link ActivityStack} class. |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 41 | * |
| 42 | * Build/Install/Run: |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 43 | * atest FrameworksServicesTests:AnimatingActivityRegistryTest |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 44 | */ |
| 45 | @SmallTest |
| 46 | @Presubmit |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 47 | public class AnimatingActivityRegistryTest extends WindowTestsBase { |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 48 | |
| 49 | @Mock |
| 50 | AnimationAdapter mAdapter; |
| 51 | |
| 52 | @Mock |
| 53 | Runnable mMockEndDeferFinishCallback1; |
| 54 | @Mock |
| 55 | Runnable mMockEndDeferFinishCallback2; |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 56 | |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 57 | @Before |
| 58 | public void setUp() throws Exception { |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 59 | MockitoAnnotations.initMocks(this); |
| 60 | } |
| 61 | |
| 62 | @Test |
Vishnu Nair | a6f4e08 | 2019-12-16 13:44:19 -0800 | [diff] [blame] | 63 | @FlakyTest(bugId = 144611135) |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 64 | public void testDeferring() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 65 | final ActivityRecord activity1 = createActivityRecord(mDisplayContent, |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 66 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 67 | final ActivityRecord activity2 = createAppWindow(activity1.getTask(), ACTIVITY_TYPE_STANDARD, |
| 68 | "activity2").mActivityRecord; |
| 69 | final AnimatingActivityRegistry registry = |
| 70 | activity1.getStack().getAnimatingActivityRegistry(); |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 71 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 72 | activity1.startAnimation(activity1.getPendingTransaction(), mAdapter, false /* hidden */); |
| 73 | activity2.startAnimation(activity1.getPendingTransaction(), mAdapter, false /* hidden */); |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 74 | assertTrue(activity1.isAnimating(TRANSITION)); |
| 75 | assertTrue(activity2.isAnimating(TRANSITION)); |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 76 | |
| 77 | // Make sure that first animation finish is deferred, second one is not deferred, and first |
| 78 | // one gets cancelled. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 79 | assertTrue(registry.notifyAboutToFinish(activity1, mMockEndDeferFinishCallback1)); |
| 80 | assertFalse(registry.notifyAboutToFinish(activity2, mMockEndDeferFinishCallback2)); |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 81 | verify(mMockEndDeferFinishCallback1).run(); |
| 82 | verifyZeroInteractions(mMockEndDeferFinishCallback2); |
| 83 | } |
Jorim Jaggi | 68653ab | 2018-04-05 23:29:10 +0200 | [diff] [blame] | 84 | |
| 85 | @Test |
Wale Ogunwale | 8e85aee | 2019-04-30 15:55:05 -0700 | [diff] [blame] | 86 | @FlakyTest(bugId = 131005232) |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 87 | public void testContainerRemoved() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 88 | final ActivityRecord window1 = createActivityRecord(mDisplayContent, |
Jorim Jaggi | 68653ab | 2018-04-05 23:29:10 +0200 | [diff] [blame] | 89 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 90 | final ActivityRecord window2 = createAppWindow(window1.getTask(), ACTIVITY_TYPE_STANDARD, |
| 91 | "window2").mActivityRecord; |
| 92 | final AnimatingActivityRegistry registry = |
| 93 | window1.getStack().getAnimatingActivityRegistry(); |
Jorim Jaggi | 68653ab | 2018-04-05 23:29:10 +0200 | [diff] [blame] | 94 | |
| 95 | window1.startAnimation(window1.getPendingTransaction(), mAdapter, false /* hidden */); |
| 96 | window2.startAnimation(window1.getPendingTransaction(), mAdapter, false /* hidden */); |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 97 | assertTrue(window1.isAnimating(TRANSITION)); |
| 98 | assertTrue(window2.isAnimating(TRANSITION)); |
Jorim Jaggi | 68653ab | 2018-04-05 23:29:10 +0200 | [diff] [blame] | 99 | |
| 100 | // Make sure that first animation finish is deferred, and removing the second window stops |
| 101 | // finishes all pending deferred finishings. |
| 102 | registry.notifyAboutToFinish(window1, mMockEndDeferFinishCallback1); |
| 103 | window2.setParent(null); |
| 104 | verify(mMockEndDeferFinishCallback1).run(); |
| 105 | } |
Jorim Jaggi | 6de6101 | 2018-03-19 14:53:23 +0100 | [diff] [blame] | 106 | } |