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