blob: e1623b075ef1de4bede49c5abe2a05d5da732d7f [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
Bryce Lee4e4a3ec2017-09-27 08:25:03 -070023import android.content.ComponentName;
24import android.graphics.Rect;
25import android.platform.test.annotations.Presubmit;
26import android.support.test.filters.SmallTest;
27import android.support.test.runner.AndroidJUnit4;
28
29import org.junit.runner.RunWith;
30import org.junit.Test;
31
32import static com.android.server.am.ActivityManagerService.ANIMATE;
33
34import static org.junit.Assert.assertEquals;
35import static org.junit.Assert.assertTrue;
36import static org.mockito.Mockito.any;
37import static org.mockito.Mockito.anyBoolean;
38import static org.mockito.Mockito.anyInt;
39import static org.mockito.Mockito.eq;
40import static org.mockito.Mockito.verify;
41import 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)
52public 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 Ogunwale44f036f2017-09-29 05:09:09 -070085 verify(mService, times(1)).resizeStack(eq(task2.getStack().mStackId),
Bryce Lee4e4a3ec2017-09-27 08:25:03 -070086 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 Ogunwale44f036f2017-09-29 05:09:09 -070096}