use of com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withBundle in project OneSignal-Android-SDK by OneSignal.
the class OutcomeEventIntegrationTests method testIndirectSession_wontOverrideDirectSession_beforeNewSession.
@Test
public void testIndirectSession_wontOverrideDirectSession_beforeNewSession() throws Exception {
foregroundAppAfterClickingNotification();
// Background app
pauseActivity(blankActivityController);
// Receive notification
Bundle bundle = getBaseNotifBundle(ONESIGNAL_NOTIFICATION_ID + "2");
FCMBroadcastReceiver_onReceived_withBundle(blankActivity, bundle);
// Foreground app through icon before new session
blankActivityController.resume();
threadAndTaskWait();
// Make sure no indirectNotificationIds exist
assertNull(trackerFactory.getNotificationChannelTracker().getIndirectIds());
// Check directNotificationId is set to clicked notification
assertEquals(ONESIGNAL_NOTIFICATION_ID + "1", trackerFactory.getNotificationChannelTracker().getDirectId());
// Make sure session is DIRECT
assertNotificationChannelDirectInfluence(ONESIGNAL_NOTIFICATION_ID + "1");
// Make sure no session is ending
assertNull(lastInfluencesEnding);
}
use of com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withBundle in project OneSignal-Android-SDK by OneSignal.
the class OutcomeEventIntegrationTests method testIndirectSession_wontOverrideUnattributedSession_fromNotificationReceived_whenAppIsInForeground.
@Test
public void testIndirectSession_wontOverrideUnattributedSession_fromNotificationReceived_whenAppIsInForeground() throws Exception {
OneSignalInit();
threadAndTaskWait();
// Make sure session is unattributed
assertNotificationChannelUnattributedInfluence();
assertIAMChannelUnattributedInfluence();
// Receive notification
Bundle bundle = getBaseNotifBundle(ONESIGNAL_NOTIFICATION_ID);
FCMBroadcastReceiver_onReceived_withBundle(blankActivity, bundle);
// Make sure notification influence is not INDIRECT
assertFalse(trackerFactory.getNotificationChannelTracker().getInfluenceType().isIndirect());
// Make sure not indirect notifications exist
assertNull(trackerFactory.getNotificationChannelTracker().getIndirectIds());
// Make sure not session is ending
assertNull(lastInfluencesEnding);
}
use of com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withBundle in project OneSignal-Android-SDK by OneSignal.
the class OutcomeEventIntegrationTests method testCleaningCachedNotifications_after7Days_willAlsoCleanUniqueOutcomeNotifications.
@Test
@Config(shadows = { ShadowGenerateNotification.class })
public void testCleaningCachedNotifications_after7Days_willAlsoCleanUniqueOutcomeNotifications() throws Exception {
foregroundAppAfterReceivingNotification();
assertEquals(1, getAllNotificationRecords(dbHelper).size());
assertEquals(0, getAllUniqueOutcomeNotificationRecordsDB(dbHelper).size());
// Should add a new unique outcome notifications (total in cache = 0 + 1)
OneSignal.sendUniqueOutcome("unique_1");
threadAndTaskWait();
// Should not add a new unique outcome notifications (total in cache = 1)
OneSignal.sendUniqueOutcome("unique_1");
threadAndTaskWait();
assertEquals(1, getAllNotificationRecords(dbHelper).size());
assertEquals(1, getAllUniqueOutcomeNotificationRecordsDB(dbHelper).size());
// Background app
pauseActivity(blankActivityController);
// Wait for 30 seconds to trigger new session
time.advanceSystemTimeBy(31);
// Receive notification
Bundle bundle = getBaseNotifBundle(ONESIGNAL_NOTIFICATION_ID + "2");
FCMBroadcastReceiver_onReceived_withBundle(blankActivity, bundle);
// Foreground app through icon
blankActivityController.resume();
threadAndTaskWait();
// Should add two unique outcome notifications (total in cache = 1 + 2)
OneSignal.sendUniqueOutcome("unique_2");
threadAndTaskWait();
// Should add two unique outcome notifications (total in cache = 3 + 2)
OneSignal.sendUniqueOutcome("unique_3");
threadAndTaskWait();
// Make sure only 2 notifications exist still, but 5 unique outcome notifications exist
assertEquals(2, getAllNotificationRecords(dbHelper).size());
assertEquals(5, getAllUniqueOutcomeNotificationRecordsDB(dbHelper).size());
// Wait a week to clear cached notifications
time.advanceSystemTimeBy(604_800);
// Restart the app and re-init OneSignal
fastColdRestartApp();
OneSignalInit();
threadAndTaskWait();
// Make sure when notification cache is cleaned so is the unique outcome events cache
assertEquals(0, getAllNotificationRecords(dbHelper).size());
assertEquals(0, getAllUniqueOutcomeNotificationRecordsDB(dbHelper).size());
}
use of com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withBundle in project OneSignal-Android-SDK by OneSignal.
the class OutcomeEventIntegrationTests method testIndirectSession_fromDirectSession_afterNewSession.
@Test
@Config(shadows = { ShadowGenerateNotification.class })
public void testIndirectSession_fromDirectSession_afterNewSession() throws Exception {
foregroundAppAfterClickingNotification();
// Background app
pauseActivity(blankActivityController);
// Receive notification
Bundle bundle = getBaseNotifBundle(ONESIGNAL_NOTIFICATION_ID + "2");
FCMBroadcastReceiver_onReceived_withBundle(blankActivity, bundle);
// Wait 31 seconds
time.advanceSystemTimeBy(31);
// Foreground app through icon before new session
blankActivityController.resume();
threadAndTaskWait();
// Check on_session is triggered
assertTrue(ShadowOneSignalRestClient.lastUrl.matches("players/.*/on_session"));
// Make sure no directNotificationId exist
assertNull(trackerFactory.getNotificationChannelTracker().getDirectId());
// Make sure indirectNotificationIds are correct
assertEquals(new JSONArray().put(ONESIGNAL_NOTIFICATION_ID + "1").put(ONESIGNAL_NOTIFICATION_ID + "2"), trackerFactory.getNotificationChannelTracker().getIndirectIds());
// Make sure session is INDIRECT
assertNotificationChannelIndirectInfluence(2);
// Make sure session is ending
assertEquals(1, lastInfluencesEnding.size());
assertEquals(OSInfluenceChannel.NOTIFICATION, lastInfluencesEnding.get(0).getInfluenceChannel());
assertEquals(OSInfluenceType.DIRECT, lastInfluencesEnding.get(0).getInfluenceType());
assertEquals(1, lastInfluencesEnding.get(0).getIds().length());
assertEquals(ONESIGNAL_NOTIFICATION_ID + "1", lastInfluencesEnding.get(0).getIds().get(0));
}
use of com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withBundle in project OneSignal-Android-SDK by OneSignal.
the class OutcomeEventIntegrationTests method foregroundAppAfterReceivingNotification.
private void foregroundAppAfterReceivingNotification() throws Exception {
OneSignalInit();
threadAndTaskWait();
// Make sure all influences are UNATTRIBUTED
List<OSInfluence> influences = sessionManager.getInfluences();
for (OSInfluence influence : influences) {
assertTrue(influence.getInfluenceType().isUnattributed());
}
// Background app
pauseActivity(blankActivityController);
String notificationID = ONESIGNAL_NOTIFICATION_ID + "1";
// Receive notification
Bundle bundle = getBaseNotifBundle(ONESIGNAL_NOTIFICATION_ID + "1");
FCMBroadcastReceiver_onReceived_withBundle(blankActivity, bundle);
// Check notification was saved
assertEquals(1, trackerFactory.getNotificationChannelTracker().getLastReceivedIds().length());
assertEquals(notificationID, trackerFactory.getNotificationChannelTracker().getLastReceivedIds().get(0));
// Foreground app through icon
blankActivityController.resume();
threadAndTaskWait();
// Upgrade on influence will end unattributed session
assertEquals(1, lastInfluencesEnding.size());
for (OSInfluence influence : lastInfluencesEnding) {
assertEquals(OSInfluenceType.UNATTRIBUTED, influence.getInfluenceType());
}
// Reset for upcoming asserts
lastInfluencesEnding = null;
}
Aggregations