blob: db1e049dec9b2bfa869bef3720ad40f894eecdd2 [file] [log] [blame]
Tony Mak628cb932018-06-19 18:30:41 +01001/*
2 * Copyright 2018 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 */
16package com.android.systemui.statusbar;
17
18import static com.google.common.truth.Truth.assertThat;
19
20import android.app.Notification;
21import android.app.PendingIntent;
22import android.app.RemoteInput;
23import android.content.Intent;
24import android.graphics.drawable.Icon;
25import android.support.test.filters.SmallTest;
26
27import com.android.internal.R;
28import com.android.systemui.SysuiTestCase;
29
30import org.junit.Test;
31
32import java.util.Collections;
Tony Makc9acf672018-07-20 13:58:24 +020033import java.util.List;
Tony Mak628cb932018-06-19 18:30:41 +010034
35@SmallTest
36public class NotificationUiAdjustmentTest extends SysuiTestCase {
37
38 @Test
39 public void needReinflate_differentLength() {
40 PendingIntent pendingIntent =
41 PendingIntent.getActivity(mContext, 0, new Intent(), 0);
42 Notification.Action action =
43 createActionBuilder("first", R.drawable.ic_corp_icon, pendingIntent).build();
44 assertThat(NotificationUiAdjustment.needReinflate(
Tony Makc9acf672018-07-20 13:58:24 +020045 createUiAdjustmentFromSmartActions("first", Collections.emptyList()),
46 createUiAdjustmentFromSmartActions("second", Collections.singletonList(action))))
Tony Mak628cb932018-06-19 18:30:41 +010047 .isTrue();
48 }
49
50 @Test
51 public void needReinflate_differentLabels() {
52 PendingIntent pendingIntent =
53 PendingIntent.getActivity(mContext, 0, new Intent(), 0);
54 Notification.Action firstAction =
55 createActionBuilder("first", R.drawable.ic_corp_icon, pendingIntent).build();
56 Notification.Action secondAction =
57 createActionBuilder("second", R.drawable.ic_corp_icon, pendingIntent).build();
58
59 assertThat(NotificationUiAdjustment.needReinflate(
Tony Makc9acf672018-07-20 13:58:24 +020060 createUiAdjustmentFromSmartActions("first", Collections.singletonList(firstAction)),
61 createUiAdjustmentFromSmartActions("second", Collections.singletonList(secondAction))))
Tony Mak628cb932018-06-19 18:30:41 +010062 .isTrue();
63 }
64
65 @Test
66 public void needReinflate_differentIcons() {
67 PendingIntent pendingIntent =
68 PendingIntent.getActivity(mContext, 0, new Intent(), 0);
69 Notification.Action firstAction =
70 createActionBuilder("same", R.drawable.ic_corp_icon, pendingIntent).build();
71 Notification.Action secondAction =
72 createActionBuilder("same", R.drawable.ic_account_circle, pendingIntent)
73 .build();
74
75 assertThat(NotificationUiAdjustment.needReinflate(
Tony Makc9acf672018-07-20 13:58:24 +020076 createUiAdjustmentFromSmartActions("first", Collections.singletonList(firstAction)),
77 createUiAdjustmentFromSmartActions("second", Collections.singletonList(secondAction))))
Tony Mak628cb932018-06-19 18:30:41 +010078 .isTrue();
79 }
80
81 @Test
82 public void needReinflate_differentPendingIntent() {
83 PendingIntent firstPendingIntent =
84 PendingIntent.getActivity(mContext, 0, new Intent(Intent.ACTION_VIEW), 0);
85 PendingIntent secondPendingIntent =
86 PendingIntent.getActivity(mContext, 0, new Intent(Intent.ACTION_PROCESS_TEXT), 0);
87 Notification.Action firstAction =
88 createActionBuilder("same", R.drawable.ic_corp_icon, firstPendingIntent)
89 .build();
90 Notification.Action secondAction =
91 createActionBuilder("same", R.drawable.ic_corp_icon, secondPendingIntent)
92 .build();
93
94 assertThat(NotificationUiAdjustment.needReinflate(
Tony Makc9acf672018-07-20 13:58:24 +020095 createUiAdjustmentFromSmartActions("first", Collections.singletonList(firstAction)),
96 createUiAdjustmentFromSmartActions("second", Collections.singletonList(secondAction))))
Tony Mak628cb932018-06-19 18:30:41 +010097 .isTrue();
98 }
99
100 @Test
101 public void needReinflate_differentChoices() {
102 PendingIntent pendingIntent =
103 PendingIntent.getActivity(mContext, 0, new Intent(), 0);
104
105 RemoteInput firstRemoteInput =
106 createRemoteInput("same", "same", new CharSequence[] {"first"});
107 RemoteInput secondRemoteInput =
108 createRemoteInput("same", "same", new CharSequence[] {"second"});
109
110 Notification.Action firstAction =
111 createActionBuilder("same", R.drawable.ic_corp_icon, pendingIntent)
112 .addRemoteInput(firstRemoteInput)
113 .build();
114 Notification.Action secondAction =
115 createActionBuilder("same", R.drawable.ic_corp_icon, pendingIntent)
116 .addRemoteInput(secondRemoteInput)
117 .build();
118
119 assertThat(NotificationUiAdjustment.needReinflate(
Tony Makc9acf672018-07-20 13:58:24 +0200120 createUiAdjustmentFromSmartActions("first", Collections.singletonList(firstAction)),
121 createUiAdjustmentFromSmartActions("second", Collections.singletonList(secondAction))))
Tony Mak628cb932018-06-19 18:30:41 +0100122 .isTrue();
123 }
124
125 @Test
126 public void needReinflate_differentRemoteInputLabel() {
127 PendingIntent pendingIntent =
128 PendingIntent.getActivity(mContext, 0, new Intent(), 0);
129
130 RemoteInput firstRemoteInput =
131 createRemoteInput("same", "first", new CharSequence[] {"same"});
132 RemoteInput secondRemoteInput =
133 createRemoteInput("same", "second", new CharSequence[] {"same"});
134
135 Notification.Action firstAction =
136 createActionBuilder("same", R.drawable.ic_corp_icon, pendingIntent)
137 .addRemoteInput(firstRemoteInput)
138 .build();
139 Notification.Action secondAction =
140 createActionBuilder("same", R.drawable.ic_corp_icon, pendingIntent)
141 .addRemoteInput(secondRemoteInput)
142 .build();
143
144 assertThat(NotificationUiAdjustment.needReinflate(
Tony Makc9acf672018-07-20 13:58:24 +0200145 createUiAdjustmentFromSmartActions("first", Collections.singletonList(firstAction)),
146 createUiAdjustmentFromSmartActions("second", Collections.singletonList(secondAction))))
Tony Mak628cb932018-06-19 18:30:41 +0100147 .isTrue();
148 }
149
150 @Test
151 public void needReinflate_negative() {
152 PendingIntent pendingIntent =
153 PendingIntent.getActivity(mContext, 0, new Intent(), 0);
154 RemoteInput firstRemoteInput =
155 createRemoteInput("same", "same", new CharSequence[] {"same"});
156 RemoteInput secondRemoteInput =
157 createRemoteInput("same", "same", new CharSequence[] {"same"});
158
159 Notification.Action firstAction =
160 createActionBuilder("same", R.drawable.ic_corp_icon, pendingIntent)
161 .addRemoteInput(firstRemoteInput).build();
162 Notification.Action secondAction =
163 createActionBuilder("same", R.drawable.ic_corp_icon, pendingIntent)
164 .addRemoteInput(secondRemoteInput).build();
165
166 assertThat(NotificationUiAdjustment.needReinflate(
Tony Makc9acf672018-07-20 13:58:24 +0200167 createUiAdjustmentFromSmartActions("first", Collections.singletonList(firstAction)),
168 createUiAdjustmentFromSmartActions(
169 "second", Collections.singletonList(secondAction))))
170 .isFalse();
171 }
172
173 @Test
174 public void needReinflate_differentSmartReplies() {
175 assertThat(NotificationUiAdjustment.needReinflate(
176 createUiAdjustmentFromSmartReplies("first", new CharSequence[]{"a", "b"}),
177 createUiAdjustmentFromSmartReplies("first", new CharSequence[] {"b", "a"})))
178 .isTrue();
179 }
180
181 @Test
182 public void needReinflate_sameSmartReplies() {
183 assertThat(NotificationUiAdjustment.needReinflate(
184 createUiAdjustmentFromSmartReplies("first", new CharSequence[] {"a", "b"}),
185 createUiAdjustmentFromSmartReplies("first", new CharSequence[] {"a", "b"})))
Tony Mak628cb932018-06-19 18:30:41 +0100186 .isFalse();
187 }
188
189 private Notification.Action.Builder createActionBuilder(
190 String title, int drawableRes, PendingIntent pendingIntent) {
191 return new Notification.Action.Builder(
192 Icon.createWithResource(mContext, drawableRes), title, pendingIntent);
193 }
194
195 private RemoteInput createRemoteInput(String resultKey, String label, CharSequence[] choices) {
196 return new RemoteInput.Builder(resultKey).setLabel(label).setChoices(choices).build();
197 }
Tony Makc9acf672018-07-20 13:58:24 +0200198
199 private NotificationUiAdjustment createUiAdjustmentFromSmartActions(
200 String key, List<Notification.Action> actions) {
201 return new NotificationUiAdjustment(key, actions, new CharSequence[0]);
202 }
203
204 private NotificationUiAdjustment createUiAdjustmentFromSmartReplies(
205 String key, CharSequence[] replies) {
206 return new NotificationUiAdjustment(key, Collections.emptyList(), replies);
207 }
Tony Mak628cb932018-06-19 18:30:41 +0100208}