Search in sources :

Example 1 with GcmBroadcastReceiver

use of com.onesignal.GcmBroadcastReceiver in project OneSignal-Android-SDK by OneSignal.

the class GenerateNotificationRunner method shouldPreventOtherGCMReceiversWhenSettingEnabled.

@Test
@Config(shadows = { ShadowGcmBroadcastReceiver.class })
public void shouldPreventOtherGCMReceiversWhenSettingEnabled() throws Exception {
    OneSignal.setInFocusDisplaying(OneSignal.OSInFocusDisplayOption.InAppAlert);
    OneSignal.startInit(blankActivity).filterOtherGCMReceivers(true).init();
    threadAndTaskWait();
    Intent intentGcm = new Intent();
    intentGcm.setAction("com.google.android.c2dm.intent.RECEIVE");
    intentGcm.putExtra("message_type", "gcm");
    Bundle bundle = getBaseNotifBundle();
    bundle.putString("o", "[{\"n\": \"text1\", \"i\": \"id1\"}]");
    intentGcm.putExtras(bundle);
    GcmBroadcastReceiver gcmBroadcastReceiver = new GcmBroadcastReceiver();
    gcmBroadcastReceiver.onReceive(blankActivity, intentGcm);
    Assert.assertNull(ShadowGcmBroadcastReceiver.lastResultCode);
    Assert.assertTrue(ShadowGcmBroadcastReceiver.calledAbortBroadcast);
}
Also used : ShadowGcmBroadcastReceiver(com.onesignal.ShadowGcmBroadcastReceiver) GcmBroadcastReceiver(com.onesignal.GcmBroadcastReceiver) Bundle(android.os.Bundle) OneSignalPackagePrivateHelper.createInternalPayloadBundle(com.onesignal.OneSignalPackagePrivateHelper.createInternalPayloadBundle) Intent(android.content.Intent) Test(org.junit.Test) BuildConfig(com.onesignal.BuildConfig) Config(org.robolectric.annotation.Config)

Example 2 with GcmBroadcastReceiver

use of com.onesignal.GcmBroadcastReceiver in project OneSignal-Android-SDK by OneSignal.

the class GenerateNotificationRunner method shouldSetButtonsCorrectly.

@Test
@Config(shadows = { ShadowGcmBroadcastReceiver.class })
public void shouldSetButtonsCorrectly() throws Exception {
    Intent intentGcm = new Intent();
    intentGcm.setAction("com.google.android.c2dm.intent.RECEIVE");
    intentGcm.putExtra("message_type", "gcm");
    Bundle bundle = getBaseNotifBundle();
    bundle.putString("o", "[{\"n\": \"text1\", \"i\": \"id1\"}]");
    intentGcm.putExtras(bundle);
    GcmBroadcastReceiver gcmBroadcastReceiver = new GcmBroadcastReceiver();
    gcmBroadcastReceiver.onReceive(blankActivity, intentGcm);
    Intent intent = Shadows.shadowOf(blankActivity).getNextStartedService();
    Assert.assertEquals("com.onesignal.GcmIntentService", intent.getComponent().getClassName());
    JSONObject jsonPayload = new JSONObject(intent.getStringExtra("json_payload"));
    Assert.assertEquals(null, jsonPayload.optString("o", null));
    JSONObject customJson = new JSONObject(jsonPayload.optString("custom"));
    JSONObject additionalData = new JSONObject((customJson.getString("a")));
    Assert.assertEquals("id1", additionalData.getJSONArray("actionButtons").getJSONObject(0).getString("id"));
}
Also used : ShadowGcmBroadcastReceiver(com.onesignal.ShadowGcmBroadcastReceiver) GcmBroadcastReceiver(com.onesignal.GcmBroadcastReceiver) JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) OneSignalPackagePrivateHelper.createInternalPayloadBundle(com.onesignal.OneSignalPackagePrivateHelper.createInternalPayloadBundle) Intent(android.content.Intent) Test(org.junit.Test) BuildConfig(com.onesignal.BuildConfig) Config(org.robolectric.annotation.Config)

Aggregations

Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 BuildConfig (com.onesignal.BuildConfig)2 GcmBroadcastReceiver (com.onesignal.GcmBroadcastReceiver)2 OneSignalPackagePrivateHelper.createInternalPayloadBundle (com.onesignal.OneSignalPackagePrivateHelper.createInternalPayloadBundle)2 ShadowGcmBroadcastReceiver (com.onesignal.ShadowGcmBroadcastReceiver)2 Test (org.junit.Test)2 Config (org.robolectric.annotation.Config)2 JSONObject (org.json.JSONObject)1