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);
}
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"));
}
Aggregations