blob: 48464e5e0248a2852f6a79cb4ce6697308d8e341 [file] [log] [blame]
Bryce Lee840c5662017-04-13 10:02:51 -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
Bryce Lee5daa3122017-04-19 10:40:42 -070019import static org.junit.Assert.assertEquals;
Bryce Lee840c5662017-04-13 10:02:51 -070020import static org.junit.Assert.assertNotNull;
21import static org.junit.Assert.assertNull;
Bryce Lee5daa3122017-04-19 10:40:42 -070022import static org.junit.Assert.assertTrue;
Bryce Lee840c5662017-04-13 10:02:51 -070023
Bryce Lee943ebe72017-05-04 10:19:07 -070024import android.app.ActivityManager;
Bryce Lee840c5662017-04-13 10:02:51 -070025import android.content.ComponentName;
Bryce Lee3345c4e2017-04-25 07:40:41 -070026import android.content.pm.ActivityInfo;
Bryce Lee840c5662017-04-13 10:02:51 -070027import android.platform.test.annotations.Presubmit;
28import android.support.test.filters.SmallTest;
29import android.support.test.runner.AndroidJUnit4;
30
31import org.junit.runner.RunWith;
32import org.junit.Test;
33
34/**
35 * Tests for the {@link ActivityStack} class.
36 *
37 * Build/Install/Run:
38 * bit FrameworksServicesTests:com.android.server.am.ActivityStackTests
39 */
40@SmallTest
41@Presubmit
42@RunWith(AndroidJUnit4.class)
43public class ActivityStackTests extends ActivityTestsBase {
Bryce Lee04ab3462017-04-10 15:06:33 -070044 private static final int TEST_STACK_ID = 100;
45 private static final ComponentName testActivityComponent =
Bryce Lee840c5662017-04-13 10:02:51 -070046 ComponentName.unflattenFromString("com.foo/.BarActivity");
47
48 @Test
49 public void testEmptyTaskCleanupOnRemove() throws Exception {
50 final ActivityManagerService service = createActivityManagerService();
Bryce Lee04ab3462017-04-10 15:06:33 -070051 final TaskRecord task = createTask(service, testActivityComponent, TEST_STACK_ID);
Bryce Lee840c5662017-04-13 10:02:51 -070052 assertNotNull(task.getWindowContainerController());
Bryce Lee04ab3462017-04-10 15:06:33 -070053 service.mStackSupervisor.getStack(TEST_STACK_ID).removeTask(task,
54 "testEmptyTaskCleanupOnRemove", ActivityStack.REMOVE_TASK_MODE_DESTROYING);
Bryce Lee840c5662017-04-13 10:02:51 -070055 assertNull(task.getWindowContainerController());
56 }
Bryce Lee5daa3122017-04-19 10:40:42 -070057
Bryce Lee840c5662017-04-13 10:02:51 -070058 @Test
59 public void testOccupiedTaskCleanupOnRemove() throws Exception {
60 final ActivityManagerService service = createActivityManagerService();
Bryce Lee04ab3462017-04-10 15:06:33 -070061 final TaskRecord task = createTask(service, testActivityComponent, TEST_STACK_ID);
Bryce Lee840c5662017-04-13 10:02:51 -070062 final ActivityRecord activityRecord = createActivity(service, testActivityComponent, task);
63 assertNotNull(task.getWindowContainerController());
Bryce Lee04ab3462017-04-10 15:06:33 -070064 service.mStackSupervisor.getStack(TEST_STACK_ID).removeTask(task,
65 "testOccupiedTaskCleanupOnRemove", ActivityStack.REMOVE_TASK_MODE_DESTROYING);
Bryce Lee840c5662017-04-13 10:02:51 -070066 assertNotNull(task.getWindowContainerController());
67 }
Bryce Lee5daa3122017-04-19 10:40:42 -070068
69 @Test
70 public void testNoPauseDuringResumeTopActivity() throws Exception {
71 final ActivityManagerService service = createActivityManagerService();
72 final TaskRecord task = createTask(service, testActivityComponent, TEST_STACK_ID);
73 final ActivityRecord activityRecord = createActivity(service, testActivityComponent, task);
74 final ActivityStack testStack = service.mStackSupervisor.getStack(TEST_STACK_ID);
75
76 // Simulate the a resumed activity set during
77 // {@link ActivityStack#resumeTopActivityUncheckedLocked}.
78 service.mStackSupervisor.inResumeTopActivity = true;
79 testStack.mResumedActivity = activityRecord;
80
81 final boolean waiting = testStack.checkReadyForSleepLocked();
82
83 // Ensure we report not being ready for sleep.
84 assertTrue(waiting);
85
86 // Make sure the resumed activity is untouched.
87 assertEquals(testStack.mResumedActivity, activityRecord);
88 }
Bryce Lee3345c4e2017-04-25 07:40:41 -070089
90 @Test
91 public void testStopActivityWhenActivityDestroyed() throws Exception {
92 final ActivityManagerService service = createActivityManagerService();
93 final TaskRecord task = createTask(service, testActivityComponent, TEST_STACK_ID);
94 final ActivityRecord activityRecord = createActivity(service, testActivityComponent, task);
95 activityRecord.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
96 final ActivityStack testStack = service.mStackSupervisor.getStack(TEST_STACK_ID);
97 service.mStackSupervisor.setFocusStackUnchecked("testStopActivityWithDestroy", testStack);
98
99 testStack.stopActivityLocked(activityRecord);
100 }
Bryce Lee840c5662017-04-13 10:02:51 -0700101}