Skip to content

Enable FCM Integration Test #3145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
dde3bfd
Enable the FCM integration test (IT) for Chrome.
Apr 14, 2020
099c76a
[AUTOMATED]: License Headers
Apr 14, 2020
14d38bc
Enable integration test (IT) for FCM.
zwu52 May 13, 2020
910e6a1
Correct int syntax
zwu52 May 13, 2020
b46f232
This file wasn't auto-saved
zwu52 May 13, 2020
1e68ca5
Trigger FCM IT
zwu52 May 15, 2020
b8ed1ba
Test Secrets can be accessed w/o dotenv
zwu52 May 15, 2020
37fb7c9
Add fcm sercret to workflow
zwu52 May 18, 2020
8d3e700
Update test-changed.yml
zwu52 May 18, 2020
cac7b80
test send (background only)
zwu52 May 18, 2020
5909104
remove dotenv
zwu52 May 18, 2020
2df79b5
feed secrest into test:all workflow
zwu52 May 19, 2020
fccb108
Update test-all.yml
zwu52 May 19, 2020
3ea2c73
background messaging checking
zwu52 May 21, 2020
81a84f0
[AUTOMATED]: License Headers
zwu52 May 21, 2020
9038d1a
rerun
zwu52 May 21, 2020
a1345e7
added waiting
zwu52 May 26, 2020
1bcab1c
wait
zwu52 May 26, 2020
75b5ba6
Update test-send.js
zwu52 May 26, 2020
36d2272
Update test-send.js
zwu52 May 26, 2020
8e7c27d
Examine wrong sercret
zwu52 May 27, 2020
976d3cd
Update sendMessage.js
zwu52 May 30, 2020
343af85
Update sendMessage.js
zwu52 Jun 1, 2020
0750f00
Update sendMessage.js
zwu52 Jun 1, 2020
068b173
Update sendMessage.js
zwu52 Jun 1, 2020
e3fcea3
Update sendMessage.js
zwu52 Jun 1, 2020
fdb4ca2
Merge branch 'master' into test
zwu52 Jun 2, 2020
b60d010
update fcm project
zwu52 Jun 2, 2020
3acc255
Update package.json
zwu52 Jun 2, 2020
4f12ef8
Update test-send.js
zwu52 Jun 3, 2020
1d2368c
open new tab for backgournd receive
zwu52 Jun 8, 2020
6ab745f
removed test-send
zwu52 Jun 9, 2020
4c5e360
Adding Reties
zwu52 Jun 10, 2020
2f9b9bc
Change timeout limit
zwu52 Jun 10, 2020
4775b91
retry 3 times
zwu52 Jun 10, 2020
1e54408
adjust mocha setting
zwu52 Jun 11, 2020
5753fa5
update
zwu52 Jun 11, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions integration/messaging/download-browsers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2017 Google Inc.
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,14 +18,9 @@
const seleniumAssistant = require('selenium-assistant');

