Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 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.server.am; |
| 18 | |
| 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 22 | |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 23 | import android.content.ComponentName; |
| 24 | import android.graphics.Rect; |
| 25 | import android.platform.test.annotations.Presubmit; |
| 26 | import android.support.test.filters.SmallTest; |
| 27 | import android.support.test.runner.AndroidJUnit4; |
| 28 | |
| 29 | import org.junit.runner.RunWith; |
| 30 | import org.junit.Test; |
| 31 | |
| 32 | import static com.android.server.am.ActivityManagerService.ANIMATE; |
| 33 | |
| 34 | import static org.junit.Assert.assertEquals; |
| 35 | import static org.junit.Assert.assertTrue; |
| 36 | import static org.mockito.Mockito.any; |
| 37 | import static org.mockito.Mockito.anyBoolean; |
| 38 | import static org.mockito.Mockito.anyInt; |
| 39 | import static org.mockito.Mockito.eq; |
| 40 | import static org.mockito.Mockito.verify; |
| 41 | import static org.mockito.Mockito.times; |
| 42 | |
| 43 | /** |
| 44 | * Tests for the {@link ActivityStack} class. |
| 45 | * |
| 46 | * Build/Install/Run: |
| 47 | * bit FrameworksServicesTests:com.android.server.am.ActivityStarterTests |
| 48 | */ |
| 49 | @SmallTest |
| 50 | @Presubmit |
| 51 | @RunWith(AndroidJUnit4.class) |
| 52 | public class ActivityStarterTests extends ActivityTestsBase { |
| 53 | private static final ComponentName testActivityComponent = |
| 54 | ComponentName.unflattenFromString("com.foo/.BarActivity"); |
| 55 | |
| 56 | private ActivityManagerService mService; |
| 57 | private ActivityStarter mStarter; |
| 58 | |
| 59 | @Override |
| 60 | public void setUp() throws Exception { |
| 61 | super.setUp(); |
| 62 | mService = createActivityManagerService(); |
| 63 | mStarter = new ActivityStarter(mService, mService.mStackSupervisor); |
| 64 | } |
| 65 | |
| 66 | @Test |
| 67 | public void testUpdateLaunchBounds() throws Exception { |
| 68 | // When in a non-resizeable stack, the task bounds should be updated. |
| 69 | final TaskRecord task = createTask(mService.mStackSupervisor, testActivityComponent, |
| 70 | mService.mStackSupervisor.getDefaultDisplay().createStack( |
| 71 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */)); |
| 72 | final Rect bounds = new Rect(10, 10, 100, 100); |
| 73 | |
| 74 | mStarter.updateBounds(task, bounds); |
| 75 | assertEquals(task.mBounds, bounds); |
| 76 | assertEquals(task.getStack().mBounds, null); |
| 77 | |
| 78 | // When in a resizeable stack, the stack bounds should be updated as well. |
| 79 | final TaskRecord task2 = createTask(mService.mStackSupervisor, testActivityComponent, |
| 80 | mService.mStackSupervisor.getDefaultDisplay().createStack( |
| 81 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */)); |
| 82 | assertTrue(task2.getStack() instanceof PinnedActivityStack); |
| 83 | mStarter.updateBounds(task2, bounds); |
| 84 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame^] | 85 | verify(mService, times(1)).resizeStack(eq(task2.getStack().mStackId), |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 86 | eq(bounds), anyBoolean(), anyBoolean(), anyBoolean(), anyInt()); |
| 87 | |
| 88 | // In the case of no animation, the stack and task bounds should be set immediately. |
| 89 | if (!ANIMATE) { |
| 90 | assertEquals(task2.getStack().mBounds, bounds); |
| 91 | assertEquals(task2.mBounds, bounds); |
| 92 | } else { |
| 93 | assertEquals(task2.mBounds, null); |
| 94 | } |
| 95 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame^] | 96 | } |