TaskSnapshotSurfaceTest.java revision ba53d8ae410976709e1413b74173a791e8dead15
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 org.mockito.Matchers.any;
20import static org.mockito.Matchers.anyInt;
21import static org.mockito.Matchers.eq;
22import static org.mockito.Mockito.mock;
23import static org.mockito.Mockito.never;
24import static org.mockito.Mockito.verify;
25import static org.mockito.Mockito.when;
26
27import android.graphics.Bitmap;
28import android.graphics.Bitmap.Config;
29import android.graphics.Canvas;
30import android.graphics.Color;
31import android.platform.test.annotations.Presubmit;
32import android.support.test.filters.SmallTest;
33import android.support.test.runner.AndroidJUnit4;
34
35import org.junit.Before;
36import org.junit.Test;
37import org.junit.runner.RunWith;
38
39/**
40 * Test class for {@link TaskSnapshotSurface}.
41 *
42 * runtest frameworks-services -c com.android.server.wm.TaskSnapshotSurfaceTest
43 */
44@SmallTest
45@Presubmit
46@RunWith(AndroidJUnit4.class)
47public class TaskSnapshotSurfaceTest extends WindowTestsBase {
48
49    private TaskSnapshotSurface mSurface;
50
51    @Before
52    public void setUp() {
53        mSurface = new TaskSnapshotSurface(null, null, null, Color.WHITE);
54    }
55
56    @Test
57    public void fillEmptyBackground_fillHorizontally() throws Exception {
58        final Canvas mockCanvas = mock(Canvas.class);
59        when(mockCanvas.getWidth()).thenReturn(200);
60        when(mockCanvas.getHeight()).thenReturn(100);
61        final Bitmap b = Bitmap.createBitmap(100, 200, Config.ARGB_8888);
62        mSurface.fillEmptyBackground(mockCanvas, b);
63        verify(mockCanvas).drawRect(eq(100.0f), eq(0.0f), eq(200.0f), eq(100.0f), any());
64    }
65
66    @Test
67    public void fillEmptyBackground_fillVertically() throws Exception {
68        final Canvas mockCanvas = mock(Canvas.class);
69        when(mockCanvas.getWidth()).thenReturn(100);
70        when(mockCanvas.getHeight()).thenReturn(200);
71        final Bitmap b = Bitmap.createBitmap(200, 100, Config.ARGB_8888);
72        mSurface.fillEmptyBackground(mockCanvas, b);
73        verify(mockCanvas).drawRect(eq(0.0f), eq(100.0f), eq(100.0f), eq(200.0f), any());
74    }
75
76    @Test
77    public void fillEmptyBackground_fillBoth() throws Exception {
78        final Canvas mockCanvas = mock(Canvas.class);
79        when(mockCanvas.getWidth()).thenReturn(200);
80        when(mockCanvas.getHeight()).thenReturn(200);
81        final Bitmap b = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
82        mSurface.fillEmptyBackground(mockCanvas, b);
83        verify(mockCanvas).drawRect(eq(100.0f), eq(0.0f), eq(200.0f), eq(100.0f), any());
84        verify(mockCanvas).drawRect(eq(0.0f), eq(100.0f), eq(200.0f), eq(200.0f), any());
85    }
86
87    @Test
88    public void fillEmptyBackground_dontFill_sameSize() throws Exception {
89        final Canvas mockCanvas = mock(Canvas.class);
90        when(mockCanvas.getWidth()).thenReturn(100);
91        when(mockCanvas.getHeight()).thenReturn(100);
92        final Bitmap b = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
93        mSurface.fillEmptyBackground(mockCanvas, b);
94        verify(mockCanvas, never()).drawRect(anyInt(), anyInt(), anyInt(), anyInt(), any());
95    }
96
97    @Test
98    public void fillEmptyBackground_dontFill_bitmapLarger() throws Exception {
99        final Canvas mockCanvas = mock(Canvas.class);
100        when(mockCanvas.getWidth()).thenReturn(100);
101        when(mockCanvas.getHeight()).thenReturn(100);
102        final Bitmap b = Bitmap.createBitmap(200, 200, Config.ARGB_8888);
103        mSurface.fillEmptyBackground(mockCanvas, b);
104        verify(mockCanvas, never()).drawRect(anyInt(), anyInt(), anyInt(), anyInt(), any());
105    }
106}
107