blob: 5b1e4b731d38ec0834ba36c7322b13b5d07459cd [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 {
Bryce Lee4e4a3ec2017-09-27 08:25:03 -070053 private ActivityManagerService mService;
54 private ActivityStarter mStarter;
55
56 @Override
57 public void setUp() throws Exception {
58 super.setUp();
59 mService = createActivityManagerService();
Bryce Lee7daee392017-10-12 13:46:18 -070060 mStarter = new ActivityStarter(mService);
Bryce Lee4e4a3ec2017-09-27 08:25:03 -070061 }
62
63 @Test
64 public void testUpdateLaunchBounds() throws Exception {
65 // When in a non-resizeable stack, the task bounds should be updated.
Bryce Lee18d51592017-10-25 10:22:19 -070066 final TaskRecord task = new TaskBuilder(mService.mStackSupervisor)
67 .setStack(mService.mStackSupervisor.getDefaultDisplay().createStack(
68 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */))
69 .build();
Bryce Lee4e4a3ec2017-09-27 08:25:03 -070070 final Rect bounds = new Rect(10, 10, 100, 100);
71
72 mStarter.updateBounds(task, bounds);
73 assertEquals(task.mBounds, bounds);
74 assertEquals(task.getStack().mBounds, null);
75
76 // When in a resizeable stack, the stack bounds should be updated as well.
Bryce Lee18d51592017-10-25 10:22:19 -070077 final TaskRecord task2 = new TaskBuilder(mService.mStackSupervisor)
78 .setStack(mService.mStackSupervisor.getDefaultDisplay().createStack(
79 WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, true /* onTop */))
80 .build();
Bryce Lee4e4a3ec2017-09-27 08:25:03 -070081 assertTrue(task2.getStack() instanceof PinnedActivityStack);
82 mStarter.updateBounds(task2, bounds);
83
Wale Ogunwale44f036f2017-09-29 05:09:09 -070084 verify(mService, times(1)).resizeStack(eq(task2.getStack().mStackId),
Bryce Lee4e4a3ec2017-09-27 08:25:03 -070085 eq(bounds), anyBoolean(), anyBoolean(), anyBoolean(), anyInt());
86
87 // In the case of no animation, the stack and task bounds should be set immediately.
88 if (!ANIMATE) {
89 assertEquals(task2.getStack().mBounds, bounds);
90 assertEquals(task2.mBounds, bounds);
91 } else {
92 assertEquals(task2.mBounds, null);
93 }
94 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -070095}