use of com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withBundle in project OneSignal-Android-SDK by OneSignal.
the class OutcomeEventIntegrationTests method testIndirectSessionNotificationsUpdated_onNewIndirectSession.
@Test
@Config(shadows = { ShadowGenerateNotification.class })
public void testIndirectSessionNotificationsUpdated_onNewIndirectSession() throws Exception {
foregroundAppAfterReceivingNotification();
// Make sure indirectNotificationIds are correct
JSONArray indirectNotificationIds = new JSONArray().put(ONESIGNAL_NOTIFICATION_ID + "1");
assertEquals(indirectNotificationIds, trackerFactory.getNotificationChannelTracker().getIndirectIds());
// Background app
pauseActivity(blankActivityController);
// Receive notification
Bundle bundle = getBaseNotifBundle(ONESIGNAL_NOTIFICATION_ID + "2");
FCMBroadcastReceiver_onReceived_withBundle(blankActivity, bundle);
indirectNotificationIds.put(ONESIGNAL_NOTIFICATION_ID + "2");
// App in background for 31 seconds to trigger new session
time.advanceSystemTimeBy(31);
// Foreground app through icon
blankActivityController.resume();
threadAndTaskWait();
// Make sure indirectNotificationIds are updated and correct
assertEquals(indirectNotificationIds, trackerFactory.getNotificationChannelTracker().getIndirectIds());
// Make sure session is ending
assertEquals(1, lastInfluencesEnding.size());
assertEquals(OSInfluenceChannel.NOTIFICATION, lastInfluencesEnding.get(0).getInfluenceChannel());
assertEquals(OSInfluenceType.INDIRECT, 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 testIndirectSession_wontOverrideIndirectSession_beforeNewSession.
@Test
@Config(shadows = { ShadowGenerateNotification.class })
public void testIndirectSession_wontOverrideIndirectSession_beforeNewSession() throws Exception {
foregroundAppAfterReceivingNotification();
// Background app
pauseActivity(blankActivityController);
// Receive another 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 indirectNotificationIds are correct
JSONArray indirectNotificationIds = new JSONArray().put(ONESIGNAL_NOTIFICATION_ID + "1");
assertEquals(indirectNotificationIds, trackerFactory.getNotificationChannelTracker().getIndirectIds());
// Make sure session is INDIRECT
assertNotificationChannelIndirectInfluence(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 testOnV2UniqueOutcomeMeasureOnlySentOncePerNotification_whenSendingMultipleUniqueOutcomes_inIndirectSessions.
@Test
@Config(shadows = { ShadowGenerateNotification.class })
public void testOnV2UniqueOutcomeMeasureOnlySentOncePerNotification_whenSendingMultipleUniqueOutcomes_inIndirectSessions() throws Exception {
// Enable IAM v2
preferences = new MockOSSharedPreferences();
trackerFactory = new OSTrackerFactory(preferences, logger, time);
sessionManager = new MockSessionManager(sessionListener, trackerFactory, logger);
preferences.saveBool(preferences.getPreferencesName(), preferences.getOutcomesV2KeyName(), true);
OneSignal_setSharedPreferences(preferences);
foregroundAppAfterReceivingNotification();
// Check notificationIds equal indirectNotificationIds from OSSessionManager
JSONArray notificationIds = new JSONArray().put(ONESIGNAL_NOTIFICATION_ID + "1");
assertEquals(notificationIds, trackerFactory.getNotificationChannelTracker().getIndirectIds());
// Make sure session is INDIRECT
assertNotificationChannelIndirectInfluence(1);
// Send unique outcome event
OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
threadAndTaskWait();
// Check measure end point was most recent request and contains received notification
assertMeasureOnV2AtIndex(2, ONESIGNAL_OUTCOME_NAME, null, null, new JSONArray(), notificationIds);
// Only 3 requests have been made
assertRestCalls(3);
// Send unique outcome event
OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
threadAndTaskWait();
// Make still only 3 requests have been made
assertRestCalls(3);
// Background app
pauseActivity(blankActivityController);
// Receive notification
Bundle bundle = getBaseNotifBundle(ONESIGNAL_NOTIFICATION_ID + "2");
FCMBroadcastReceiver_onReceived_withBundle(blankActivity, bundle);
// Wait 31 seconds to start new session
time.advanceSystemTimeBy(31);
// Foreground app will start a new session upgrade
blankActivityController.resume();
threadAndTaskWait();
// Send unique outcome event
OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
threadAndTaskWait();
// Check notificationIds are not equal indirectNotificationIds from OSSessionManager
notificationIds.put(ONESIGNAL_NOTIFICATION_ID + "2");
assertEquals(notificationIds, trackerFactory.getNotificationChannelTracker().getIndirectIds());
// Make sure session is INDIRECT
assertNotificationChannelIndirectInfluence(2);
// Check measure end point was most recent request and contains received notification
assertMeasureOnV2AtIndex(4, ONESIGNAL_OUTCOME_NAME, null, null, new JSONArray(), new JSONArray().put(ONESIGNAL_NOTIFICATION_ID + "2"));
}
use of com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withBundle in project OneSignal-Android-SDK by OneSignal.
the class OutcomeEventIntegrationTests method testUniqueOutcomeMeasureOnlySentOncePerNotification_whenSendingMultipleUniqueOutcomes_inIndirectSessions.
@Test
@Config(shadows = { ShadowGenerateNotification.class })
public void testUniqueOutcomeMeasureOnlySentOncePerNotification_whenSendingMultipleUniqueOutcomes_inIndirectSessions() throws Exception {
foregroundAppAfterReceivingNotification();
// Check notificationIds equal indirectNotificationIds from OSSessionManager
JSONArray notificationIds = new JSONArray().put(ONESIGNAL_NOTIFICATION_ID + "1");
assertEquals(notificationIds, trackerFactory.getNotificationChannelTracker().getIndirectIds());
// Make sure session is INDIRECT
assertNotificationChannelIndirectInfluence(1);
// Send unique outcome event
OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
threadAndTaskWait();
// Check measure end point was most recent request and contains received notification
assertMeasureAtIndex(2, false, ONESIGNAL_OUTCOME_NAME, new JSONArray().put(ONESIGNAL_NOTIFICATION_ID + "1"));
// Only 3 requests have been made
assertRestCalls(3);
// Send unique outcome event
OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
threadAndTaskWait();
// Make still only 3 requests have been made
assertRestCalls(3);
// Background app
pauseActivity(blankActivityController);
// Receive notification
Bundle bundle = getBaseNotifBundle(ONESIGNAL_NOTIFICATION_ID + "2");
FCMBroadcastReceiver_onReceived_withBundle(blankActivity, bundle);
// Wait 31 seconds to start new session
time.advanceSystemTimeBy(31);
// Foreground app will start a new session upgrade
blankActivityController.resume();
threadAndTaskWait();
// Send unique outcome event
OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
threadAndTaskWait();
// Check notificationIds are not equal indirectNotificationIds from OSSessionManager
notificationIds.put(ONESIGNAL_NOTIFICATION_ID + "2");
assertEquals(notificationIds, trackerFactory.getNotificationChannelTracker().getIndirectIds());
// Make sure session is INDIRECT
assertNotificationChannelIndirectInfluence(2);
// Check measure end point was most recent request and contains received notification
assertMeasureAtIndex(4, false, ONESIGNAL_OUTCOME_NAME, new JSONArray().put(ONESIGNAL_NOTIFICATION_ID + "2"));
}
Aggregations