|
3 | 3 | import android.annotation.SuppressLint;
|
4 | 4 | import android.app.Activity;
|
5 | 5 | import android.os.Bundle;
|
| 6 | +import android.util.Log; |
6 | 7 |
|
7 | 8 | import com.huawei.hms.push.RemoteMessage;
|
8 | 9 | import com.onesignal.MockOSTimeImpl;
|
| 10 | +import com.onesignal.OneSignal; |
| 11 | +import com.onesignal.OneSignalPackagePrivateHelper; |
9 | 12 | import com.onesignal.OneSignalPackagePrivateHelper.NotificationPayloadProcessorHMS;
|
10 | 13 | import com.onesignal.ShadowBadgeCountUpdater;
|
11 | 14 | import com.onesignal.ShadowGenerateNotification;
|
| 15 | +import com.onesignal.ShadowHmsNotificationPayloadProcessor; |
12 | 16 | import com.onesignal.ShadowHmsRemoteMessage;
|
13 | 17 | import com.onesignal.ShadowNotificationManagerCompat;
|
14 | 18 | import com.onesignal.ShadowOSUtils;
|
|
33 | 37 |
|
34 | 38 | import java.util.UUID;
|
35 | 39 |
|
| 40 | +import static com.onesignal.OneSignalHmsEventBridge.HMS_SENT_TIME_KEY; |
| 41 | +import static com.onesignal.OneSignalHmsEventBridge.HMS_TTL_KEY; |
36 | 42 | import static com.onesignal.OneSignalPackagePrivateHelper.HMSEventBridge_onMessageReceive;
|
37 | 43 | import static com.onesignal.OneSignalPackagePrivateHelper.HMSProcessor_processDataMessageReceived;
|
38 | 44 | import static com.onesignal.OneSignalPackagePrivateHelper.OSNotificationFormatHelper.PAYLOAD_OS_NOTIFICATION_ID;
|
@@ -138,6 +144,28 @@ public void ttl_shouldNotDisplayNotification() throws Exception {
|
138 | 144 | assertEquals(0, ShadowBadgeCountUpdater.lastCount);
|
139 | 145 | }
|
140 | 146 |
|
| 147 | + @Test |
| 148 | + @Config(shadows = { ShadowGenerateNotification.class, ShadowHmsRemoteMessage.class, ShadowBadgeCountUpdater.class, ShadowHmsNotificationPayloadProcessor.class }) |
| 149 | + public void ttl_shouldDisplayNotificationWithNoTTLandSentTime() throws Exception { |
| 150 | + blankActivityController.pause(); |
| 151 | + |
| 152 | + long sentTime = 1_635_971_895_940L; |
| 153 | + |
| 154 | + time.setMockedTime(sentTime * 1_000); |
| 155 | + long setSentTime = time.getCurrentTimeMillis(); |
| 156 | + |
| 157 | + ShadowHmsRemoteMessage.data = helperBasicOSPayload(); |
| 158 | + |
| 159 | + HMSEventBridge_onMessageReceive(blankActivity, new RemoteMessage(new Bundle())); |
| 160 | + threadAndTaskWait(); |
| 161 | + |
| 162 | + String messageData = ShadowHmsNotificationPayloadProcessor.getMessageData(); |
| 163 | + JSONObject jsonObject = new JSONObject(messageData); |
| 164 | + |
| 165 | + assertEquals(OneSignalPackagePrivateHelper.OSNotificationRestoreWorkManager.getDEFAULT_TTL_IF_NOT_IN_PAYLOAD(), jsonObject.getInt(HMS_TTL_KEY)); |
| 166 | + assertEquals(setSentTime, jsonObject.getLong(HMS_SENT_TIME_KEY)); |
| 167 | + } |
| 168 | + |
141 | 169 | // NOTE: More tests can be added but they would be duplicated with GenerateNotificationRunner
|
142 | 170 | // In 4.0.0 or later these should be written in a reusable way between HMS, FCM, and ADM
|
143 | 171 | }
|
0 commit comments