Skip to content

Commit f78a559

Browse files
committed
Merge branch 'master' into ch-index-types
2 parents 03004a3 + 3aa0b36 commit f78a559

Some content is hidden

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

53 files changed

+849
-295
lines changed

common/api-review/auth-exp.api.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export interface Auth {
8686
readonly emulatorConfig: EmulatorConfig | null;
8787
languageCode: string | null;
8888
readonly name: string;
89-
// Warning: (ae-forgotten-export) The symbol "NextOrObserver" needs to be exported by the entry point index.d.ts
9089
onAuthStateChanged(nextOrObserver: NextOrObserver<User | null>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;
9190
onIdTokenChanged(nextOrObserver: NextOrObserver<User | null>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;
9291
setPersistence(persistence: Persistence): Promise<void>;
@@ -153,6 +152,8 @@ export const browserSessionPersistence: Persistence;
153152
// @public
154153
export function checkActionCode(auth: Auth, oobCode: string): Promise<ActionCodeInfo>;
155154

155+
export { CompleteFn }
156+
156157
// @public
157158
export interface Config {
158159
apiHost: string;
@@ -184,6 +185,16 @@ export const debugErrorMap: AuthErrorMap;
184185
// @public
185186
export function deleteUser(user: User): Promise<void>;
186187

188+
// @public (undocumented)
189+
export interface Dependencies {
190+
// (undocumented)
191+
errorMap?: AuthErrorMap;
192+
// (undocumented)
193+
persistence?: Persistence | Persistence[];
194+
// (undocumented)
195+
popupRedirectResolver?: PopupRedirectResolver;
196+
}
197+
187198
// @public
188199
export class EmailAuthCredential extends AuthCredential {
189200
// (undocumented)
@@ -216,6 +227,8 @@ export class EmailAuthProvider implements AuthProvider {
216227
readonly providerId = ProviderId.PASSWORD;
217228
}
218229

230+
export { ErrorFn }
231+
219232
// Warning: (ae-forgotten-export) The symbol "BaseOAuthProvider" needs to be exported by the entry point index.d.ts
220233
//
221234
// @public
@@ -248,10 +261,8 @@ export function getIdToken(user: User, forceRefresh?: boolean): Promise<string>;
248261
// @public
249262
export function getIdTokenResult(user: User, forceRefresh?: boolean): Promise<IdTokenResult>;
250263

251-
// Warning: (ae-forgotten-export) The symbol "MultiFactorError" needs to be exported by the entry point index.d.ts
252-
//
253264
// @public
254-
export function getMultiFactorResolver(auth: Auth, error: MultiFactorError_2): MultiFactorResolver;
265+
export function getMultiFactorResolver(auth: Auth, error: MultiFactorError): MultiFactorResolver;
255266

256267
// @public
257268
export function getRedirectResult(auth: Auth, resolver?: PopupRedirectResolver): Promise<UserCredential | null>;
@@ -290,8 +301,6 @@ export interface IdTokenResult {
290301
// @public
291302
export const indexedDBLocalPersistence: Persistence;
292303

293-
// Warning: (ae-forgotten-export) The symbol "Dependencies" needs to be exported by the entry point index.d.ts
294-
//
295304
// @public (undocumented)
296305
export function initializeAuth(app: FirebaseApp, deps?: Dependencies): Auth;
297306

@@ -353,6 +362,9 @@ export interface MultiFactorUser {
353362
unenroll(option: MultiFactorInfo | string): Promise<void>;
354363
}
355364

365+
// @public
366+
export type NextOrObserver<T> = NextFn<T | null> | Observer<T | null>;
367+
356368
// @public
357369
export class OAuthCredential extends AuthCredential {
358370
accessToken?: string;
@@ -645,6 +657,8 @@ export class TwitterAuthProvider extends BaseOAuthProvider {
645657
// @public
646658
export function unlink(user: User, providerId: ProviderId): Promise<User>;
647659

660+
export { Unsubscribe }
661+
648662
// @public
649663
export function updateCurrentUser(auth: Auth, user: User | null): Promise<void>;
650664

common/api-review/messaging-exp.api.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
```ts
66

7-
import { FirebaseApp } from '@firebase/app-exp';
7+
import { FirebaseApp } from '@firebase/app';
88
import { NextFn } from '@firebase/util';
99
import { Observer } from '@firebase/util';
1010
import { Unsubscribe } from '@firebase/util';
@@ -52,6 +52,8 @@ export interface MessagePayload {
5252
notification?: NotificationPayload;
5353
}
5454

55+
export { NextFn }
56+
5557
// @public
5658
export interface NotificationPayload {
5759
// (undocumented)
@@ -62,6 +64,8 @@ export interface NotificationPayload {
6264
title?: string;
6365
}
6466

67+
export { Observer }
68+
6569
// Warning: (ae-internal-missing-underscore) The name "onBackgroundMessage" should be prefixed with an underscore because the declaration is marked as @internal
6670
//
6771
// @internal
@@ -70,6 +74,8 @@ export function onBackgroundMessage(messaging: FirebaseMessaging, nextOrObserver
7074
// @public
7175
export function onMessage(messaging: FirebaseMessaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
7276

77+
export { Unsubscribe }
78+
7379

7480
// (No @packageDocumentation comment for this package)
7581

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/**
2+
* @license
3+
* Copyright 2017 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+
const testServer = require('./utils/test-server');
19+
const sendMessage = require('./utils/sendMessage');
20+
const retrieveToken = require('./utils/retrieveToken');
21+
const seleniumAssistant = require('selenium-assistant');
22+
const getReceivedBackgroundMessages = require('./utils/getReceivedBackgroundMessages');
23+
const createPermittedWebDriver = require('./utils/createPermittedWebDriver');
24+
const checkSendResponse = require('./utils/checkSendResponse');
25+
const checkMessageReceived = require('./utils/checkMessageReceived');
26+
const openNewTab = require('./utils/openNewTab');
27+
28+
const TEST_DOMAINS = ['valid-vapid-key-modern-sw'];
29+
30+
// 4 minutes. The fact that the flow includes making a request to the Send Service,
31+
// storing/retrieving form indexedDb asynchronously makes these test units to have a execution time
32+
// variance. Therefore, allowing these units to have a longer time to work is crucial.
33+
const TIMEOUT_BACKGROUND_MESSAGE_TEST_UNIT_MILLISECONDS = 240000;
34+
35+
// 1 minute. Wait for object store to be created and received message to be stored in idb. This
36+
// waiting time MUST be longer than the wait time for adding to db in the sw.
37+
const WAIT_TIME_BEFORE_RETRIEVING_BACKGROUND_MESSAGES_MILLISECONDS = 60000;
38+
39+
const wait = ms => new Promise(res => setTimeout(res, ms));
40+
41+
// 50% of integration test run time is spent in testing receiving in background. Running these
42+
// slower tests last so other tests can fail quickly if they do fail.
43+
require('./test-token-delete');
44+
require('./test-token-update');
45+
require('./test-useValidManifest');
46+
require('./test-useDefaultServiceWorker');
47+
require('./test-receive-foreground');
48+
49+
describe('Firebase Messaging Integration Tests > Test Background Receive', function () {
50+
this.retries(2);
51+
let globalWebDriver;
52+
53+
before(async function () {
54+
await testServer.start();
55+
});
56+
57+
after(async function () {
58+
await testServer.stop();
59+
});
60+
61+
// TODO: enable testing for firefox
62+
seleniumAssistant.getLocalBrowsers().forEach(assistantBrowser => {
63+
if (assistantBrowser.getId() !== 'chrome') {
64+
return;
65+
}
66+
67+
TEST_DOMAINS.forEach(domain => {
68+
describe(`Testing browser: ${assistantBrowser.getPrettyName()} : ${domain}`, function () {
69+
before(async function () {
70+
globalWebDriver = createPermittedWebDriver(
71+
/* browser= */ assistantBrowser.getId()
72+
);
73+
});
74+
75+
it('Background app can receive a {} empty message from sw', async function () {
76+
this.timeout(TIMEOUT_BACKGROUND_MESSAGE_TEST_UNIT_MILLISECONDS);
77+
78+
// Clearing the cache and db data by killing the previously instantiated driver. Note that
79+
// ideally this call is placed inside the after/before hooks. However, Mocha forbids
80+
// operations longer than 2s in hooks. Hence, this clearing call needs to be inside the
81+
// test unit.
82+
await seleniumAssistant.killWebDriver(globalWebDriver);
83+
84+
globalWebDriver = createPermittedWebDriver(
85+
/* browser= */ assistantBrowser.getId()
86+
);
87+
88+
prepareBackgroundApp(globalWebDriver, domain);
89+
90+
checkSendResponse(
91+
await sendMessage({
92+
to: await retrieveToken(globalWebDriver)
93+
})
94+
);
95+
96+
await wait(
97+
WAIT_TIME_BEFORE_RETRIEVING_BACKGROUND_MESSAGES_MILLISECONDS
98+
);
99+
100+
checkMessageReceived(
101+
await getReceivedBackgroundMessages(globalWebDriver),
102+
/* expectedNotificationPayload= */ null,
103+
/* expectedDataPayload= */ null,
104+
/* isLegacyPayload= */ false
105+
);
106+
});
107+
108+
it('Background app can receive a {"data"} message frow sw', async function () {
109+
this.timeout(TIMEOUT_BACKGROUND_MESSAGE_TEST_UNIT_MILLISECONDS);
110+
111+
await seleniumAssistant.killWebDriver(globalWebDriver);
112+
113+
globalWebDriver = createPermittedWebDriver(
114+
/* browser= */ assistantBrowser.getId()
115+
);
116+
117+
prepareBackgroundApp(globalWebDriver, domain);
118+
119+
checkSendResponse(
120+
await sendMessage({
121+
to: await retrieveToken(globalWebDriver),
122+
data: getTestDataPayload()
123+
})
124+
);
125+
126+
await wait(
127+
WAIT_TIME_BEFORE_RETRIEVING_BACKGROUND_MESSAGES_MILLISECONDS
128+
);
129+
130+
checkMessageReceived(
131+
await getReceivedBackgroundMessages(globalWebDriver),
132+
/* expectedNotificationPayload= */ null,
133+
/* expectedDataPayload= */ getTestDataPayload()
134+
);
135+
});
136+
});
137+
});
138+
});
139+
});
140+
141+
async function prepareBackgroundApp(globalWebDriver, domain) {
142+
await globalWebDriver.get(`${testServer.serverAddress}/${domain}/`);
143+
// TODO: remove the try/catch block once the underlying bug has been resolved. Shift window focus
144+
// away from app window so that background messages can be received/processed
145+
try {
146+
await openNewTab(globalWebDriver);
147+
} catch (err) {
148+
// ChromeDriver seems to have an open bug which throws "JavascriptError: javascript error:
149+
// circular reference". Nevertheless, a new tab can still be opened. Hence, just catch and
150+
// continue here.
151+
console.log('FCM (ignored on purpose): ' + err);
152+
}
153+
}
154+
155+
function getTestDataPayload() {
156+
return { hello: 'world' };
157+
}

0 commit comments

Comments
 (0)