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