Search in sources :

Example 6 with OSInfluence

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());
}
Also used : OSInfluence(com.onesignal.influence.domain.OSInfluence)

Example 7 with OSInfluence

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));
}
Also used : OSInfluence(com.onesignal.influence.domain.OSInfluence)

Example 8 with OSInfluence

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());
    }
}
Also used : JSONArray(org.json.JSONArray) OSInfluence(com.onesignal.influence.domain.OSInfluence) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 9 with OSInfluence

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;
}
Also used : JSONArray(org.json.JSONArray) OSInfluence(com.onesignal.influence.domain.OSInfluence)

Example 10 with OSInfluence

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;
}
Also used : Bundle(android.os.Bundle) GenerateNotificationRunner.getBaseNotifBundle(com.test.onesignal.GenerateNotificationRunner.getBaseNotifBundle) FCMBroadcastReceiver_onReceived_withBundle(com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withBundle) OSInfluence(com.onesignal.influence.domain.OSInfluence)

Aggregations

OSInfluence (com.onesignal.influence.domain.OSInfluence)40 Test (org.junit.Test)25 OneSignalPackagePrivateHelper (com.onesignal.OneSignalPackagePrivateHelper)23 OSChannelTracker (com.onesignal.influence.data.OSChannelTracker)7 JSONArray (org.json.JSONArray)5 ArrayList (java.util.ArrayList)3 Config (org.robolectric.annotation.Config)2 Bundle (android.os.Bundle)1 FCMBroadcastReceiver_onReceived_withBundle (com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withBundle)1 OSOutcomeEventParams (com.onesignal.outcomes.domain.OSOutcomeEventParams)1 OSOutcomeSource (com.onesignal.outcomes.domain.OSOutcomeSource)1 OSOutcomeSourceBody (com.onesignal.outcomes.domain.OSOutcomeSourceBody)1 GenerateNotificationRunner.getBaseNotifBundle (com.test.onesignal.GenerateNotificationRunner.getBaseNotifBundle)1