blob: c9d800449ff9adb063b9ad7510135d288bebe664 [file] [log] [blame]
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01001/*
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.wm;
18
Jorim Jaggi10abe2f2017-01-03 16:44:46 +010019import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
Brett Chabota26eda92018-07-23 13:08:30 -070020
Jorim Jaggi10abe2f2017-01-03 16:44:46 +010021import static junit.framework.Assert.assertNotNull;
22import static junit.framework.Assert.assertNull;
23
Wale Ogunwale68e882c2017-05-03 07:54:23 -070024import android.platform.test.annotations.Presubmit;
Brett Chabota26eda92018-07-23 13:08:30 -070025
26import androidx.test.filters.SmallTest;
27import androidx.test.runner.AndroidJUnit4;
Jorim Jaggi10abe2f2017-01-03 16:44:46 +010028
Jorim Jaggi7361bab2017-01-16 17:17:58 +010029import org.junit.Before;
Jorim Jaggi10abe2f2017-01-03 16:44:46 +010030import org.junit.Test;
31import org.junit.runner.RunWith;
32
33/**
34 * Test class for {@link TaskSnapshotCache}.
35 *
John Reck3d294e72018-09-21 20:26:48 +000036 * runtest frameworks-services -c com.android.server.wm.TaskSnapshotCacheTest
Jorim Jaggi10abe2f2017-01-03 16:44:46 +010037 */
38@SmallTest
Wale Ogunwale68e882c2017-05-03 07:54:23 -070039@Presubmit
Jorim Jaggi10abe2f2017-01-03 16:44:46 +010040@RunWith(AndroidJUnit4.class)
Jorim Jaggi7361bab2017-01-16 17:17:58 +010041public class TaskSnapshotCacheTest extends TaskSnapshotPersisterTestBase {
Jorim Jaggi10abe2f2017-01-03 16:44:46 +010042
Jorim Jaggi7361bab2017-01-16 17:17:58 +010043 private TaskSnapshotCache mCache;
44
45 @Before
46 public void setUp() throws Exception {
47 super.setUp();
48 mCache = new TaskSnapshotCache(sWm, mLoader);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +010049 }
50
Jorim Jaggi7361bab2017-01-16 17:17:58 +010051 @Test
52 public void testAppRemoved() throws Exception {
53 final WindowState window = createWindow(null, FIRST_APPLICATION_WINDOW, "window");
54 mCache.putSnapshot(window.getTask(), createSnapshot());
55 assertNotNull(mCache.getSnapshot(window.getTask().mTaskId, 0 /* userId */,
Jorim Jaggi35e3f532017-03-17 17:06:50 +010056 false /* restoreFromDisk */, false /* reducedResolution */));
Jorim Jaggi7361bab2017-01-16 17:17:58 +010057 mCache.onAppRemoved(window.mAppToken);
58 assertNull(mCache.getSnapshot(window.getTask().mTaskId, 0 /* userId */,
Jorim Jaggi35e3f532017-03-17 17:06:50 +010059 false /* restoreFromDisk */, false /* reducedResolution */));
Jorim Jaggi7361bab2017-01-16 17:17:58 +010060 }
61
62 @Test
63 public void testAppDied() throws Exception {
64 final WindowState window = createWindow(null, FIRST_APPLICATION_WINDOW, "window");
65 mCache.putSnapshot(window.getTask(), createSnapshot());
66 assertNotNull(mCache.getSnapshot(window.getTask().mTaskId, 0 /* userId */,
Jorim Jaggi35e3f532017-03-17 17:06:50 +010067 false /* restoreFromDisk */, false /* reducedResolution */));
Jorim Jaggi7361bab2017-01-16 17:17:58 +010068 mCache.onAppDied(window.mAppToken);
Jorim Jaggi7361bab2017-01-16 17:17:58 +010069 assertNull(mCache.getSnapshot(window.getTask().mTaskId, 0 /* userId */,
Jorim Jaggi35e3f532017-03-17 17:06:50 +010070 false /* restoreFromDisk */, false /* reducedResolution */));
Jorim Jaggi7361bab2017-01-16 17:17:58 +010071 }
72
73 @Test
74 public void testTaskRemoved() throws Exception {
75 final WindowState window = createWindow(null, FIRST_APPLICATION_WINDOW, "window");
76 mCache.putSnapshot(window.getTask(), createSnapshot());
77 assertNotNull(mCache.getSnapshot(window.getTask().mTaskId, 0 /* userId */,
Jorim Jaggi35e3f532017-03-17 17:06:50 +010078 false /* restoreFromDisk */, false /* reducedResolution */));
Jorim Jaggi7361bab2017-01-16 17:17:58 +010079 mCache.onTaskRemoved(window.getTask().mTaskId);
80 assertNull(mCache.getSnapshot(window.getTask().mTaskId, 0 /* userId */,
Jorim Jaggi35e3f532017-03-17 17:06:50 +010081 false /* restoreFromDisk */, false /* reducedResolution */));
82 }
83
84 @Test
85 public void testReduced_notCached() throws Exception {
86 final WindowState window = createWindow(null, FIRST_APPLICATION_WINDOW, "window");
87 mPersister.persistSnapshot(window.getTask().mTaskId, sWm.mCurrentUserId, createSnapshot());
88 mPersister.waitForQueueEmpty();
89 assertNull(mCache.getSnapshot(window.getTask().mTaskId, sWm.mCurrentUserId,
90 false /* restoreFromDisk */, false /* reducedResolution */));
91
92 // Load it from disk
93 assertNotNull(mCache.getSnapshot(window.getTask().mTaskId, sWm.mCurrentUserId,
94 true /* restoreFromDisk */, true /* reducedResolution */));
95
96 // Make sure it's not in the cache now.
97 assertNull(mCache.getSnapshot(window.getTask().mTaskId, sWm.mCurrentUserId,
98 false /* restoreFromDisk */, false /* reducedResolution */));
Jorim Jaggi7361bab2017-01-16 17:17:58 +010099 }
100
101 @Test
102 public void testRestoreFromDisk() throws Exception {
103 final WindowState window = createWindow(null, FIRST_APPLICATION_WINDOW, "window");
104 mPersister.persistSnapshot(window.getTask().mTaskId, sWm.mCurrentUserId, createSnapshot());
105 mPersister.waitForQueueEmpty();
106 assertNull(mCache.getSnapshot(window.getTask().mTaskId, sWm.mCurrentUserId,
Jorim Jaggi35e3f532017-03-17 17:06:50 +0100107 false /* restoreFromDisk */, false /* reducedResolution */));
Jorim Jaggi7361bab2017-01-16 17:17:58 +0100108
109 // Load it from disk
110 assertNotNull(mCache.getSnapshot(window.getTask().mTaskId, sWm.mCurrentUserId,
Jorim Jaggi35e3f532017-03-17 17:06:50 +0100111 true /* restoreFromDisk */, false /* reducedResolution */));
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100112 }
113}