use of com.onesignal.ShadowRoboNotificationManager.PostedNotification in project OneSignal-Android-SDK by OneSignal.
the class GenerateNotificationRunner method shouldSetCorrectNumberOfButtonsOnSummaryNotification.
@Test
public void shouldSetCorrectNumberOfButtonsOnSummaryNotification() throws Exception {
// Setup - Init
OneSignal.setInFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification);
OneSignal.init(blankActivity, "123456789", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
threadAndTaskWait();
// Setup - Display a single notification with a grouped.
Bundle bundle = getBaseNotifBundle("UUID1");
bundle.putString("grp", "test1");
bundle.putString("custom", "{\"i\": \"some_UUID\", \"a\": {\"actionButtons\": [{\"text\": \"test\"} ]}}");
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
Iterator<Map.Entry<Integer, PostedNotification>> postedNotifsIterator = postedNotifs.entrySet().iterator();
PostedNotification postedSummaryNotification = postedNotifsIterator.next().getValue();
Assert.assertEquals(Notification.FLAG_GROUP_SUMMARY, postedSummaryNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY);
Assert.assertEquals(1, postedSummaryNotification.notif.actions.length);
}
use of com.onesignal.ShadowRoboNotificationManager.PostedNotification in project OneSignal-Android-SDK by OneSignal.
the class GenerateNotificationRunner method shouldUpdateBadgesWhenDismissingNotification.
@Test
public void shouldUpdateBadgesWhenDismissingNotification() {
Bundle bundle = getBaseNotifBundle();
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
Assert.assertEquals(notifMessage, ShadowRoboNotificationManager.getLastShadowNotif().getContentText());
Assert.assertEquals(1, ShadowBadgeCountUpdater.lastCount);
Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
Iterator<Map.Entry<Integer, PostedNotification>> postedNotifsIterator = postedNotifs.entrySet().iterator();
PostedNotification postedNotification = postedNotifsIterator.next().getValue();
Intent intent = Shadows.shadowOf(postedNotification.notif.deleteIntent).getSavedIntent();
NotificationOpenedProcessor_processFromContext(blankActivity, intent);
Assert.assertEquals(0, ShadowBadgeCountUpdater.lastCount);
}
use of com.onesignal.ShadowRoboNotificationManager.PostedNotification in project OneSignal-Android-SDK by OneSignal.
the class GenerateNotificationRunner method shouldUpdateNormalNotificationDisplayWhenReplacingANotification.
@Test
public void shouldUpdateNormalNotificationDisplayWhenReplacingANotification() throws Exception {
// Setup - init
OneSignal.setInFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification);
OneSignal.init(blankActivity, "123456789", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
threadAndTaskWait();
// Setup - Display 2 notifications with the same group and collapse_id
Bundle bundle = getBaseNotifBundle("UUID1");
bundle.putString("grp", "test1");
bundle.putString("collapse_key", "1");
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
bundle = getBaseNotifBundle("UUID2");
bundle.putString("grp", "test1");
bundle.putString("collapse_key", "1");
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
// Test - Summary created and sub notification. Summary will look the same as the normal notification.
Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
Iterator<Map.Entry<Integer, PostedNotification>> postedNotifsIterator = postedNotifs.entrySet().iterator();
Assert.assertEquals(2, postedNotifs.size());
PostedNotification postedSummaryNotification = postedNotifsIterator.next().getValue();
Assert.assertEquals(notifMessage, postedSummaryNotification.getShadow().getContentText());
Assert.assertEquals(Notification.FLAG_GROUP_SUMMARY, postedSummaryNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY);
int lastNotifId = postedNotifsIterator.next().getValue().id;
ShadowRoboNotificationManager.notifications.clear();
// Setup - Restore
bundle = getBaseNotifBundle("UUID2");
bundle.putString("grp", "test1");
bundle = createInternalPayloadBundle(bundle);
bundle.putInt("android_notif_id", lastNotifId);
bundle.putBoolean("restoring", true);
NotificationBundleProcessor_ProcessFromGCMIntentService_NoWrap(blankActivity, bundle, null);
// Test - Restored notifications display exactly the same as they did when recevied.
postedNotifs = ShadowRoboNotificationManager.notifications;
postedNotifsIterator = postedNotifs.entrySet().iterator();
// Test - 1 notifi + 1 summary
Assert.assertEquals(2, postedNotifs.size());
Assert.assertEquals(notifMessage, postedSummaryNotification.getShadow().getContentText());
Assert.assertEquals(Notification.FLAG_GROUP_SUMMARY, postedSummaryNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY);
}
use of com.onesignal.ShadowRoboNotificationManager.PostedNotification in project OneSignal-Android-SDK by OneSignal.
the class GenerateNotificationRunner method shouldContainPayloadWhenOldSummaryNotificationIsOpened.
@Test
public void shouldContainPayloadWhenOldSummaryNotificationIsOpened() throws Exception {
OneSignal.setInFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification);
OneSignal.init(blankActivity, "123456789", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba", new OneSignal.NotificationOpenedHandler() {
@Override
public void notificationOpened(OSNotificationOpenResult result) {
lastOpenResult = result;
}
});
// Display 2 notifications that will be grouped together.
Bundle bundle = getBaseNotifBundle("UUID1");
bundle.putString("grp", "test1");
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
bundle = getBaseNotifBundle("UUID2");
bundle.putString("grp", "test1");
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
// Go forward 4 weeks
ShadowSystemClock.setCurrentTimeMillis(System.currentTimeMillis() + 2419202L * 1000L);
// Display a 3 normal notification.
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, getBaseNotifBundle("UUID3"), null);
Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
// Open the summary notification
Iterator<Map.Entry<Integer, PostedNotification>> postedNotifsIterator = postedNotifs.entrySet().iterator();
PostedNotification postedNotification = postedNotifsIterator.next().getValue();
Intent intent = Shadows.shadowOf(postedNotification.notif.contentIntent).getSavedIntent();
NotificationOpenedProcessor_processFromContext(blankActivity, intent);
// Make sure we get a payload when it is opened.
Assert.assertNotNull(lastOpenResult.notification.payload);
}
use of com.onesignal.ShadowRoboNotificationManager.PostedNotification in project OneSignal-Android-SDK by OneSignal.
the class GenerateNotificationRunner method shouldFireNotificationExtenderService.
@Test
@Config(shadows = { ShadowOneSignal.class })
public void shouldFireNotificationExtenderService() throws Exception {
// Test that GCM receiver starts the NotificationExtenderServiceTest when it is in the AndroidManifest.xml
Bundle bundle = getBaseNotifBundle();
Intent serviceIntent = new Intent();
serviceIntent.setPackage("com.onesignal.example");
serviceIntent.setAction("com.onesignal.NotificationExtender");
ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.serviceInfo = new ServiceInfo();
resolveInfo.serviceInfo.name = "com.onesignal.example.NotificationExtenderServiceTest";
RuntimeEnvironment.getRobolectricPackageManager().addResolveInfoForIntent(serviceIntent, resolveInfo);
boolean ret = OneSignalPackagePrivateHelper.GcmBroadcastReceiver_processBundle(blankActivity, bundle);
Assert.assertTrue(ret);
Intent intent = Shadows.shadowOf(blankActivity).getNextStartedService();
Assert.assertEquals("com.onesignal.NotificationExtender", intent.getAction());
// Test that all options are set.
NotificationExtenderServiceTest service = startNotificationExtender(createInternalPayloadBundle(getBundleWithAllOptionsSet()), NotificationExtenderServiceTest.class);
OSNotificationReceivedResult notificationReceived = service.notification;
OSNotificationPayload notificationPayload = notificationReceived.payload;
Assert.assertEquals("Test H", notificationPayload.title);
Assert.assertEquals("Test B", notificationPayload.body);
Assert.assertEquals("9764eaeb-10ce-45b1-a66d-8f95938aaa51", notificationPayload.notificationID);
Assert.assertEquals(0, notificationPayload.lockScreenVisibility);
Assert.assertEquals("FF0000FF", notificationPayload.smallIconAccentColor);
Assert.assertEquals("703322744261", notificationPayload.fromProjectNumber);
Assert.assertEquals("FFFFFF00", notificationPayload.ledColor);
Assert.assertEquals("big_picture", notificationPayload.bigPicture);
Assert.assertEquals("large_icon", notificationPayload.largeIcon);
Assert.assertEquals("small_icon", notificationPayload.smallIcon);
Assert.assertEquals("test_sound", notificationPayload.sound);
Assert.assertEquals("You test $[notif_count] MSGs!", notificationPayload.groupMessage);
Assert.assertEquals("http://google.com", notificationPayload.launchURL);
Assert.assertEquals(10, notificationPayload.priority);
Assert.assertEquals("a_key", notificationPayload.collapseId);
Assert.assertEquals("id1", notificationPayload.actionButtons.get(0).id);
Assert.assertEquals("button1", notificationPayload.actionButtons.get(0).text);
Assert.assertEquals("ic_menu_share", notificationPayload.actionButtons.get(0).icon);
Assert.assertEquals("id2", notificationPayload.actionButtons.get(1).id);
Assert.assertEquals("button2", notificationPayload.actionButtons.get(1).text);
Assert.assertEquals("ic_menu_send", notificationPayload.actionButtons.get(1).icon);
Assert.assertEquals("test_image_url", notificationPayload.backgroundImageLayout.image);
Assert.assertEquals("FF000000", notificationPayload.backgroundImageLayout.titleTextColor);
Assert.assertEquals("FFFFFFFF", notificationPayload.backgroundImageLayout.bodyTextColor);
JSONObject additionalData = notificationPayload.additionalData;
Assert.assertEquals("myValue", additionalData.getString("myKey"));
Assert.assertEquals("nValue", additionalData.getJSONObject("nested").getString("nKey"));
Assert.assertNotSame(-1, service.notificationId);
// Test a basic notification without anything special.
startNotificationExtender(createInternalPayloadBundle(getBaseNotifBundle()), NotificationExtenderServiceTest.class);
Assert.assertFalse(ShadowOneSignal.messages.contains("Error assigning"));
// Test that a notification is still displayed if the developer's code in onNotificationProcessing throws an Exception.
NotificationExtenderServiceTest.throwInAppCode = true;
startNotificationExtender(createInternalPayloadBundle(getBaseNotifBundle("NewUUID1")), NotificationExtenderServiceTest.class);
Assert.assertTrue(ShadowOneSignal.messages.contains("onNotificationProcessing throw an exception"));
Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
Assert.assertEquals(3, postedNotifs.size());
}
Aggregations