TaskSnapshotCacheTest.java revision 10abe2fe297ce1ec60c15a3bd947757aee5b14b3
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.wm;
18
19import static android.graphics.GraphicBuffer.USAGE_HW_TEXTURE;
20import static android.graphics.GraphicBuffer.USAGE_SW_READ_NEVER;
21import static android.graphics.GraphicBuffer.USAGE_SW_WRITE_NEVER;
22import static android.graphics.GraphicBuffer.create;
23import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
24import static junit.framework.Assert.assertNotNull;
25import static junit.framework.Assert.assertNull;
26
27import android.app.ActivityManager.TaskSnapshot;
28import android.content.res.Configuration;
29import android.graphics.GraphicBuffer;
30import android.graphics.PixelFormat;
31import android.graphics.Rect;
32import android.platform.test.annotations.Presubmit;
33import android.support.test.filters.SmallTest;
34import android.support.test.runner.AndroidJUnit4;
35
36import org.junit.Test;
37import org.junit.runner.RunWith;
38
39/**
40 * Test class for {@link TaskSnapshotCache}.
41 *
42 * runtest frameworks-services -c com.android.server.wm.TaskSnapshotCacheTest
43 */
44@SmallTest
45@Presubmit
46@RunWith(AndroidJUnit4.class)
47public class TaskSnapshotCacheTest extends WindowTestsBase {
48
49    @Test
50    public void testCleanCache() throws Exception {
51        TaskSnapshotCache snapshotCache = new TaskSnapshotCache();
52        final WindowState window = createWindow(null, FIRST_APPLICATION_WINDOW, "window");
53        snapshotCache.putSnapshot(window.getTask(), createSnapshot());
54        assertNotNull(snapshotCache.getSnapshot(window.getTask()));
55        snapshotCache.cleanCache(window.mAppToken);
56        assertNull(snapshotCache.getSnapshot(window.getTask()));
57    }
58
59    private TaskSnapshot createSnapshot() {
60        GraphicBuffer buffer = create(1, 1, PixelFormat.RGBA_8888,
61                USAGE_HW_TEXTURE | USAGE_SW_WRITE_NEVER | USAGE_SW_READ_NEVER);
62        return new TaskSnapshot(buffer, Configuration.ORIENTATION_PORTRAIT, new Rect());
63    }
64}
65