Search in sources :

Example 1 with ShadowOneSignalRestClient.setRemoteParamsGetHtmlResponse

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

the class MainOneSignalClassRunner method shouldFirePermissionObserverWhenUserDisablesNotifications.

@Test
public void shouldFirePermissionObserverWhenUserDisablesNotifications() throws Exception {
    ShadowOneSignalRestClient.setRemoteParamsGetHtmlResponse(new JSONObject().put("unsubscribe_on_notifications_disabled", false));
    OneSignalInit();
    threadAndTaskWait();
    OSPermissionObserver permissionObserver = stateChanges -> {
        lastPermissionStateChanges = stateChanges;
        currentPermission = stateChanges.getTo().areNotificationsEnabled();
    };
    OneSignal.addPermissionObserver(permissionObserver);
    lastPermissionStateChanges = null;
    // Make sure garbage collection doesn't nuke any observers.
    Runtime.getRuntime().gc();
    stopActivity(blankActivityController);
    ShadowNotificationManagerCompat.enabled = false;
    blankActivityController.resume();
    assertTrue(lastPermissionStateChanges.getFrom().areNotificationsEnabled());
    assertFalse(lastPermissionStateChanges.getTo().areNotificationsEnabled());
    // Test to make sure object was correct at the time of firing.
    assertFalse(currentPermission);
    // unsubscribeWhenNotificationsAreDisabled is not set so don't send notification_types.
    assertFalse(ShadowOneSignalRestClient.lastPost.has("notification_types"));
}
Also used : NotificationBundleProcessor_Process(com.onesignal.OneSignalPackagePrivateHelper.NotificationBundleProcessor_Process) Arrays(java.util.Arrays) Bundle(android.os.Bundle) ShadowGoogleApiClientBuilder(com.onesignal.ShadowGoogleApiClientBuilder) RestClientAsserts.assertOnSessionAtIndex(com.test.onesignal.RestClientAsserts.assertOnSessionAtIndex) ShadowOneSignalRestClient(com.onesignal.ShadowOneSignalRestClient) TestHelpers.stopActivity(com.test.onesignal.TestHelpers.stopActivity) OSDeviceState(com.onesignal.OSDeviceState) RestClientAsserts.assertHuaweiPlayerCreateAtIndex(com.test.onesignal.RestClientAsserts.assertHuaweiPlayerCreateAtIndex) ShadowConnectivityManager(org.robolectric.shadows.ShadowConnectivityManager) ShadowRoboNotificationManager(com.onesignal.ShadowRoboNotificationManager) OneSignal(com.onesignal.OneSignal) TestHelpers.fastColdRestartApp(com.test.onesignal.TestHelpers.fastColdRestartApp) JSONException(org.json.JSONException) Map(java.util.Map) TestHelpers.assertAndRunSyncService(com.test.onesignal.TestHelpers.assertAndRunSyncService) TestHelpers.pauseActivity(com.test.onesignal.TestHelpers.pauseActivity) MockOneSignalDBHelper(com.onesignal.MockOneSignalDBHelper) ShadowCustomTabsClient(com.onesignal.ShadowCustomTabsClient) ConnectivityManager(android.net.ConnectivityManager) OneSignal_isInForeground(com.onesignal.OneSignalPackagePrivateHelper.OneSignal_isInForeground) AfterClass(org.junit.AfterClass) StaticResetHelper(com.onesignal.StaticResetHelper) BlockingQueue(java.util.concurrent.BlockingQueue) ShadowGMSLocationController(com.onesignal.ShadowGMSLocationController) RuntimeEnvironment(org.robolectric.RuntimeEnvironment) OneSignal_setSessionManager(com.onesignal.OneSignalPackagePrivateHelper.OneSignal_setSessionManager) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) EMAIL_USER_ID(com.onesignal.ShadowOneSignalRestClient.EMAIL_USER_ID) RestClientAsserts.assertOnFocusAtIndex(com.test.onesignal.RestClientAsserts.assertOnFocusAtIndex) RestClientAsserts.assertRemoteParamsAtIndex(com.test.onesignal.RestClientAsserts.assertRemoteParamsAtIndex) Awaitility(org.awaitility.Awaitility) ShadowCustomTabsSession(com.onesignal.ShadowCustomTabsSession) Assert.assertEquals(junit.framework.Assert.assertEquals) OSNotificationReceivedEvent(com.onesignal.OSNotificationReceivedEvent) GenerateNotificationRunner.getBaseNotifBundle(com.test.onesignal.GenerateNotificationRunner.getBaseNotifBundle) ShadowPushRegistratorFCM(com.onesignal.ShadowPushRegistratorFCM) TestHelpers.restartAppAndElapseTimeToNextSession(com.test.onesignal.TestHelpers.restartAppAndElapseTimeToNextSession) OneSignal_getSessionListener(com.onesignal.OneSignalPackagePrivateHelper.OneSignal_getSessionListener) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) SyncJobService(com.onesignal.SyncJobService) ShadowReceiveReceiptController(com.onesignal.ShadowReceiveReceiptController) ArrayList(java.util.ArrayList) OSNotificationOpenedResult(com.onesignal.OSNotificationOpenedResult) Assert.assertTrue(junit.framework.Assert.assertTrue) NotificationOpenedProcessor_processFromContext(com.onesignal.OneSignalPackagePrivateHelper.NotificationOpenedProcessor_processFromContext) ShadowNotificationManagerCompat(com.onesignal.ShadowNotificationManagerCompat) Assert.assertNull(junit.framework.Assert.assertNull) MockOSLog(com.onesignal.MockOSLog) Before(org.junit.Before) SMS_USER_ID(com.onesignal.ShadowOneSignalRestClient.SMS_USER_ID) TestHelpers.afterTestCleanup(com.test.onesignal.TestHelpers.afterTestCleanup) ShadowFusedLocationApiWrapper(com.onesignal.ShadowFusedLocationApiWrapper) Test(org.junit.Test) Field(java.lang.reflect.Field) BlankActivity(com.onesignal.example.BlankActivity) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) FCMBroadcastReceiver_processBundle(com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_processBundle) PUSH_USER_ID(com.onesignal.ShadowOneSignalRestClient.PUSH_USER_ID) OSPermissionStateChanges(com.onesignal.OSPermissionStateChanges) SharedPreferences(android.content.SharedPreferences) ShadowOneSignalNotificationManager(com.onesignal.ShadowOneSignalNotificationManager) ShadowGenerateNotification(com.onesignal.ShadowGenerateNotification) ShadowFirebaseAnalytics(com.onesignal.ShadowFirebaseAnalytics) ShadowJobService(com.onesignal.ShadowJobService) TestHelpers.threadAndTaskWait(com.test.onesignal.TestHelpers.threadAndTaskWait) OSSubscriptionObserver(com.onesignal.OSSubscriptionObserver) OSSubscriptionStateChanges(com.onesignal.OSSubscriptionStateChanges) ActivityController(org.robolectric.android.controller.ActivityController) OSSMSSubscriptionStateChanges(com.onesignal.OSSMSSubscriptionStateChanges) ShadowBadgeCountUpdater(com.onesignal.ShadowBadgeCountUpdater) OSPermissionObserver(com.onesignal.OSPermissionObserver) OneSignalPackagePrivateHelper(com.onesignal.OneSignalPackagePrivateHelper) ApplicationProvider(androidx.test.core.app.ApplicationProvider) Assert.assertThat(org.junit.Assert.assertThat) JSONObject(org.json.JSONObject) ShadowOneSignalRestClient.setRemoteParamsGetHtmlResponse(com.onesignal.ShadowOneSignalRestClient.setRemoteParamsGetHtmlResponse) TestHelpers.startRemoteNotificationReceivedHandlerService(com.test.onesignal.TestHelpers.startRemoteNotificationReceivedHandlerService) OneSignal_taskQueueWaitingForInit(com.onesignal.OneSignalPackagePrivateHelper.OneSignal_taskQueueWaitingForInit) Assert.assertNotNull(junit.framework.Assert.assertNotNull) After(org.junit.After) RestClientAsserts.assertRestCalls(com.test.onesignal.RestClientAsserts.assertRestCalls) ActivityInfo(android.content.pm.ActivityInfo) ShadowPushRegistratorADM(com.onesignal.ShadowPushRegistratorADM) PermissionsActivity(com.onesignal.PermissionsActivity) RestClientAsserts.assertAndroidPlayerCreateAtIndex(com.test.onesignal.RestClientAsserts.assertAndroidPlayerCreateAtIndex) TimeZone(java.util.TimeZone) OneSignalShadowPackageManager(com.onesignal.OneSignalShadowPackageManager) ShadowHmsInstanceId(com.onesignal.ShadowHmsInstanceId) OneSignal_handleNotificationOpen(com.onesignal.OneSignalPackagePrivateHelper.OneSignal_handleNotificationOpen) MockOSTimeImpl(com.onesignal.MockOSTimeImpl) RestClientAsserts.assertAmazonPlayerCreateAtIndex(com.test.onesignal.RestClientAsserts.assertAmazonPlayerCreateAtIndex) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) MockSessionManager(com.onesignal.MockSessionManager) ShadowOneSignal(com.onesignal.ShadowOneSignal) List(java.util.List) ShadowGoogleApiClientCompatProxy(com.onesignal.ShadowGoogleApiClientCompatProxy) OSSMSSubscriptionObserver(com.onesignal.OSSMSSubscriptionObserver) ShadowOSUtils(com.onesignal.ShadowOSUtils) Pattern(java.util.regex.Pattern) ShadowLog(org.robolectric.shadows.ShadowLog) SyncService(com.onesignal.SyncService) Context(android.content.Context) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) MainActivity(com.onesignal.example.MainActivity) BeforeClass(org.junit.BeforeClass) OSObservable(com.onesignal.OneSignalPackagePrivateHelper.OSObservable) CoreMatchers.not(org.hamcrest.CoreMatchers.not) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Intent(android.content.Intent) RestClientAsserts.assertPlayerCreatePushAtIndex(com.test.onesignal.RestClientAsserts.assertPlayerCreatePushAtIndex) ChangeTagsUpdateHandler(com.onesignal.OneSignal.ChangeTagsUpdateHandler) Shadows.shadowOf(org.robolectric.Shadows.shadowOf) SuppressLint(android.annotation.SuppressLint) OSEmailSubscriptionObserver(com.onesignal.OSEmailSubscriptionObserver) OSNotification(com.onesignal.OSNotification) WeakReference(java.lang.ref.WeakReference) Cursor(android.database.Cursor) REST_METHOD(com.onesignal.ShadowOneSignalRestClient.REST_METHOD) Duration(org.awaitility.Duration) Iterator(java.util.Iterator) TestHelpers.getNextJob(com.test.onesignal.TestHelpers.getNextJob) AlarmManager(android.app.AlarmManager) Robolectric(org.robolectric.Robolectric) ShadowFocusHandler(com.onesignal.ShadowFocusHandler) LooperMode(org.robolectric.annotation.LooperMode) TestHelpers.flushBufferedSharedPrefs(com.test.onesignal.TestHelpers.flushBufferedSharedPrefs) TestHelpers.assertNextJob(com.test.onesignal.TestHelpers.assertNextJob) TestHelpers.assertNumberOfServicesAvailable(com.test.onesignal.TestHelpers.assertNumberOfServicesAvailable) ResolveInfo(android.content.pm.ResolveInfo) TimeUnit(java.util.concurrent.TimeUnit) OneSignal_setTime(com.onesignal.OneSignalPackagePrivateHelper.OneSignal_setTime) ShadowAlarmManager(org.robolectric.shadows.ShadowAlarmManager) OneSignal_setTrackerFactory(com.onesignal.OneSignalPackagePrivateHelper.OneSignal_setTrackerFactory) OSNotificationAction(com.onesignal.OSNotificationAction) Activity(android.app.Activity) OSEmailSubscriptionStateChanges(com.onesignal.OSEmailSubscriptionStateChanges) OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) JSONArray(org.json.JSONArray) RestClientAsserts.assertOnFocusAtIndexDoesNotHaveKeys(com.test.onesignal.RestClientAsserts.assertOnFocusAtIndexDoesNotHaveKeys) Assert.assertFalse(junit.framework.Assert.assertFalse) OSPermissionObserver(com.onesignal.OSPermissionObserver) JSONObject(org.json.JSONObject) Test(org.junit.Test)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 AlarmManager (android.app.AlarmManager)1 Context (android.content.Context)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 ActivityInfo (android.content.pm.ActivityInfo)1 ResolveInfo (android.content.pm.ResolveInfo)1 Cursor (android.database.Cursor)1 ConnectivityManager (android.net.ConnectivityManager)1 Bundle (android.os.Bundle)1 ApplicationProvider (androidx.test.core.app.ApplicationProvider)1 MockOSLog (com.onesignal.MockOSLog)1 MockOSSharedPreferences (com.onesignal.MockOSSharedPreferences)1 MockOSTimeImpl (com.onesignal.MockOSTimeImpl)1 MockOneSignalDBHelper (com.onesignal.MockOneSignalDBHelper)1 MockSessionManager (com.onesignal.MockSessionManager)1 OSDeviceState (com.onesignal.OSDeviceState)1 OSEmailSubscriptionObserver (com.onesignal.OSEmailSubscriptionObserver)1 OSEmailSubscriptionStateChanges (com.onesignal.OSEmailSubscriptionStateChanges)1