Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +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 |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 14 | * limitations under the License |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 18 | |
| 19 | import static org.junit.Assert.assertEquals; |
| 20 | import static org.junit.Assert.assertNotNull; |
| 21 | import static org.junit.Assert.assertNull; |
| 22 | |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 23 | import android.app.ActivityOptions; |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 24 | import android.platform.test.annotations.Presubmit; |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 25 | import android.view.RemoteAnimationAdapter; |
| 26 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 27 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 28 | |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 29 | import com.android.server.testutils.OffsettableClock; |
| 30 | import com.android.server.testutils.TestHandler; |
| 31 | |
| 32 | import org.junit.Before; |
| 33 | import org.junit.Test; |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 34 | import org.mockito.Mock; |
| 35 | import org.mockito.MockitoAnnotations; |
| 36 | |
| 37 | /** |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 38 | * Build/Install/Run: |
| 39 | * atest WmTests:PendingRemoteAnimationRegistryTest |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 40 | */ |
| 41 | @SmallTest |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 42 | @Presubmit |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 43 | public class PendingRemoteAnimationRegistryTest extends ActivityTestsBase { |
| 44 | |
| 45 | @Mock RemoteAnimationAdapter mAdapter; |
| 46 | private PendingRemoteAnimationRegistry mRegistry; |
| 47 | private final OffsettableClock mClock = new OffsettableClock.Stopped(); |
| 48 | private TestHandler mHandler; |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 49 | |
| 50 | @Before |
| 51 | public void setUp() throws Exception { |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 52 | MockitoAnnotations.initMocks(this); |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 53 | mService.mH.runWithScissors(() -> { |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 54 | mHandler = new TestHandler(null, mClock); |
| 55 | }, 0); |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 56 | mRegistry = new PendingRemoteAnimationRegistry(mService, mHandler); |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | @Test |
| 60 | public void testOverrideActivityOptions() { |
| 61 | mRegistry.addPendingAnimation("com.android.test", mAdapter); |
| 62 | ActivityOptions opts = ActivityOptions.makeBasic(); |
| 63 | opts = mRegistry.overrideOptionsIfNeeded("com.android.test", opts); |
| 64 | assertEquals(mAdapter, opts.getRemoteAnimationAdapter()); |
| 65 | } |
| 66 | |
| 67 | @Test |
| 68 | public void testOverrideActivityOptions_null() { |
| 69 | mRegistry.addPendingAnimation("com.android.test", mAdapter); |
| 70 | final ActivityOptions opts = mRegistry.overrideOptionsIfNeeded("com.android.test", null); |
| 71 | assertNotNull(opts); |
| 72 | assertEquals(mAdapter, opts.getRemoteAnimationAdapter()); |
| 73 | } |
| 74 | |
| 75 | @Test |
| 76 | public void testTimeout() { |
| 77 | mRegistry.addPendingAnimation("com.android.test", mAdapter); |
| 78 | mClock.fastForward(5000); |
| 79 | mHandler.timeAdvance(); |
| 80 | assertNull(mRegistry.overrideOptionsIfNeeded("com.android.test", null)); |
| 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void testTimeout_overridenEntry() { |
| 85 | mRegistry.addPendingAnimation("com.android.test", mAdapter); |
| 86 | mClock.fastForward(2500); |
| 87 | mHandler.timeAdvance(); |
| 88 | mRegistry.addPendingAnimation("com.android.test", mAdapter); |
| 89 | mClock.fastForward(1000); |
| 90 | mHandler.timeAdvance(); |
| 91 | final ActivityOptions opts = mRegistry.overrideOptionsIfNeeded("com.android.test", null); |
| 92 | assertEquals(mAdapter, opts.getRemoteAnimationAdapter()); |
| 93 | } |
| 94 | } |