15
15
* limitations under the License.
16
16
*/
17
17
18
- const expect = require ( 'chai' ) . expect ;
19
18
const testServer = require ( './utils/test-server' ) ;
20
19
const sendMessage = require ( './utils/sendMessage' ) ;
21
20
const retrieveToken = require ( './utils/retrieveToken' ) ;
22
21
const seleniumAssistant = require ( 'selenium-assistant' ) ;
23
- const getReceivedBackgroundMessages = require ( './utils/getReceivedBackgroundMessages ' ) ;
22
+ const checkSendResponse = require ( './utils/checkSendResponse ' ) ;
24
23
const getReceivedForegroundMessages = require ( './utils/getReceivedForegroundMessages' ) ;
25
- const openNewTab = require ( './utils/openNewTab ' ) ;
24
+ const checkMessageReceived = require ( './utils/checkMessageReceived ' ) ;
26
25
const createPermittedWebDriver = require ( './utils/createPermittedWebDriver' ) ;
27
26
28
- const TEST_DOMAINS = [ 'valid-vapid-key' , 'valid-vapid-key-modern-sw' ] ;
29
- const TEST_PROJECT_SENDER_ID = '750970317741' ;
30
- const DEFAULT_COLLAPSE_KEY_VALUE = 'do_not_collapse' ;
31
- const FIELD_FROM = 'from' ;
32
- const FIELD_COLLAPSE_KEY_LEGACY = 'collapse_key' ;
33
- const FIELD_COLLAPSE_KEY = 'collapseKey' ;
34
-
35
- const FIELD_DATA = 'data' ;
36
- const FIELD_NOTIFICATION = 'notification' ;
37
-
38
- // 4 minutes. The fact that the flow includes making a request to the Send Service,
39
- // storing/retrieving form indexedDb asynchronously makes these test units to have a execution time
40
- // variance. Therefore, allowing these units to have a longer time to work is crucial.
41
- const TIMEOUT_BACKGROUND_MESSAGE_TEST_UNIT_MILLISECONDS = 240000 ;
42
-
27
+ // Only testing 'valid-vapid-key' because 'valid-vapid-key-modern-sw' has the same behavior
28
+ const TEST_DOMAINS = [ 'valid-vapid-key' ] ;
43
29
const TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS = 120000 ;
44
30
45
- // 1 minute. Wait for object store to be created and received message to be stored in idb. This
46
- // waiting time MUST be longer than the wait time for adding to db in the sw.
47
- const WAIT_TIME_BEFORE_RETRIEVING_BACKGROUND_MESSAGES_MILLISECONDS = 60000 ;
31
+ // Getting and deleting token is the entry step of using FM SDK. Let it run first and fail quickly.
32
+ require ( './test-token-delete' ) ;
48
33
49
- const wait = ms => new Promise ( res => setTimeout ( res , ms ) ) ;
50
-
51
- describe ( 'Starting Integration Test > Sending and Receiving ' , function ( ) {
52
- this . retries ( 3 ) ;
34
+ describe ( 'Firebase Messaging Integration Tests > Test Foreground Receive' , function ( ) {
35
+ this . retries ( 2 ) ;
53
36
let globalWebDriver ;
54
37
55
38
before ( async function ( ) {
@@ -73,68 +56,6 @@ describe('Starting Integration Test > Sending and Receiving ', function () {
73
56
/* browser= */ assistantBrowser . getId ( )
74
57
) ;
75
58
} ) ;
76
-
77
- it ( 'Background app can receive a {} empty message from sw' , async function ( ) {
78
- this . timeout ( TIMEOUT_BACKGROUND_MESSAGE_TEST_UNIT_MILLISECONDS ) ;
79
-
80
- // Clearing the cache and db data by killing the previously instantiated driver. Note that
81
- // ideally this call is placed inside the after/before hooks. However, Mocha forbids
82
- // operations longer than 2s in hooks. Hence, this clearing call needs to be inside the
83
- // test unit.
84
- await seleniumAssistant . killWebDriver ( globalWebDriver ) ;
85
-
86
- globalWebDriver = createPermittedWebDriver (
87
- /* browser= */ assistantBrowser . getId ( )
88
- ) ;
89
-
90
- prepareBackgroundApp ( globalWebDriver , domain ) ;
91
-
92
- checkSendResponse (
93
- await sendMessage ( {
94
- to : await retrieveToken ( globalWebDriver )
95
- } )
96
- ) ;
97
-
98
- await wait (
99
- WAIT_TIME_BEFORE_RETRIEVING_BACKGROUND_MESSAGES_MILLISECONDS
100
- ) ;
101
-
102
- checkMessageReceived (
103
- await getReceivedBackgroundMessages ( globalWebDriver ) ,
104
- /* expectedNotificationPayload= */ null ,
105
- /* expectedDataPayload= */ null ,
106
- /* isLegacyPayload= */ false
107
- ) ;
108
- } ) ;
109
-
110
- it ( 'Background app can receive a {"data"} message frow sw' , async function ( ) {
111
- this . timeout ( TIMEOUT_BACKGROUND_MESSAGE_TEST_UNIT_MILLISECONDS ) ;
112
-
113
- await seleniumAssistant . killWebDriver ( globalWebDriver ) ;
114
-
115
- globalWebDriver = createPermittedWebDriver (
116
- /* browser= */ assistantBrowser . getId ( )
117
- ) ;
118
-
119
- prepareBackgroundApp ( globalWebDriver , domain ) ;
120
-
121
- checkSendResponse (
122
- await sendMessage ( {
123
- to : await retrieveToken ( globalWebDriver ) ,
124
- data : getTestDataPayload ( )
125
- } )
126
- ) ;
127
-
128
- await wait (
129
- WAIT_TIME_BEFORE_RETRIEVING_BACKGROUND_MESSAGES_MILLISECONDS
130
- ) ;
131
-
132
- checkMessageReceived (
133
- await getReceivedBackgroundMessages ( globalWebDriver ) ,
134
- /* expectedNotificationPayload= */ null ,
135
- /* expectedDataPayload= */ getTestDataPayload ( )
136
- ) ;
137
- } ) ;
138
59
} ) ;
139
60
140
61
it ( 'Foreground app can receive a {} empty message in onMessage' , async function ( ) {
@@ -241,35 +162,8 @@ describe('Starting Integration Test > Sending and Receiving ', function () {
241
162
} ) ;
242
163
} ) ;
243
164
244
- function checkMessageReceived (
245
- receivedMessages ,
246
- expectedNotificationPayload ,
247
- expectedDataPayload
248
- ) {
249
- expect ( receivedMessages ) . to . exist ;
250
-
251
- const message = receivedMessages [ 0 ] ;
252
-
253
- expect ( message [ FIELD_FROM ] ) . to . equal ( TEST_PROJECT_SENDER_ID ) ;
254
- const collapseKey = ! ! message [ FIELD_COLLAPSE_KEY_LEGACY ]
255
- ? message [ FIELD_COLLAPSE_KEY_LEGACY ]
256
- : message [ FIELD_COLLAPSE_KEY ] ;
257
- expect ( collapseKey ) . to . equal ( DEFAULT_COLLAPSE_KEY_VALUE ) ;
258
-
259
- if ( expectedNotificationPayload ) {
260
- expect ( message [ FIELD_NOTIFICATION ] ) . to . deep . equal (
261
- getTestNotificationPayload ( )
262
- ) ;
263
- }
264
-
265
- if ( expectedDataPayload ) {
266
- expect ( message [ FIELD_DATA ] ) . to . deep . equal ( getTestDataPayload ( ) ) ;
267
- }
268
- }
269
-
270
- function checkSendResponse ( response ) {
271
- expect ( response ) . to . exist ;
272
- expect ( response . success ) . to . equal ( 1 ) ;
165
+ function getTestDataPayload ( ) {
166
+ return { hello : 'world' } ;
273
167
}
274
168
275
169
function getTestNotificationPayload ( ) {
@@ -281,22 +175,3 @@ function getTestNotificationPayload() {
281
175
tag : 'test-tag'
282
176
} ;
283
177
}
284
-
285
- function getTestDataPayload ( ) {
286
- return { hello : 'world' } ;
287
- }
288
-
289
- async function prepareBackgroundApp ( globalWebDriver , domain ) {
290
- await globalWebDriver . get ( `${ testServer . serverAddress } /${ domain } /` ) ;
291
-
292
- // TODO: remove the try/catch block once the underlying bug has been resolved. Shift window focus
293
- // away from app window so that background messages can be received/processed
294
- try {
295
- await openNewTab ( globalWebDriver ) ;
296
- } catch ( err ) {
297
- // ChromeDriver seems to have an open bug which throws "JavascriptError: javascript error:
298
- // circular reference". Nevertheless, a new tab can still be opened. Hence, just catch and
299
- // continue here.
300
- console . log ( 'FCM (ignored on purpose): ' + err ) ;
301
- }
302
- }
0 commit comments