summaryrefslogtreecommitdiffstats
path: root/services/tests
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2014-07-17 17:08:53 -0400
committerChris Wren <cwren@android.com>2014-07-23 10:36:57 +0000
commit4a24fd3c7bab53e4e9c127214e7168db0af8800a (patch)
tree697b76542e4966ba05e8b2cd030bf7b7b82d4f2f /services/tests
parent0c434aed47faf396caef06b146355565b0e778c2 (diff)
downloadframeworks_base-4a24fd3c7bab53e4e9c127214e7168db0af8800a.zip
frameworks_base-4a24fd3c7bab53e4e9c127214e7168db0af8800a.tar.gz
frameworks_base-4a24fd3c7bab53e4e9c127214e7168db0af8800a.tar.bz2
Honor the sort and group keys for notification ranking.
Sort notifications naturally, then move group childen to be next their proxy. The group proxy is the summary, or if no summary exists, the lowest-ranked member of the group is chosen as the proxy. Notifications with a sortKey but no group and placed into a synthetic group that consists of all notifications from that package and user in the same priority bucket that also have sortKeys. Bug: 15190903 Change-Id: I377ed65b9592079446da4a4189f5ab49d28630ec
Diffstat (limited to 'services/tests')
-rw-r--r--services/tests/servicestests/src/com/android/server/notification/RankingHelperTest.java136
1 files changed, 136 insertions, 0 deletions
diff --git a/services/tests/servicestests/src/com/android/server/notification/RankingHelperTest.java b/services/tests/servicestests/src/com/android/server/notification/RankingHelperTest.java
new file mode 100644
index 0000000..3cc04e8
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/notification/RankingHelperTest.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.server.notification;
+
+import android.app.Notification;
+import android.os.UserHandle;
+import android.service.notification.StatusBarNotification;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import java.util.ArrayList;
+
+public class RankingHelperTest extends AndroidTestCase {
+
+ private Notification mNotiGroupGSortA;
+ private Notification mNotiGroupGSortB;
+ private Notification mNotiNoGroup;
+ private Notification mNotiNoGroup2;
+ private Notification mNotiNoGroupSortA;
+ private NotificationRecord mRecordGroupGSortA;
+ private NotificationRecord mRecordGroupGSortB;
+ private NotificationRecord mRecordNoGroup;
+ private NotificationRecord mRecordNoGroup2;
+ private NotificationRecord mRecordNoGroupSortA;
+ private RankingHelper mHelper;
+
+ @Override
+ public void setUp() {
+ UserHandle user = UserHandle.ALL;
+
+ mHelper = new RankingHelper(getContext(), null, new String[0]);
+
+ mNotiGroupGSortA = new Notification.Builder(getContext())
+ .setContentTitle("A")
+ .setGroup("G")
+ .setSortKey("A")
+ .setWhen(1205)
+ .build();
+ mRecordGroupGSortA = new NotificationRecord(new StatusBarNotification(
+ "package", "package", 1, null, 0, 0, 0, mNotiGroupGSortA, user), 0);
+
+ mNotiGroupGSortB = new Notification.Builder(getContext())
+ .setContentTitle("B")
+ .setGroup("G")
+ .setSortKey("B")
+ .setWhen(1200)
+ .build();
+ mRecordGroupGSortB = new NotificationRecord(new StatusBarNotification(
+ "package", "package", 1, null, 0, 0, 0, mNotiGroupGSortB, user), 0);
+
+ mNotiNoGroup = new Notification.Builder(getContext())
+ .setContentTitle("C")
+ .setWhen(1201)
+ .build();
+ mRecordNoGroup = new NotificationRecord(new StatusBarNotification(
+ "package", "package", 1, null, 0, 0, 0, mNotiNoGroup, user), 0);
+
+ mNotiNoGroup2 = new Notification.Builder(getContext())
+ .setContentTitle("D")
+ .setWhen(1202)
+ .build();
+ mRecordNoGroup2 = new NotificationRecord(new StatusBarNotification(
+ "package", "package", 1, null, 0, 0, 0, mNotiNoGroup2, user), 0);
+
+ mNotiNoGroupSortA = new Notification.Builder(getContext())
+ .setContentTitle("E")
+ .setWhen(1201)
+ .setSortKey("A")
+ .build();
+ mRecordNoGroupSortA = new NotificationRecord(new StatusBarNotification(
+ "package", "package", 1, null, 0, 0, 0, mNotiNoGroupSortA, user), 0);
+ }
+
+ @SmallTest
+ public void testFindAfterRankingWithASplitGroup() throws Exception {
+ ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(3);
+ notificationList.add(mRecordGroupGSortA);
+ notificationList.add(mRecordGroupGSortB);
+ notificationList.add(mRecordNoGroup);
+ notificationList.add(mRecordNoGroupSortA);
+ mHelper.sort(notificationList);
+ assertTrue(mHelper.indexOf(notificationList, mRecordGroupGSortA) >= 0);
+ assertTrue(mHelper.indexOf(notificationList, mRecordGroupGSortB) >= 0);
+ assertTrue(mHelper.indexOf(notificationList, mRecordNoGroup) >= 0);
+ assertTrue(mHelper.indexOf(notificationList, mRecordNoGroupSortA) >= 0);
+ }
+
+ @SmallTest
+ public void testSortShouldNotThrowWithPlainNotifications() throws Exception {
+ ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(2);
+ notificationList.add(mRecordNoGroup);
+ notificationList.add(mRecordNoGroup2);
+ mHelper.sort(notificationList);
+ }
+
+ @SmallTest
+ public void testSortShouldNotThrowOneSorted() throws Exception {
+ ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(2);
+ notificationList.add(mRecordNoGroup);
+ notificationList.add(mRecordNoGroupSortA);
+ mHelper.sort(notificationList);
+ }
+
+ @SmallTest
+ public void testSortShouldNotThrowOneNotification() throws Exception {
+ ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(1);
+ notificationList.add(mRecordNoGroup);
+ mHelper.sort(notificationList);
+ }
+
+ @SmallTest
+ public void testSortShouldNotThrowOneSortKey() throws Exception {
+ ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(1);
+ notificationList.add(mRecordGroupGSortB);
+ mHelper.sort(notificationList);
+ }
+
+ @SmallTest
+ public void testSortShouldNotThrowOnEmptyList() throws Exception {
+ ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>();
+ mHelper.sort(notificationList);
+ }
+}