console.log('Starting browser download - this may take some time.');
Promise.all([
seleniumAssistant.downloadLocalBrowser('chrome', 'stable', 48),
seleniumAssistant.downloadLocalBrowser('chrome', 'beta', 48),
seleniumAssistant.downloadLocalBrowser('chrome', 'unstable', 48),
seleniumAssistant.downloadLocalBrowser('firefox', 'stable', 48),
seleniumAssistant.downloadLocalBrowser('firefox', 'beta', 48),
seleniumAssistant.downloadLocalBrowser('firefox', 'unstable', 48)
])
// TODO: enable firefox testing once figure out how to give notification permission with SE webdriver.
// TODO: Run the integration test against multiple major chrome versions to ensure backward compatibility
Promise.all([seleniumAssistant.downloadLocalBrowser('chrome', 'stable', 80)])
.then(() => {
console.log('Browser download complete.');
})
Expand Down
4 changes: 2 additions & 2 deletions integration/messaging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"version": "0.2.1",
"scripts": {
"pretest:manual": "node ./download-browsers.js",
"test": "echo 'Tests disabled due to flakiness'",
"test": "mocha --exit",
"test:manual": "mocha --exit"
},
"dependencies": {
"firebase": "7.14.6"
},
"devDependencies": {
"chai": "4.2.0",
"chromedriver": "80.0.2",
"chromedriver": "^83.0.0",
"express": "4.17.1",
"geckodriver": "1.19.1",
"mocha": "7.1.2",
Expand Down
60 changes: 36 additions & 24 deletions integration/messaging/test/static/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2017 Google Inc.
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,8 +15,6 @@
* limitations under the License.
*/

const EIGHT_DAYS_IN_MS = 8 * 86400000;

/**
* This class just wraps the expected behavior or a demo app that will
* be orchestrated by selenium tests (Although manual use of the demo will
Expand All @@ -36,40 +34,49 @@ class DemoApp {
this._triggerDeleteToken = this.triggerDeleteToken;
this._triggerGetToken = this.triggerGetToken;
this._triggerTimeForward = this.triggerTimeForward;
this._clearInstanceForTest = this.clearInstanceForTest;
this.appendMessage = this.appendMessage;

// Initialize Firebase
firebase.initializeApp(firebaseConfig);

this._messaging = firebase.messaging();

if (options.applicationKey) {
this._messaging.usePublicVapidKey(options.applicationKey);
if (options.vapidKey) {
console.debug('VapidKey is provided to the test app. ');
this._messaging.usePublicVapidKey(options.vapidKey);
} else {
console.debug('VapidKey is not specified. Skip setting it');
}

if (options.swReg) {
console.debug('ServiceWorker is provided to the test app');
this._messaging.useServiceWorker(options.swReg);
} else {
console.debug(
'ServiceWorker is not specified. The default ServiceWorker will be used.'
);
}

this._messaging.onMessage(payload => {
console.log(`Message received: `, payload);
this._messages.push(payload);
this._messaging.onMessage(message => {
this.appendMessage(message);
});

// Initializa state of token
this._messaging
.requestPermission()
.then(() => this._messaging.getToken())
.then(
token => {
console.log('getToken() worked: ', token);
this._token = token;
},
err => {
console.log('getToken() failed: ', err.message, err.stack);
this._errors.push(err);
this._token = null;
}
);
this._messaging.getToken().then(
token => {
console.log('Test app getToken() succeed. Token: ', token);
this._token = token;
},
err => {
console.log('Test app getToken() failed: ', err.message, err.stack);
this._errors.push(err);
this._token = null;
}
);
}

appendMessage(payload) {
this._messages.push(payload);
}

async triggerDeleteToken(token) {
Expand All @@ -95,10 +102,15 @@ class DemoApp {
return this._token;
}

async triggerTimeForward() {
triggerTimeForward() {
this._clock.tick(EIGHT_DAYS_IN_MS);
}

clearInstanceForTest() {
this._errors = [];
this._messages = [];
}

get token() {
return this._token;
}
Expand Down
35 changes: 35 additions & 0 deletions integration/messaging/test/static/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Test project managed by the FCM team
const PUBLIC_VAPID_KEY =
'BNjjus3nz38aYtbDLVfunY3VULg0Yq5T4GXWd7iDDmeqWCUNqfrK1eiKVdoT0VncLuCjfJ1GmdfmNZz-AjHfkxM';
const FIREBASE_CONFIG = {
apiKey: 'AIzaSyBpIe0xyUNHOwtE_go32NmUJF4acsc6S6c',
projectId: 'fcm-web-sdk-test',
messagingSenderId: '750970317741',
appId: '1:750970317741:web:f382be3155e250906a4f24'
};

const TAG = 'FCM_INTEGRATION_TEST: ';
const EIGHT_DAYS_IN_MS = 8 * 86400000;
const TEST_DB = 'FCM_INTEGRATION_TEST_DB';
const TEST_DB_VERSION = 1;
const BACKGROUND_MESSAGES_OBJECT_STORE = 'background_messages';
// indexDb object store creation require a "primary key", "ndx" is used.
const BACKGROUND_MESSAGES_OBJECT_STORE_PRIMARY_KEY = 'ndx';
const BACKGROUND_MESSAGES_OBJECT_STORE_DEFAULT_NDX = 'default_ndx';
34 changes: 18 additions & 16 deletions integration/messaging/test/static/default-sw/index.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<html>
<head>
<title>FCM Demo</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
<h1>Default SW</h1>
<script src="/firebase/firebase-app.js"></script>
<script src="/firebase/firebase-messaging.js"></script>
<script src="/app.js"></script>
<script src="../valid-no-vapid-key/firebaseConfig.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sinon.js/4.1.3/sinon.min.js"></script>
<script>
window.__test = new window.DemoApp(window.firebaseConfig);
</script>
</body>
</html>
<head>
<title>FCM Demo</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
</head>
<body>
<h1>Default SW</h1>
<script src="/firebase-app.js"></script>
<script src="/firebase-messaging.js"></script>
<script src="../app.js"></script>
<script src="../constants.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sinon.js/4.1.3/sinon.min.js"></script>
<script>
window.__test = new window.DemoApp(FIREBASE_CONFIG, {
vapidKey: PUBLIC_VAPID_KEY
});
</script>
</body>
</html>
13 changes: 2 additions & 11 deletions integration/messaging/test/static/firebase-messaging-sw.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2017 Google Inc.
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,13 +15,4 @@
* limitations under the License.
*/

importScripts('/sw-shared.js');
importScripts('/valid-no-vapid-key/firebaseConfig.js');

firebase.initializeApp(self.firebaseConfig);

const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(data => {
const title = 'Background Notification';
return self.registration.showNotification(title, {});
});
importScripts('./sw-base.js');
18 changes: 0 additions & 18 deletions integration/messaging/test/static/invalid-manifest/index.html

This file was deleted.

This file was deleted.

71 changes: 71 additions & 0 deletions integration/messaging/test/static/sw-base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

importScripts('../constants.js');

// HEAD targets served through express
importScripts('/firebase-app.js');
importScripts('/firebase-messaging.js');

firebase.initializeApp(FIREBASE_CONFIG);
const messaging = firebase.messaging();

messaging.setBackgroundMessageHandler(payload => {
console.log(
TAG +
'a background message is received: ' +
JSON.stringify(payload) +
'. Storing it into idb for tests to read...'
);

addPayloadToDb(payload);
});

async function addPayloadToDb(payload) {
const dbOpenReq = indexedDB.open(TEST_DB);

dbOpenReq.onupgradeneeded = () => {
const db = dbOpenReq.result;

// store creation is a synchronized call
console.log('creating object store...');
db.createObjectStore(BACKGROUND_MESSAGES_OBJECT_STORE, {
keyPath: BACKGROUND_MESSAGES_OBJECT_STORE_PRIMARY_KEY
});
};

dbOpenReq.onsuccess = () => {
const db = dbOpenReq.result;

addPayloadToDbInternal(db, {
...payload,
// ndx is required as the primary key of the store. It doesn't have any other testing purpose
ndx: BACKGROUND_MESSAGES_OBJECT_STORE_DEFAULT_NDX
});
};
}

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

tx = db.transaction(BACKGROUND_MESSAGES_OBJECT_STORE, 'readwrite');

console.log('adding message payload to db: ' + JSON.stringify(payload));
addReq = tx.objectStore(BACKGROUND_MESSAGES_OBJECT_STORE).add(payload);
}
34 changes: 17 additions & 17 deletions integration/messaging/test/static/valid-manifest/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<html>
<head>
<title>FCM Demo</title>
<link rel="manifest" href="./manifest.json">
<meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
<h1>Valid Manifest</h1>
<script src="/firebase/firebase-app.js"></script>
<script src="/firebase/firebase-messaging.js"></script>
<script src="/app.js"></script>
<script src="../valid-no-vapid-key/firebaseConfig.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sinon.js/4.1.3/sinon.min.js"></script>
<script>
window.__test = new window.DemoApp(window.firebaseConfig);
</script>
</body>
</html>
<head>
<title>FCM Demo</title>
<link rel="manifest" href="./manifest.json" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
</head>
<body>
<h1>Valid Manifest</h1>
<script src="/firebase-app.js"></script>
<script src="/firebase-messaging.js"></script>
<script src="../app.js"></script>
<script src="../constants.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sinon.js/4.1.3/sinon.min.js"></script>
<script>
window.__test = new window.DemoApp(FIREBASE_CONFIG, {});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"gcm_sender_id": "103953800507"
"gcm_sender_id": "750970317741"
}
Loading