blob: 855b82c233e0c3be19af77c984600802d6497b50 [file] [log] [blame]
Bryce Lee4e4a3ec2017-09-27 08:25:03 -07001/*
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
17package com.android.server.am;
18
19import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
20import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
21import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
22
23import android.app.ActivityManager;
24import android.content.ComponentName;
25import android.graphics.Rect;
26import android.platform.test.annotations.Presubmit;
27import android.support.test.filters.SmallTest;
28import android.support.test.runner.AndroidJUnit4;
29
30import org.junit.runner.RunWith;
31import org.junit.Test;
32
33import static com.android.server.am.ActivityManagerService.ANIMATE;
34
35import static org.junit.Assert.assertEquals;
36import static org.junit.Assert.assertTrue;
37import static org.mockito.Mockito.any;
38import static org.mockito.Mockito.anyBoolean;
39import static org.mockito.Mockito.anyInt;
40import static org.mockito.Mockito.eq;
41import static org.mockito.Mockito.verify;
42import 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)
53public 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}