Skip to content

Commit 93d6d22

Browse files
authored
Merge 374dc78 into 46fd70b
2 parents 46fd70b + 374dc78 commit 93d6d22

Some content is hidden

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

47 files changed

+1435
-688
lines changed

.changeset/strange-crabs-tell.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'firebase': minor
3+
'@firebase/messaging': minor,
4+
'@firebase/messaging-types': minor
5+
---
6+
7+
Add `getToken(options:{serviceWorkerRegistration, vapidKey})`,`onBackgroundMessage`.
8+
Deprecate `setBackgroundMessageHandler`, `onTokenRefresh`, `useVapidKey`, `useServiceWorker`, `getToken`.
9+
10+
Add Typing `MessagePayload`, `NotificationPayload`, `FcmOptions`.

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.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
async function addPayloadToDb(payload) {
19+
const dbOpenReq = indexedDB.open(TEST_DB);
20+
21+
dbOpenReq.onupgradeneeded = () => {
22+
const db = dbOpenReq.result;
23+
24+
// store creation is a synchronized call
25+
console.log('creating object store...');
26+
db.createObjectStore(BACKGROUND_MESSAGES_OBJECT_STORE, {
27+
keyPath: BACKGROUND_MESSAGES_OBJECT_STORE_PRIMARY_KEY
28+
});
29+
};
30+
31+
dbOpenReq.onsuccess = () => {
32+
const db = dbOpenReq.result;
33+
34+
addPayloadToDbInternal(db, {
35+
...payload,
36+
// ndx is required as the primary key of the store. It doesn't have any other testing purpose
37+
ndx: BACKGROUND_MESSAGES_OBJECT_STORE_DEFAULT_NDX
38+
});
39+
};
40+
}
41+
42+
async function addPayloadToDbInternal(db, payload) {
43+
// onsuccess might race with onupgradeneeded. Consequently causing "object stores was not found"
44+
// error. Therefore, wait briefly for db.createObjectStore to complete
45+
const delay = ms => new Promise(res => setTimeout(res, ms));
46+
await delay(/* milliseconds= */ 30000);
47+
48+
tx = db.transaction(BACKGROUND_MESSAGES_OBJECT_STORE, 'readwrite');
49+
50+
console.log('adding message payload to db: ' + JSON.stringify(payload));
51+
addReq = tx.objectStore(BACKGROUND_MESSAGES_OBJECT_STORE).add(payload);
52+
}

integration/messaging/test/static/sw-base.js

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
importScripts('../constants.js');
19+
importScripts('../helpers.js');
1920

2021
// HEAD targets served through express
2122
importScripts('/firebase-app.js');
@@ -27,45 +28,10 @@ const messaging = firebase.messaging();
2728
messaging.setBackgroundMessageHandler(payload => {
2829
console.log(
2930
TAG +
30-
'a background message is received: ' +
31+
'a background message is received in the background handler hook: ' +
3132
JSON.stringify(payload) +
3233
'. Storing it into idb for tests to read...'
3334
);
3435

3536
addPayloadToDb(payload);
3637
});
37-
38-
async function addPayloadToDb(payload) {
39-
const dbOpenReq = indexedDB.open(TEST_DB);
40-
41-
dbOpenReq.onupgradeneeded = () => {
42-
const db = dbOpenReq.result;
43-
44-
// store creation is a synchronized call
45-
console.log('creating object store...');
46-
db.createObjectStore(BACKGROUND_MESSAGES_OBJECT_STORE, {
47-
keyPath: BACKGROUND_MESSAGES_OBJECT_STORE_PRIMARY_KEY
48-
});
49-
};
50-
51-
dbOpenReq.onsuccess = () => {
52-
const db = dbOpenReq.result;
53-
54-
addPayloadToDbInternal(db, {
55-
...payload,
56-
// ndx is required as the primary key of the store. It doesn't have any other testing purpose
57-
ndx: BACKGROUND_MESSAGES_OBJECT_STORE_DEFAULT_NDX
58-
});
59-
};
60-
}
61-
62-
async function addPayloadToDbInternal(db, payload) {
63-
// onsuccess might race with onupgradeneeded. Consequently causing " object stores was not found" error. Therefore, wait briefly for db.createObjectStore to complete
64-
const delay = ms => new Promise(res => setTimeout(res, ms));
65-
await delay(/* milliseconds= */ 30000);
66-
67-
tx = db.transaction(BACKGROUND_MESSAGES_OBJECT_STORE, 'readwrite');
68-
69-
console.log('adding message payload to db: ' + JSON.stringify(payload));
70-
addReq = tx.objectStore(BACKGROUND_MESSAGES_OBJECT_STORE).add(payload);
71-
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<html>
2+
<head>
3+
<title>FCM Demo</title>
4+
<meta name="viewport" content="width=device-width,initial-scale=1" />
5+
</head>
6+
<body>
7+
<h1>Valid <strong>WITH</strong> VAPID Key - Modern SW</h1>
8+
9+
<script src="/firebase-app.js"></script>
10+
<script src="/firebase-messaging.js"></script>
11+
<script src="../app.js"></script>
12+
<script src="../constants.js"></script>
13+
<script src="https://cdnjs.cloudflare.com/ajax/libs/sinon.js/4.1.3/sinon.min.js"></script>
14+
<script>
15+
navigator.serviceWorker
16+
.register('./sw.js')
17+
.then(reg => {
18+
window.__test = new window.DemoApp(FIREBASE_CONFIG, {
19+
swReg: reg,
20+
vapidKey: PUBLIC_VAPID_KEY
21+
});
22+
})
23+
.catch(error => {
24+
console.log('Error registering FCM SW: ' + error);
25+
});
26+
</script>
27+
</body>
28+
</html>

packages/messaging/src/interfaces/internal-message.ts renamed to integration/messaging/test/static/valid-vapid-key-modern-sw/sw.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,23 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { MessagePayload } from './message-payload';
18+
importScripts('../constants.js');
19+
importScripts('../helpers.js');
1920

20-
export enum MessageType {
21-
PUSH_RECEIVED = 'push-received',
22-
NOTIFICATION_CLICKED = 'notification-clicked'
23-
}
21+
// HEAD targets served through express
22+
importScripts('/firebase-app.js');
23+
importScripts('/firebase-messaging.js');
2424

25-
export interface InternalMessage {
26-
firebaseMessaging: {
27-
type: MessageType;
28-
payload: MessagePayload;
29-
};
30-
}
25+
firebase.initializeApp(FIREBASE_CONFIG);
26+
const messaging = firebase.messaging();
27+
28+
messaging.onBackgroundMessage(payload => {
29+
console.log(
30+
TAG +
31+
'a background message is received in the onBackgroundMessage hook: ' +
32+
JSON.stringify(payload) +
33+
'. Storing it into idb for tests to read...'
34+
);
35+
36+
addPayloadToDb(payload);
37+
});

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
}

0 commit comments

Comments
 (0)