Skip to content
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

Issue 2393 - Add environment check to Performance Module #3424

Merged
merged 33 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5afb588
issue #2393, first fix on performance module and remote-config module
XuechunHou Jun 2, 2020
cff6383
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk
XuechunHou Jun 2, 2020
75646d9
added error handler to remote-config and performance modules on index…
XuechunHou Jun 2, 2020
e63607a
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk
XuechunHou Jun 2, 2020
f63a3e5
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou Jun 4, 2020
4307ee5
issue #2393 fix for analytics module
XuechunHou Jun 4, 2020
0843a6e
updateDoc()/deleteDoc() signature fix (#3147)
schmidt-sebastian Jun 2, 2020
0c426c3
Transaction/WriteBatch signature fix (#3151)
schmidt-sebastian Jun 2, 2020
fd0c0a3
Take WriteStream offline when IndexedDB is unavailable (#2995)
schmidt-sebastian Jun 2, 2020
9512b48
Do not build firestore lite in build because it breaks regular releas…
Feiyang1 Jun 3, 2020
b5c7b78
add pre script for build:release (#3161)
Feiyang1 Jun 3, 2020
e10388c
Add setLogLevel() (#3154)
schmidt-sebastian Jun 3, 2020
3ac0fe3
Add DocumentReference (#3123)
schmidt-sebastian Jun 3, 2020
a377c68
issue #2393 fix for analytics module
XuechunHou Jun 4, 2020
8b20b49
Merge branch 'issue-2393-analytics' of https://github.com/XuechunHou/…
XuechunHou Jun 4, 2020
5bae362
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk
XuechunHou Jun 26, 2020
1cac9fa
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk
XuechunHou Jul 16, 2020
5db434a
added isSupported method to performance module
XuechunHou Jul 16, 2020
cdb438f
added isSupported method and indexedDB check in performance module
XuechunHou Jul 16, 2020
25c19b8
added method signature to firebase/index.d.ts
XuechunHou Jul 16, 2020
d57d086
reverted unrelated files in remote-config
XuechunHou Jul 16, 2020
9a15fa5
Create little-cycles-fold.md
XuechunHou Jul 16, 2020
8efeefe
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou Jul 22, 2020
0eb394f
removed isSupported method from performance
XuechunHou Jul 22, 2020
a6f0f2e
Merge branch 'issue-2393-performance' of https://github.com/firebase/…
XuechunHou Jul 22, 2020
712b5d2
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou Jul 26, 2020
a3aeb6c
wrote tests for requiredApisAvailable
XuechunHou Jul 26, 2020
1455b4e
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou Aug 3, 2020
65d7b6d
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou Aug 3, 2020
dc23631
updated isRequiredApiAvailable tests, updated logTrace function to re…
XuechunHou Aug 4, 2020
faa05bd
added Promise existence check before every test of requiredApisAvailable
XuechunHou Aug 5, 2020
e012877
took validateIndexedDBOpenable outside of isRequiredApisAvailable
XuechunHou Aug 5, 2020
f558aa0
updated performance constructor test
XuechunHou Aug 6, 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
6 changes: 6 additions & 0 deletions .changeset/little-cycles-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"firebase": minor
"@firebase/performance": minor
---

Issue 2393 - Add environment check to Performance Module
1 change: 0 additions & 1 deletion packages/performance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { ERROR_FACTORY, ErrorCode } from './src/utils/errors';
import { FirebasePerformance } from '@firebase/performance-types';
import { Component, ComponentType } from '@firebase/component';
import { FirebaseInstallations } from '@firebase/installations-types';

import { name, version } from './package.json';

const DEFAULT_ENTRY_NAME = '[DEFAULT]';
Expand Down
32 changes: 29 additions & 3 deletions packages/performance/src/controllers/perf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Trace } from '../resources/trace';
import { Api, setupApi } from '../services/api_service';
import { FirebaseApp } from '@firebase/app-types';
import * as initializationService from '../services/initialization_service';
import * as FirebaseUtil from '@firebase/util';
import { consoleLogger } from '../utils/console_logger';
import '../../test/setup';

Expand All @@ -46,11 +47,36 @@ describe('Firebase Performance Test', () => {
it('does not initialize performance if the required apis are not available', () => {
stub(Api.prototype, 'requiredApisAvailable').returns(false);
stub(initializationService, 'getInitializationPromise');
stub(consoleLogger, 'info');
new PerformanceController(fakeFirebaseApp);

expect(initializationService.getInitializationPromise).not.be.called;
expect(consoleLogger.info).be.called;
});
it('does not initialize performance if validateIndexedDBOpenable return false', async () => {
stub(Api.prototype, 'requiredApisAvailable').returns(true);
const validateStub = stub(
FirebaseUtil,
'validateIndexedDBOpenable'
).resolves(false);
stub(initializationService, 'getInitializationPromise');
new PerformanceController(fakeFirebaseApp);
await validateStub;
expect(initializationService.getInitializationPromise).not.be.called;
});

it('does not initialize performance if validateIndexedDBOpenable throws an error', async () => {
stub(Api.prototype, 'requiredApisAvailable').returns(true);
const validateStub = stub(
FirebaseUtil,
'validateIndexedDBOpenable'
).rejects();

stub(initializationService, 'getInitializationPromise');
stub(consoleLogger, 'info');
new PerformanceController(fakeFirebaseApp);
try {
await validateStub;
expect(initializationService.getInitializationPromise).not.be.called;
expect(consoleLogger.info).be.called;
} catch (ignored) {}
});
});

Expand Down
23 changes: 15 additions & 8 deletions packages/performance/src/controllers/perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,25 @@ import { getInitializationPromise } from '../services/initialization_service';
import { Api } from '../services/api_service';
import { FirebaseApp } from '@firebase/app-types';
import { FirebasePerformance } from '@firebase/performance-types';
import { consoleLogger } from '../utils/console_logger';
import { setupTransportService } from '../services/transport_service';

import { validateIndexedDBOpenable } from '@firebase/util';
import { consoleLogger } from '../utils/console_logger';
export class PerformanceController implements FirebasePerformance {
constructor(readonly app: FirebaseApp) {
if (Api.getInstance().requiredApisAvailable()) {
setupTransportService();
getInitializationPromise().then(setupOobResources, setupOobResources);
} else {
consoleLogger.info(
'Firebase Performance cannot start if browser does not support fetch and Promise or cookie is disabled.'
);
validateIndexedDBOpenable()
.then(isAvailable => {
if (isAvailable) {
setupTransportService();
getInitializationPromise().then(
setupOobResources,
setupOobResources
);
}
})
.catch(error => {
consoleLogger.info(`Environment doesn't support IndexedDB: ${error}`);
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/performance/src/services/api_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { stub } from 'sinon';
import { expect } from 'chai';
import { Api, setupApi } from './api_service';
import '../../test/setup';

describe('Firebase Performance > api_service', () => {
const PAGE_URL = 'http://www.test.com/abcd?a=2';
const PERFORMANCE_ENTRY: PerformanceEntry = {
Expand Down Expand Up @@ -47,6 +46,7 @@ describe('Firebase Performance > api_service', () => {
]);
// This is to make sure the test page is not changed by changing the href of location object.
mockWindow.location = { ...self.location, href: PAGE_URL };

setupApi(mockWindow);
api = Api.getInstance();
});
Expand Down
22 changes: 18 additions & 4 deletions packages/performance/src/services/api_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/

import { ERROR_FACTORY, ErrorCode } from '../utils/errors';

import { isIndexedDBAvailable } from '@firebase/util';
import { consoleLogger } from '../utils/console_logger';
declare global {
interface Window {
PerformanceObserver: typeof PerformanceObserver;
Expand Down Expand Up @@ -110,10 +111,23 @@ export class Api {
}

requiredApisAvailable(): boolean {
if (fetch && Promise && this.navigator && this.navigator.cookieEnabled) {
return true;
if (
!fetch ||
!Promise ||
!this.navigator ||
!this.navigator.cookieEnabled
) {
consoleLogger.info(
'Firebase Performance cannot start if browser does not support fetch and Promise or cookie is disabled.'
);
return false;
}

if (!isIndexedDBAvailable()) {
consoleLogger.info('IndexedDB is not supported by current browswer');
return false;
}
return false;
return true;
}

setupObserver(
Expand Down
1 change: 1 addition & 0 deletions packages/performance/src/services/perf_logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export function logTrace(trace: Trace): void {
if (!Api.getInstance().requiredApisAvailable()) {
return;
}

// Only log the page load auto traces if page is visible.
if (trace.isAuto && getVisibilityState() !== VisibilityState.VISIBLE) {
return;
Expand Down