@@ -1252,15 +1252,15 @@ public void shouldSetExpireTimeCorrectlyFromGoogleTTL() throws Exception {
1252
1252
@ Test
1253
1253
@ Config (sdk = 23 , shadows = { ShadowGenerateNotification .class })
1254
1254
public void notShowNotificationPastTTL () throws Exception {
1255
- long sentTime = time .getCurrentThreadTimeMillis ();
1255
+ long sentTime = time .getCurrentTimeMillis ();
1256
1256
long ttl = 60L ;
1257
1257
1258
1258
Bundle bundle = getBaseNotifBundle ();
1259
1259
bundle .putLong (OneSignalPackagePrivateHelper .GOOGLE_SENT_TIME_KEY , sentTime );
1260
1260
bundle .putLong (OneSignalPackagePrivateHelper .GOOGLE_TTL_KEY , ttl );
1261
1261
1262
1262
// Go forward just past the TTL of the notification
1263
- time .advanceThreadTimeBy (ttl + 1 );
1263
+ time .advanceSystemTimeBy (ttl + 1 );
1264
1264
1265
1265
NotificationBundleProcessor_ProcessFromFCMIntentService (blankActivity , bundle );
1266
1266
threadAndTaskWait ();
@@ -1275,7 +1275,7 @@ public void shouldSetExpireTimeCorrectlyWhenMissingFromPayload() throws Exceptio
1275
1275
threadAndTaskWait ();
1276
1276
1277
1277
long expireTime = (Long )TestHelpers .getAllNotificationRecords (dbHelper ).get (0 ).get (NotificationTable .COLUMN_NAME_EXPIRE_TIME );
1278
- assertEquals ((SystemClock . currentThreadTimeMillis () / 1_000L ) + 259_200 , expireTime );
1278
+ assertEquals ((System . currentTimeMillis () / 1_000L ) + 259_200 , expireTime );
1279
1279
}
1280
1280
1281
1281
// TODO: Once we figure out the correct way to process notifications with high priority using the WorkManager
@@ -1983,6 +1983,64 @@ public void remoteNotificationReceived(Context context, OSNotificationReceivedEv
1983
1983
}
1984
1984
}
1985
1985
1986
+ @ Test
1987
+ @ Config (shadows = { ShadowGenerateNotification .class })
1988
+ public void testNotificationProcessingAndForegroundHandler_callCompleteWithMutableNotification_displays () throws Exception {
1989
+ // 1. Setup correct notification extension service class
1990
+ startRemoteNotificationReceivedHandlerService (
1991
+ RemoteNotificationReceivedHandler_notificationReceivedCallCompleteWithMutableNotification
1992
+ .class
1993
+ .getName ()
1994
+ );
1995
+
1996
+ // 2. Init OneSignal
1997
+ OneSignal .setAppId ("b2f7f966-d8cc-11e4-bed1-df8f05be55ba" );
1998
+ OneSignal .initWithContext (blankActivity );
1999
+ OneSignal .setNotificationWillShowInForegroundHandler (notificationReceivedEvent -> {
2000
+ lastForegroundNotificationReceivedEvent = notificationReceivedEvent ;
2001
+
2002
+ // Call complete to end without waiting default 30 second timeout
2003
+ notificationReceivedEvent .complete (notificationReceivedEvent .getNotification ());
2004
+ });
2005
+ threadAndTaskWait ();
2006
+
2007
+ blankActivityController .resume ();
2008
+ threadAndTaskWait ();
2009
+
2010
+ // 3. Receive a notification in foreground
2011
+ FCMBroadcastReceiver_processBundle (blankActivity , getBaseNotifBundle ());
2012
+ threadAndTaskWait ();
2013
+
2014
+ // 4. Make sure service was called
2015
+ assertNotNull (lastServiceNotificationReceivedEvent );
2016
+
2017
+ // 5. Make sure foreground handler was called
2018
+ assertNotNull (lastForegroundNotificationReceivedEvent );
2019
+
2020
+ // 6. Make sure running on main thread check is called, this is only called for showing the notification
2021
+ assertTrue (ShadowGenerateNotification .isRunningOnMainThreadCheckCalled ());
2022
+
2023
+ // 7. Check badge count to represent the notification is displayed
2024
+ assertEquals (1 , ShadowBadgeCountUpdater .lastCount );
2025
+ }
2026
+
2027
+ /**
2028
+ * @see #testNotificationProcessingAndForegroundHandler_callCompleteWithMutableNotification_displays
2029
+ */
2030
+ public static class RemoteNotificationReceivedHandler_notificationReceivedCallCompleteWithMutableNotification implements OneSignal .OSRemoteNotificationReceivedHandler {
2031
+
2032
+ @ Override
2033
+ public void remoteNotificationReceived (final Context context , OSNotificationReceivedEvent receivedEvent ) {
2034
+ lastServiceNotificationReceivedEvent = receivedEvent ;
2035
+
2036
+ OSNotification notification = receivedEvent .getNotification ();
2037
+ OSMutableNotification mutableNotification = notification .mutableCopy ();
2038
+
2039
+ // Complete is called to end NotificationProcessingHandler
2040
+ receivedEvent .complete (mutableNotification );
2041
+ }
2042
+ }
2043
+
1986
2044
@ Test
1987
2045
@ Config (shadows = { ShadowGenerateNotification .class })
1988
2046
public void testNotificationWillShowInForegroundHandlerIsCallWhenReceivingNotificationInForeground () throws Exception {
0 commit comments