diff --git a/src/OpenFin/openfin.ts b/src/OpenFin/openfin.ts index 96c4d174..2b87f60f 100644 --- a/src/OpenFin/openfin.ts +++ b/src/OpenFin/openfin.ts @@ -10,7 +10,7 @@ import { MessageBus, MessageBusSubscription, MessageBusOptions } from "../ipc"; ContainerRegistry.registerContainer("OpenFin", { condition: () => typeof window !== "undefined" && "fin" in window && "desktop" in fin, - create: () => new OpenFinContainer() + create: (options) => new OpenFinContainer(null, null, options) }); const windowEventMap = { @@ -298,11 +298,15 @@ export class OpenFinContainer extends WebContainerBase { `; /* tslint:enable */ - public constructor(desktop?: fin.OpenFinDesktop, win?: Window) { + public constructor(desktop?: fin.OpenFinDesktop, win?: Window, options?: any) { super(win); this.desktop = desktop || fin.desktop; this.hostType = "OpenFin"; + if (options && options.userName && options.appName) { + this.desktop.Application.getCurrent().registerUser(options.userName, options.appName); + } + this.ipc = new OpenFinMessageBus(this.desktop.InterApplicationBus, (this.desktop.Application.getCurrent()).uuid); this.registerNotificationsApi(); } diff --git a/tests/unit/OpenFin/openfin.spec.ts b/tests/unit/OpenFin/openfin.spec.ts index 9bbe5821..4dc2839d 100644 --- a/tests/unit/OpenFin/openfin.spec.ts +++ b/tests/unit/OpenFin/openfin.spec.ts @@ -336,6 +336,40 @@ describe("OpenFinContainer", () => { expect(container.hostType).toEqual("OpenFin"); }); + describe("ctor options", () => { + describe("registerUser", () => { + let desktop; + let app; + + beforeEach(() => { + desktop = jasmine.createSpyObj("desktop", ["Application"]); + app = jasmine.createSpyObj("application", ["getCurrent", "registerUser"]); + Object.defineProperty(desktop, "Application", { value: app }); + app.getCurrent.and.returnValue(app); + }); + + it("options userName and appName to registerUser", () => { + const container = new OpenFinContainer(desktop, null, { userName: "user", appName: "app" }); + expect(app.registerUser).toHaveBeenCalledWith("user", "app"); + }); + + it("options missing userName does not invoke registerUser", () => { + const container = new OpenFinContainer(desktop, null, { appName: "app" }); + expect(app.registerUser).toHaveBeenCalledTimes(0); + }); + + it("options missing userName does not invoke registerUser", () => { + const container = new OpenFinContainer(desktop, null, { userName: "user" }); + expect(app.registerUser).toHaveBeenCalledTimes(0); + }); + + it("options missing userName and appName does not invoke registerUser", () => { + const container = new OpenFinContainer(desktop, null, {}); + expect(app.registerUser).toHaveBeenCalledTimes(0); + }); + }); + }); + it("getMainWindow returns wrapped inner window", () => { const win: OpenFinContainerWindow = container.getMainWindow(); expect(win).toBeDefined();