blob: b769fcecc46983e52a593df8e6ebce57ed7d2631 [file] [log] [blame]
Jorim Jaggi04dc5962018-01-29 18:54:13 +01001/*
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 Ogunwale59507092018-10-29 09:00:30 -070014 * limitations under the License
Jorim Jaggi04dc5962018-01-29 18:54:13 +010015 */
16
Wale Ogunwale59507092018-10-29 09:00:30 -070017package com.android.server.wm;
Jorim Jaggi04dc5962018-01-29 18:54:13 +010018
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertNotNull;
21import static org.junit.Assert.assertNull;
22
Jorim Jaggi04dc5962018-01-29 18:54:13 +010023import android.app.ActivityOptions;
Jorim Jaggi04dc5962018-01-29 18:54:13 +010024import android.platform.test.annotations.Presubmit;
Jorim Jaggi04dc5962018-01-29 18:54:13 +010025import android.view.RemoteAnimationAdapter;
26
Brett Chabota26eda92018-07-23 13:08:30 -070027import androidx.test.filters.SmallTest;
Brett Chabota26eda92018-07-23 13:08:30 -070028
Jorim Jaggi04dc5962018-01-29 18:54:13 +010029import com.android.server.testutils.OffsettableClock;
30import com.android.server.testutils.TestHandler;
31
32import org.junit.Before;
33import org.junit.Test;
Jorim Jaggi04dc5962018-01-29 18:54:13 +010034import org.mockito.Mock;
35import org.mockito.MockitoAnnotations;
36
37/**
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090038 * Build/Install/Run:
39 * atest WmTests:PendingRemoteAnimationRegistryTest
Jorim Jaggi04dc5962018-01-29 18:54:13 +010040 */
41@SmallTest
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090042@Presubmit
Jorim Jaggi04dc5962018-01-29 18:54:13 +010043public 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 Jaggi04dc5962018-01-29 18:54:13 +010049
50 @Before
51 public void setUp() throws Exception {
Jorim Jaggi04dc5962018-01-29 18:54:13 +010052 MockitoAnnotations.initMocks(this);
Wale Ogunwale27c48ae2018-10-25 19:01:01 -070053 mService.mH.runWithScissors(() -> {
Jorim Jaggi04dc5962018-01-29 18:54:13 +010054 mHandler = new TestHandler(null, mClock);
55 }, 0);
Wale Ogunwale27c48ae2018-10-25 19:01:01 -070056 mRegistry = new PendingRemoteAnimationRegistry(mService, mHandler);
Jorim Jaggi04dc5962018-01-29 18:54:13 +010057 }
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}