Skip to content

Commit 0403b84

Browse files
committed
Polish PR based on feedbacks
1 parent d1670fe commit 0403b84

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+531
-481
lines changed

integration/messaging/download-browsers.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
const seleniumAssistant = require('selenium-assistant');
1919

2020
console.log('Starting browser download - this may take some time.');
21-
// TODO: enable firefox testing once figure out how to give notification permission with SE webdriver.
22-
// TODO: Run the integration test against multiple major chrome versions to ensure backward compatibility
21+
// TODO: enable firefox testing once figure out how to give notification permission with SE
22+
// webdriver. TODO: Run the integration test against multiple major chrome versions to ensure
23+
// backward compatibility
2324
Promise.all([seleniumAssistant.downloadLocalBrowser('chrome', 'stable', 80)])
2425
.then(() => {
2526
console.log('Browser download complete.');

integration/messaging/manual-test-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

integration/messaging/test/static/helpers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ async function addPayloadToDb(payload) {
4040
}
4141

4242
async function addPayloadToDbInternal(db, payload) {
43-
// onsuccess might race with onupgradeneeded. Consequently causing "object stores was not found" error. Therefore, wait briefly for db.createObjectStore to complete
43+
// onsuccess might race with onupgradeneeded. Consequently causing "object stores was not found"
44+
// error. Therefore, wait briefly for db.createObjectStore to complete
4445
const delay = ms => new Promise(res => setTimeout(res, ms));
4546
await delay(/* milliseconds= */ 30000);
4647

integration/messaging/test/test-deleteToken.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('Firebase Messaging Integration Tests > get and delete token', function
4141

4242
const availableBrowsers = seleniumAssistant.getLocalBrowsers();
4343
availableBrowsers.forEach(assistantBrowser => {
44-
//TODO: enable testing for firefox
44+
// TODO: enable testing for firefox
4545
if (assistantBrowser.getId() !== 'chrome') {
4646
return;
4747
}

integration/messaging/test/test-send.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,21 @@ const TEST_DOMAINS = ['valid-vapid-key', 'valid-vapid-key-modern-sw'];
2929
const TEST_PROJECT_SENDER_ID = '750970317741';
3030
const DEFAULT_COLLAPSE_KEY_VALUE = 'do_not_collapse';
3131
const FIELD_FROM = 'from';
32-
const FIELD_COLLAPSE_KEY = 'collapse_key';
32+
const FIELD_COLLAPSE_KEY_LEGACY = 'collapse_key';
33+
const FIELD_COLLAPSE_KEY = 'collapseKey';
34+
3335
const FIELD_DATA = 'data';
3436
const FIELD_NOTIFICATION = 'notification';
3537

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.
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.
3741
const TIMEOUT_BACKGROUND_MESSAGE_TEST_UNIT_MILLISECONDS = 240000;
3842

3943
const TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS = 120000;
4044

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.
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.
4247
const WAIT_TIME_BEFORE_RETRIEVING_BACKGROUND_MESSAGES_MILLISECONDS = 60000;
4348

4449
const wait = ms => new Promise(res => setTimeout(res, ms));
@@ -55,7 +60,7 @@ describe('Starting Integration Test > Sending and Receiving ', function() {
5560
await testServer.stop();
5661
});
5762

58-
//TODO: enable testing for firefox
63+
// TODO: enable testing for firefox
5964
seleniumAssistant.getLocalBrowsers().forEach(assistantBrowser => {
6065
if (assistantBrowser.getId() !== 'chrome') {
6166
return;
@@ -72,7 +77,10 @@ describe('Starting Integration Test > Sending and Receiving ', function() {
7277
it('Background app can receive a {} empty message from sw', async function() {
7378
this.timeout(TIMEOUT_BACKGROUND_MESSAGE_TEST_UNIT_MILLISECONDS);
7479

75-
// Clearing the cache and db data by killing the previously instantiated driver. Note that ideally this call is placed inside the after/before hooks. However, Mocha forbids operations longer than 2s in hooks. Hence, this clearing call needs to be inside the test unit.
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.
7684
await seleniumAssistant.killWebDriver(globalWebDriver);
7785

7886
globalWebDriver = createPermittedWebDriver(
@@ -94,7 +102,8 @@ describe('Starting Integration Test > Sending and Receiving ', function() {
94102
checkMessageReceived(
95103
await getReceivedBackgroundMessages(globalWebDriver),
96104
/* expectedNotificationPayload= */ null,
97-
/* expectedDataPayload= */ null
105+
/* expectedDataPayload= */ null,
106+
/* isLegacyPayload= */ false
98107
);
99108
});
100109

@@ -137,9 +146,7 @@ describe('Starting Integration Test > Sending and Receiving ', function() {
137146
/* browser= */ assistantBrowser.getId()
138147
);
139148

140-
await globalWebDriver.get(
141-
`${testServer.serverAddress}/${TEST_DOMAIN}/`
142-
);
149+
await globalWebDriver.get(`${testServer.serverAddress}/${domain}/`);
143150

144151
let token = await retrieveToken(globalWebDriver);
145152
checkSendResponse(
@@ -164,9 +171,7 @@ describe('Starting Integration Test > Sending and Receiving ', function() {
164171
/* browser= */ assistantBrowser.getId()
165172
);
166173

167-
await globalWebDriver.get(
168-
`${testServer.serverAddress}/${TEST_DOMAIN}/`
169-
);
174+
await globalWebDriver.get(`${testServer.serverAddress}/${domain}/`);
170175

171176
checkSendResponse(
172177
await sendMessage({
@@ -191,9 +196,7 @@ describe('Starting Integration Test > Sending and Receiving ', function() {
191196
/* browser= */ assistantBrowser.getId()
192197
);
193198

194-
await globalWebDriver.get(
195-
`${testServer.serverAddress}/${TEST_DOMAIN}/`
196-
);
199+
await globalWebDriver.get(`${testServer.serverAddress}/${domain}/`);
197200

198201
checkSendResponse(
199202
await sendMessage({
@@ -218,9 +221,7 @@ describe('Starting Integration Test > Sending and Receiving ', function() {
218221
/* browser= */ assistantBrowser.getId()
219222
);
220223

221-
await globalWebDriver.get(
222-
`${testServer.serverAddress}/${TEST_DOMAIN}/`
223-
);
224+
await globalWebDriver.get(`${testServer.serverAddress}/${domain}/`);
224225

225226
checkSendResponse(
226227
await sendMessage({
@@ -250,7 +251,10 @@ function checkMessageReceived(
250251
const message = receivedMessages[0];
251252

252253
expect(message[FIELD_FROM]).to.equal(TEST_PROJECT_SENDER_ID);
253-
expect(message[FIELD_COLLAPSE_KEY]).to.equal(DEFAULT_COLLAPSE_KEY_VALUE);
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);
254258

255259
if (expectedNotificationPayload) {
256260
expect(message[FIELD_NOTIFICATION]).to.deep.equal(
@@ -285,13 +289,14 @@ function getTestDataPayload() {
285289
async function prepareBackgroundApp(globalWebDriver, domain) {
286290
await globalWebDriver.get(`${testServer.serverAddress}/${domain}/`);
287291

288-
// TODO: remove the try/catch block once the underlying bug has been resolved.
289-
// Shift window focus away from app window so that background messages can be received/processed
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
290294
try {
291295
await openNewTab(globalWebDriver);
292296
} catch (err) {
293-
// ChromeDriver seems to have an open bug which throws "JavascriptError: javascript error: circular reference".
294-
// Nevertheless, a new tab can still be opened. Hence, just catch and continue here.
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.
295300
console.log('FCM (ignored on purpose): ' + err);
296301
}
297302
}

integration/messaging/test/test-updateToken.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('Firebase Messaging Integration Tests > update a token', function() {
4343
});
4444

4545
const availableBrowsers = seleniumAssistant.getLocalBrowsers();
46-
//TODO: enable testing for edge and firefox if applicable
46+
// TODO: enable testing for edge and firefox if applicable
4747
availableBrowsers.forEach(assistantBrowser => {
4848
if (assistantBrowser.getId() !== 'chrome') {
4949
return;

integration/messaging/test/utils/getReceivedBackgroundMessages.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
const TEST_DB = 'FCM_INTEGRATION_TEST_DB';
1919
const BACKGROUND_MESSAGES_OBJECT_STORE = 'background_messages';
2020

21-
/** Getting received background messages are trickier than getting foreground messages from app. It requires idb object store creation with the service worker. Idb operations are fired as async events. This method needs to be called after the idb operations inside sw is done. In tests, consider adding a brief timeout before calling the method to give sw some time to work.
21+
/** Getting received background messages are trickier than getting foreground messages from app. It
22+
* requires idb object store creation with the service worker. Idb operations are fired as async
23+
* events. This method needs to be called after the idb operations inside sw is done. In tests,
24+
* consider adding a brief timeout before calling the method to give sw some time to work.
2225
*/
2326
module.exports = async webdriver => {
2427
console.log('Getting received background messages from idb: ');

integration/messaging/test/utils/sendMessage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
const fetch = require('node-fetch');
1919
const FCM_SEND_ENDPOINT = 'https://fcm.googleapis.com/fcm/send';
20-
// Rotatable fcm server key. It's generally a bad idea to expose server keys. The reason is to simplify testing process (no need to implement server side decryption of git secret). The justification is that a) this is a disposable test project b) the key itself is rotatable.
20+
// Rotatable fcm server key. It's generally a bad idea to expose server keys. The reason is to
21+
// simplify testing process (no need to implement server side decryption of git secret). The
22+
// justification is that a) this is a disposable test project b) the key itself is rotatable.
2123
const FCM_KEY =
2224
'AAAArtlRq60:APA91bHFulW1dBpIPbArYXPbFtO9M_a9ZNXhnj9hGArfGK55g8fv5s5Qset6984xRIrqhZ_3IlKcG9LgSk3DiTdHMDIOkxboNJquNK1SChC7J0ULTvHPg7t0V6AjR1UEA21DXI22BM5N';
2325

integration/messaging/test/utils/test-server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ class MessagingTestServer {
6161
});
6262
}
6363

64-
// Sometimes the server doesn't trigger the callback due to
65-
// currently open sockets. So call close this._server
64+
// Sometimes the server doesn't trigger the callback due to currently open sockets. So call close
65+
// this._server
6666
async stop() {
6767
if (this._server) {
6868
this._server.close();

0 commit comments

Comments
 (0)