@@ -21,6 +21,7 @@ const sendMessage = require('./utils/sendMessage');
21
21
const retrieveToken = require ( './utils/retrieveToken' ) ;
22
22
const seleniumAssistant = require ( 'selenium-assistant' ) ;
23
23
const getReceivedBackgroundMessages = require ( './utils/getReceivedBackgroundMessages' ) ;
24
+ const getReceivedForegroundMessages = require ( './utils/getReceivedForegroundMessages' ) ;
24
25
const openNewTab = require ( './utils/openNewTab' ) ;
25
26
const createPermittedWebDriver = require ( './utils/createPermittedWebDriver' ) ;
26
27
@@ -35,6 +36,8 @@ const FIELD_NOTIFICATION = 'notification';
35
36
// 4 minutes. The fact that the flow includes making a request to the Send Service, storing/retrieving form indexedDb asynchronously makes these test units to have a execution time variance. Therefore, allowing these units to have a longer time to work is crucial.
36
37
const TIMEOUT_BACKGROUND_MESSAGE_TEST_UNIT_MILLISECONDS = 240000 ;
37
38
39
+ const TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS = 120000 ;
40
+
38
41
// 1 minute. Wait for object store to be created and received message to be stored in idb. This waiting time MUST be longer than the wait time for adding to db in the sw.
39
42
const WAIT_TIME_BEFORE_RETRIEVING_BACKGROUND_MESSAGES_MILLISECONDS = 60000 ;
40
43
@@ -122,6 +125,115 @@ describe('Starting Integration Test > Sending and Receiving ', function() {
122
125
/* expectedDataPayload= */ getTestDataPayload ( )
123
126
) ;
124
127
} ) ;
128
+
129
+ it ( 'Foreground app can receive a {} empty message in onMessage' , async function ( ) {
130
+ this . timeout ( TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS ) ;
131
+
132
+ await seleniumAssistant . killWebDriver ( globalWebDriver ) ;
133
+
134
+ globalWebDriver = createPermittedWebDriver (
135
+ /* browser= */ assistantBrowser . getId ( )
136
+ ) ;
137
+
138
+ await globalWebDriver . get (
139
+ `${ testServer . serverAddress } /${ TEST_DOMAIN } /`
140
+ ) ;
141
+
142
+ let token = await retrieveToken ( globalWebDriver ) ;
143
+ checkSendResponse (
144
+ await sendMessage ( {
145
+ to : token
146
+ } )
147
+ ) ;
148
+
149
+ await checkMessageReceived (
150
+ await getReceivedForegroundMessages ( globalWebDriver ) ,
151
+ /* expectedNotificationPayload= */ null ,
152
+ /* expectedDataPayload= */ null
153
+ ) ;
154
+ } ) ;
155
+
156
+ it ( 'Foreground app can receive a {"notification"} message in onMessage' , async function ( ) {
157
+ this . timeout ( TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS ) ;
158
+
159
+ await seleniumAssistant . killWebDriver ( globalWebDriver ) ;
160
+
161
+ globalWebDriver = createPermittedWebDriver (
162
+ /* browser= */ assistantBrowser . getId ( )
163
+ ) ;
164
+
165
+ await globalWebDriver . get (
166
+ `${ testServer . serverAddress } /${ TEST_DOMAIN } /`
167
+ ) ;
168
+
169
+ checkSendResponse (
170
+ await sendMessage ( {
171
+ to : await retrieveToken ( globalWebDriver ) ,
172
+ notification : getTestNotificationPayload ( )
173
+ } )
174
+ ) ;
175
+
176
+ await checkMessageReceived (
177
+ await getReceivedForegroundMessages ( globalWebDriver ) ,
178
+ /* expectedNotificationPayload= */ getTestNotificationPayload ( ) ,
179
+ /* expectedDataPayload= */ null
180
+ ) ;
181
+ } ) ;
182
+
183
+ it ( 'Foreground app can receive a {"data"} message in onMessage' , async function ( ) {
184
+ this . timeout ( TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS ) ;
185
+
186
+ await seleniumAssistant . killWebDriver ( globalWebDriver ) ;
187
+
188
+ globalWebDriver = createPermittedWebDriver (
189
+ /* browser= */ assistantBrowser . getId ( )
190
+ ) ;
191
+
192
+ await globalWebDriver . get (
193
+ `${ testServer . serverAddress } /${ TEST_DOMAIN } /`
194
+ ) ;
195
+
196
+ checkSendResponse (
197
+ await sendMessage ( {
198
+ to : await retrieveToken ( globalWebDriver ) ,
199
+ data : getTestDataPayload ( )
200
+ } )
201
+ ) ;
202
+
203
+ await checkMessageReceived (
204
+ await getReceivedForegroundMessages ( globalWebDriver ) ,
205
+ /* expectedNotificationPayload= */ null ,
206
+ /* expectedDataPayload= */ getTestDataPayload ( )
207
+ ) ;
208
+ } ) ;
209
+
210
+ it ( 'Foreground app can receive a {"notification", "data"} message in onMessage' , async function ( ) {
211
+ this . timeout ( TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS ) ;
212
+
213
+ await seleniumAssistant . killWebDriver ( globalWebDriver ) ;
214
+
215
+ globalWebDriver = createPermittedWebDriver (
216
+ /* browser= */ assistantBrowser . getId ( )
217
+ ) ;
218
+
219
+ await globalWebDriver . get (
220
+ `${ testServer . serverAddress } /${ TEST_DOMAIN } /`
221
+ ) ;
222
+
223
+ checkSendResponse (
224
+ await sendMessage ( {
225
+ to : await retrieveToken ( globalWebDriver ) ,
226
+ data : getTestDataPayload ( ) ,
227
+ notification : getTestNotificationPayload ( )
228
+ } )
229
+ ) ;
230
+
231
+ await checkMessageReceived (
232
+ await getReceivedForegroundMessages ( globalWebDriver ) ,
233
+ /* expectedNotificationPayload= */ getTestNotificationPayload ( ) ,
234
+ /* expectedDataPayload= */ getTestDataPayload ( )
235
+ ) ;
236
+ } ) ;
125
237
} ) ;
126
238
} ) ;
127
239
} ) ;
0 commit comments