ActivityStackTests.java revision 3345c4ea9687bb35a8c419ec21ec90b49616b2c9
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
17package com.android.server.am;
18
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertNotNull;
21import static org.junit.Assert.assertNull;
22import static org.junit.Assert.assertTrue;
23
24import android.content.ComponentName;
25import android.content.pm.ActivityInfo;
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
33/**
34 * Tests for the {@link ActivityStack} class.
35 *
36 * Build/Install/Run:
37 *  bit FrameworksServicesTests:com.android.server.am.ActivityStackTests
38 */
39@SmallTest
40@Presubmit
41@RunWith(AndroidJUnit4.class)
42public class ActivityStackTests extends ActivityTestsBase {
43    private static final int TEST_STACK_ID = 100;
44    private static final ComponentName testActivityComponent =
45            ComponentName.unflattenFromString("com.foo/.BarActivity");
46
47    @Test
48    public void testEmptyTaskCleanupOnRemove() throws Exception {
49        final ActivityManagerService service = createActivityManagerService();
50        final TaskRecord task = createTask(service, testActivityComponent, TEST_STACK_ID);
51        assertNotNull(task.getWindowContainerController());
52        service.mStackSupervisor.getStack(TEST_STACK_ID).removeTask(task,
53                "testEmptyTaskCleanupOnRemove", ActivityStack.REMOVE_TASK_MODE_DESTROYING);
54        assertNull(task.getWindowContainerController());
55    }
56
57    @Test
58    public void testOccupiedTaskCleanupOnRemove() throws Exception {
59        final ActivityManagerService service = createActivityManagerService();
60        final TaskRecord task = createTask(service, testActivityComponent, TEST_STACK_ID);
61        final ActivityRecord activityRecord = createActivity(service, testActivityComponent, task);
62        assertNotNull(task.getWindowContainerController());
63        service.mStackSupervisor.getStack(TEST_STACK_ID).removeTask(task,
64                "testOccupiedTaskCleanupOnRemove", ActivityStack.REMOVE_TASK_MODE_DESTROYING);
65        assertNotNull(task.getWindowContainerController());
66    }
67
68    @Test
69    public void testNoPauseDuringResumeTopActivity() throws Exception {
70        final ActivityManagerService service = createActivityManagerService();
71        final TaskRecord task = createTask(service, testActivityComponent, TEST_STACK_ID);
72        final ActivityRecord activityRecord = createActivity(service, testActivityComponent, task);
73        final ActivityStack testStack = service.mStackSupervisor.getStack(TEST_STACK_ID);
74
75        // Simulate the a resumed activity set during
76        // {@link ActivityStack#resumeTopActivityUncheckedLocked}.
77        service.mStackSupervisor.inResumeTopActivity = true;
78        testStack.mResumedActivity = activityRecord;
79
80        final boolean waiting = testStack.checkReadyForSleepLocked();
81
82        // Ensure we report not being ready for sleep.
83        assertTrue(waiting);
84
85        // Make sure the resumed activity is untouched.
86        assertEquals(testStack.mResumedActivity, activityRecord);
87    }
88
89    @Test
90    public void testStopActivityWhenActivityDestroyed() throws Exception {
91        final ActivityManagerService service = createActivityManagerService();
92        final TaskRecord task = createTask(service, testActivityComponent, TEST_STACK_ID);
93        final ActivityRecord activityRecord = createActivity(service, testActivityComponent, task);
94        activityRecord.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
95        final ActivityStack testStack = service.mStackSupervisor.getStack(TEST_STACK_ID);
96        service.mStackSupervisor.setFocusStackUnchecked("testStopActivityWithDestroy", testStack);
97
98        testStack.stopActivityLocked(activityRecord);
99    }
100}
101