Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const SENDER_ID_OPTION_NAME = 'messagingSenderId';
// Database cache should be invalidated once a week.
export const TOKEN_EXPIRATION_MILLIS = 7 * 24 * 60 * 60 * 1000; // 7 days

export abstract class ControllerInterface implements FirebaseMessaging {
export abstract class BaseController implements FirebaseMessaging {
app: FirebaseApp;
INTERNAL: FirebaseServiceInternals;
private readonly messagingSenderId: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/messaging/src/controllers/sw-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import {
MessageParameter,
MessageType
} from '../models/worker-page-message';
import { BgMessageHandler, ControllerInterface } from './controller-interface';
import { BaseController, BgMessageHandler } from './base-controller';

// Let TS know that this is a service worker
declare const self: ServiceWorkerGlobalScope;

const FCM_MSG = 'FCM_MSG';

export class SwController extends ControllerInterface {
export class SwController extends BaseController {
private bgMessageHandler: BgMessageHandler | null = null;

constructor(app: FirebaseApp) {
Expand Down
4 changes: 2 additions & 2 deletions packages/messaging/src/controllers/window-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ import {
MessageParameter,
MessageType
} from '../models/worker-page-message';
import { ControllerInterface } from './controller-interface';
import { BaseController } from './base-controller';

interface ManifestContent {
gcm_sender_id: string;
}

export class WindowController extends ControllerInterface {
export class WindowController extends BaseController {
private registrationToUse: ServiceWorkerRegistration | null = null;
private publicVapidKeyToUse: Uint8Array | null = null;
private manifestCheckPromise: Promise<void> | null = null;
Expand Down
20 changes: 10 additions & 10 deletions packages/messaging/test/controller-get-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as sinon from 'sinon';

import { FirebaseApp } from '@firebase/app-types';

import { ControllerInterface } from '../src/controllers/controller-interface';
import { BaseController } from '../src/controllers/base-controller';
import { SwController } from '../src/controllers/sw-controller';
import { WindowController } from '../src/controllers/window-controller';
import { base64ToArrayBuffer } from '../src/helpers/base64-to-array-buffer';
Expand Down Expand Up @@ -141,7 +141,7 @@ describe('Firebase Messaging > *Controller.getToken()', () => {

it('should handle a failure to get registration', () => {
sandbox
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
.stub(BaseController.prototype, 'getNotificationPermission_')
.callsFake(() => 'granted');

sandbox
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('Firebase Messaging > *Controller.getToken()', () => {

it('should handle the notification permission', () => {
const notificationStub = sandbox.stub(
ControllerInterface.prototype,
BaseController.prototype,
'getNotificationPermission_'
);
notificationStub.onCall(0).returns('denied');
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('Firebase Messaging > *Controller.getToken()', () => {
.callsFake(() => Promise.resolve(vapidKeyToUse));

sandbox
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
.stub(BaseController.prototype, 'getNotificationPermission_')
.callsFake(() => 'granted');

sandbox
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('Firebase Messaging > *Controller.getToken()', () => {
.callsFake(() => Promise.resolve(CUSTOM_VAPID_KEY));

sandbox
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
.stub(BaseController.prototype, 'getNotificationPermission_')
.callsFake(() => 'granted');

sandbox
Expand All @@ -281,7 +281,7 @@ describe('Firebase Messaging > *Controller.getToken()', () => {
mockGetReg(Promise.resolve(registration));

sandbox
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
.stub(BaseController.prototype, 'getNotificationPermission_')
.callsFake(() => 'granted');

sandbox
Expand Down Expand Up @@ -330,7 +330,7 @@ describe('Firebase Messaging > *Controller.getToken()', () => {
};

sandbox
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
.stub(BaseController.prototype, 'getNotificationPermission_')
.callsFake(() => 'granted');

sandbox
Expand Down Expand Up @@ -408,7 +408,7 @@ describe('Firebase Messaging > *Controller.getToken()', () => {
saveTokenDetailsStub.callsFake(async () => {});

sandbox
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
.stub(BaseController.prototype, 'getNotificationPermission_')
.callsFake(() => 'granted');

let vapidKeyToUse = DEFAULT_PUBLIC_VAPID_KEY;
Expand Down Expand Up @@ -482,7 +482,7 @@ describe('Firebase Messaging > *Controller.getToken()', () => {
mockGetReg(regPromise);

sandbox
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
.stub(BaseController.prototype, 'getNotificationPermission_')
.callsFake(() => 'granted');

// start with using the deault key.
Expand Down Expand Up @@ -567,7 +567,7 @@ describe('Firebase Messaging > *Controller.getToken()', () => {
const errorMsg = 'messaging/' + ERROR_CODES.TOKEN_UPDATE_FAILED;

sandbox
.stub(ControllerInterface.prototype, 'getNotificationPermission_')
.stub(BaseController.prototype, 'getNotificationPermission_')
.callsFake(() => 'granted');

sandbox
Expand Down
30 changes: 15 additions & 15 deletions packages/messaging/test/controller-interface.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { FirebaseApp } from '@firebase/app-types';
import { expect } from 'chai';
import * as sinon from 'sinon';

import { ControllerInterface } from '../src/controllers/controller-interface';
import { BaseController } from '../src/controllers/base-controller';
import { SwController } from '../src/controllers/sw-controller';
import { WindowController } from '../src/controllers/window-controller';
import { DEFAULT_PUBLIC_VAPID_KEY } from '../src/models/fcm-details';
Expand All @@ -34,10 +34,10 @@ import { describe } from './testing-utils/messaging-test-runner';
const controllersToTest = [WindowController, SwController];

/**
* As ControllerInterface is an abstract class, we need a concrete
* As BaseController is an abstract class, we need a concrete
* implementation that can be initialized for testing
*/
class MockControllerInterface extends ControllerInterface {
class MockBaseController extends BaseController {
async getSWRegistration_(): Promise<ServiceWorkerRegistration> {
return new ServiceWorkerRegistration();
}
Expand All @@ -47,7 +47,7 @@ class MockControllerInterface extends ControllerInterface {
}
}

describe('Firebase Messaging > *ControllerInterface', () => {
describe('Firebase Messaging > *BaseController', () => {
let sandbox: sinon.SinonSandbox;
let app: FirebaseApp;

Expand All @@ -64,7 +64,7 @@ describe('Firebase Messaging > *ControllerInterface', () => {

describe('INTERNAL.delete()', () => {
it('should call delete()', () => {
const controller = new MockControllerInterface(app);
const controller = new MockBaseController(app);
const spy = sandbox.spy(controller, 'delete');
controller.INTERNAL.delete();
expect(spy.callCount).to.equal(1);
Expand All @@ -73,7 +73,7 @@ describe('Firebase Messaging > *ControllerInterface', () => {

describe('requestPermission()', () => {
it(`should throw`, () => {
const controller = new MockControllerInterface(app);
const controller = new MockBaseController(app);
let thrownError;
try {
controller.requestPermission();
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('Firebase Messaging > *ControllerInterface', () => {

describe('useServiceWorker()', () => {
it(`should throw`, () => {
const controller = new MockControllerInterface(app);
const controller = new MockBaseController(app);
let thrownError;
try {
controller.useServiceWorker(null as any);
Expand All @@ -165,7 +165,7 @@ describe('Firebase Messaging > *ControllerInterface', () => {

describe('usePublicVapidKey()', () => {
it(`should throw`, () => {
const controller = new MockControllerInterface(app);
const controller = new MockBaseController(app);
let thrownError;
try {
controller.usePublicVapidKey(null as any);
Expand All @@ -179,7 +179,7 @@ describe('Firebase Messaging > *ControllerInterface', () => {

describe('onMessage()', () => {
it(`should throw`, () => {
const controller = new MockControllerInterface(app);
const controller = new MockBaseController(app);
let thrownError;
try {
controller.onMessage(null as any, null as any, null as any);
Expand All @@ -193,7 +193,7 @@ describe('Firebase Messaging > *ControllerInterface', () => {

describe('onTokenRefresh()', () => {
it(`should throw`, () => {
const controller = new MockControllerInterface(app);
const controller = new MockBaseController(app);
let thrownError;
try {
controller.onTokenRefresh(null as any, null as any, null as any);
Expand All @@ -207,7 +207,7 @@ describe('Firebase Messaging > *ControllerInterface', () => {

describe('setBackgroundMessageHandler()', () => {
it(`should throw`, () => {
const controller = new MockControllerInterface(app);
const controller = new MockBaseController(app);
let thrownError;
try {
controller.setBackgroundMessageHandler(null as any);
Expand All @@ -222,31 +222,31 @@ describe('Firebase Messaging > *ControllerInterface', () => {
describe('getNotificationPermission_', () => {
it('should return current permission', () => {
sandbox.stub(Notification as any, 'permission').value('test');
const controller = new MockControllerInterface(app);
const controller = new MockBaseController(app);
const result = controller.getNotificationPermission_();
expect(result).to.equal('test');
});
});

describe('getTokenDetailsModel', () => {
it('should return an instance of TokenDetailsModel', () => {
const controller = new MockControllerInterface(app);
const controller = new MockBaseController(app);
const result = controller.getTokenDetailsModel();
expect(result).to.be.instanceof(TokenDetailsModel);
});
});

describe('getVapidDetailsModel', () => {
it('should return an instance of VapidDetailsModel', () => {
const controller = new MockControllerInterface(app);
const controller = new MockBaseController(app);
const result = controller.getVapidDetailsModel();
expect(result).to.be.instanceof(VapidDetailsModel);
});
});

describe('getIidModel', () => {
it('should return an instance of IidModel', () => {
const controller = new MockControllerInterface(app);
const controller = new MockBaseController(app);
const result = controller.getIidModel();
expect(result).to.be.instanceof(IidModel);
});
Expand Down