blob: b03abecbc59b64f348d0ff3ec7fbfe76247b1f36 [file] [log] [blame]
Selim Cineka7679b62017-05-10 16:33:25 -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.systemui.statusbar.notification;
18
19import static org.junit.Assert.assertNotSame;
20import static org.mockito.ArgumentMatchers.any;
21import static org.mockito.ArgumentMatchers.anyBoolean;
22import static org.mockito.ArgumentMatchers.anyInt;
23import static org.mockito.Mockito.spy;
24import static org.mockito.Mockito.verify;
25import static org.mockito.Mockito.verifyZeroInteractions;
26
27import android.app.Notification;
28import android.graphics.Bitmap;
29import android.graphics.drawable.Drawable;
Selim Cineka7679b62017-05-10 16:33:25 -070030import android.test.suitebuilder.annotation.SmallTest;
31import android.widget.RemoteViews;
32
Brett Chabot84151d92019-02-27 15:37:59 -080033import androidx.test.runner.AndroidJUnit4;
34
Selim Cineka7679b62017-05-10 16:33:25 -070035import com.android.systemui.R;
36import com.android.systemui.SysuiTestCase;
37
38import org.junit.Before;
39import org.junit.Test;
40import org.junit.runner.RunWith;
41
42@SmallTest
43@RunWith(AndroidJUnit4.class)
44public class MediaNotificationProcessorTest extends SysuiTestCase {
45
46 private MediaNotificationProcessor mProcessor;
47 private Bitmap mBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
48 private ImageGradientColorizer mColorizer;
49
50 @Before
51 public void setUp() {
52 mColorizer = spy(new TestableColorizer(mBitmap));
53 mProcessor = new MediaNotificationProcessor(getContext(), getContext(), mColorizer);
54 }
55
56 @Test
57 public void testColorizedWithLargeIcon() {
58 Notification.Builder builder = new Notification.Builder(getContext()).setSmallIcon(
59 R.drawable.ic_person)
60 .setContentTitle("Title")
61 .setLargeIcon(mBitmap)
62 .setContentText("Text");
63 Notification notification = builder.build();
64 mProcessor.processNotification(notification, builder);
65 verify(mColorizer).colorize(any(), anyInt(), anyBoolean());
66 }
67
68 @Test
69 public void testNotColorizedWithoutLargeIcon() {
70 Notification.Builder builder = new Notification.Builder(getContext()).setSmallIcon(
71 R.drawable.ic_person)
72 .setContentTitle("Title")
73 .setContentText("Text");
74 Notification notification = builder.build();
75 mProcessor.processNotification(notification, builder);
76 verifyZeroInteractions(mColorizer);
77 }
78
79 @Test
80 public void testRemoteViewsReset() {
81 Notification.Builder builder = new Notification.Builder(getContext()).setSmallIcon(
82 R.drawable.ic_person)
83 .setContentTitle("Title")
84 .setStyle(new Notification.MediaStyle())
85 .setLargeIcon(mBitmap)
86 .setContentText("Text");
87 Notification notification = builder.build();
88 RemoteViews remoteViews = new RemoteViews(getContext().getPackageName(),
89 R.layout.custom_view_dark);
90 notification.contentView = remoteViews;
91 notification.bigContentView = remoteViews;
92 notification.headsUpContentView = remoteViews;
93 mProcessor.processNotification(notification, builder);
94 verify(mColorizer).colorize(any(), anyInt(), anyBoolean());
95 RemoteViews contentView = builder.createContentView();
96 assertNotSame(contentView, remoteViews);
97 contentView = builder.createBigContentView();
98 assertNotSame(contentView, remoteViews);
99 contentView = builder.createHeadsUpContentView();
100 assertNotSame(contentView, remoteViews);
101 }
102
103 public static class TestableColorizer extends ImageGradientColorizer {
104 private final Bitmap mBitmap;
105
106 private TestableColorizer(Bitmap bitmap) {
107 mBitmap = bitmap;
108 }
109
110 @Override
111 public Bitmap colorize(Drawable drawable, int backgroundColor, boolean isRtl) {
112 return mBitmap;
113 }
114 }
115}