use of com.onesignal.influence.domain.OSInfluence in project OneSignal-Android-SDK by OneSignal.
the class OutcomeEventIntegrationTests method assertNotificationChannelUnattributedInfluence.
private void assertNotificationChannelUnattributedInfluence() {
OSInfluence influence = trackerFactory.getNotificationChannelTracker().getCurrentSessionInfluence();
assertTrue(influence.getInfluenceType().isUnattributed());
assertNull(influence.getIds());
}
use of com.onesignal.influence.domain.OSInfluence in project OneSignal-Android-SDK by OneSignal.
the class OutcomeEventIntegrationTests method assertNotificationChannelDirectInfluence.
private void assertNotificationChannelDirectInfluence(String id) throws JSONException {
OSInfluence influence = trackerFactory.getNotificationChannelTracker().getCurrentSessionInfluence();
assertTrue(influence.getInfluenceType().isDirect());
assertEquals(1, influence.getIds().length());
assertEquals(id, influence.getIds().get(0));
}
use of com.onesignal.influence.domain.OSInfluence in project OneSignal-Android-SDK by OneSignal.
the class OutcomeEventIntegrationTests method testDirectSession_fromNotificationClick_OpenHandleByUser_NewSession_whenAppIsInBackground.
@Test
@Config(shadows = { OneSignalShadowPackageManager.class })
public void testDirectSession_fromNotificationClick_OpenHandleByUser_NewSession_whenAppIsInBackground() throws Exception {
OneSignalInit();
threadAndTaskWait();
OneSignalShadowPackageManager.addManifestMetaData("com.onesignal.NotificationOpened.DEFAULT", "DISABLE");
OneSignal.setNotificationOpenedHandler(result -> {
OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "OSNotificationOpenedHandler called with result: " + result);
notificationOpenedResult = result;
// App opened after clicking notification, but Robolectric needs this to simulate onAppFocus() code after a click
blankActivityController.resume();
});
// Background app
pauseActivity(blankActivityController);
String notificationID = ONESIGNAL_NOTIFICATION_ID + "1";
sessionManager.onNotificationReceived(notificationID);
time.advanceSystemAndElapsedTimeBy(61);
// Click notification before new session
OneSignal_handleNotificationOpen(blankActivity, new JSONArray("[{ \"alert\": \"Test Msg\", \"custom\": { \"i\": \"" + notificationID + "\" } }]"), false, notificationID);
threadAndTaskWait();
assertNotNull(notificationOpenedResult);
// Check message String matches data sent in open handler
assertEquals("Test Msg", notificationOpenedResult.getNotification().getBody());
// Make sure notification influence is DIRECT
assertNotificationChannelDirectInfluence(notificationID);
// Make sure iam influence is UNATTRIBUTED
assertIAMChannelUnattributedInfluence();
for (OSInfluence influence : lastInfluencesEnding) {
assertEquals(OSInfluenceType.UNATTRIBUTED, influence.getInfluenceType());
}
}
use of com.onesignal.influence.domain.OSInfluence in project OneSignal-Android-SDK by OneSignal.
the class OutcomeEventIntegrationTests method foregroundAppAfterClickingNotification.
private void foregroundAppAfterClickingNotification() throws Exception {
OneSignalInit();
threadAndTaskWait();
// Make sure no notification data exists
assertNull(notificationOpenedMessage);
// Make no direct notification id is set
assertNull(trackerFactory.getNotificationChannelTracker().getDirectId());
// 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";
sessionManager.onNotificationReceived(notificationID);
// Click notification before new session
OneSignal_handleNotificationOpen(blankActivity, new JSONArray("[{ \"alert\": \"Test Msg\", \"custom\": { \"i\": \"" + notificationID + "\" } }]"), false, notificationID);
threadAndTaskWait();
// App opened after clicking notification, but Robolectric needs this to simulate onAppFocus() code after a click
blankActivityController.resume();
threadAndTaskWait();
// Check directNotificationId is set to clicked notification
assertEquals(notificationID, trackerFactory.getNotificationChannelTracker().getDirectId());
// Make sure notification influence is DIRECT
assertNotificationChannelDirectInfluence(notificationID);
// Make sure iam influence is UNATTRIBUTED
assertIAMChannelUnattributedInfluence();
// 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;
}
use of com.onesignal.influence.domain.OSInfluence 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