UNPKG

4.59 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2020 Ericsson and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18const inversify_1 = require("inversify");
19const common_1 = require("../../common");
20const core_preferences_1 = require("../core-preferences");
21const frontend_application_contribution_1 = require("../frontend-application-contribution");
22const default_window_service_1 = require("./default-window-service");
23const assert = require("assert");
24describe('DefaultWindowService', () => {
25 class TestFrontendApplicationContribution {
26 constructor(preventUnload) {
27 this.preventUnload = preventUnload;
28 this.onWillStopCalled = false;
29 }
30 onWillStop() {
31 this.onWillStopCalled = true;
32 return this.preventUnload;
33 }
34 }
35 function setupWindowService(confirmExit, frontendContributions) {
36 const container = new inversify_1.Container();
37 container.bind(default_window_service_1.DefaultWindowService).toSelf().inSingletonScope();
38 container.bind(common_1.ContributionProvider)
39 .toConstantValue({
40 getContributions: () => frontendContributions,
41 })
42 .whenTargetNamed(frontend_application_contribution_1.FrontendApplicationContribution);
43 container.bind(core_preferences_1.CorePreferences)
44 .toConstantValue({
45 'application.confirmExit': confirmExit,
46 });
47 return container.get(default_window_service_1.DefaultWindowService);
48 }
49 it('onWillStop should be called on every contribution (never)', () => {
50 const frontendContributions = [
51 // preventUnload should be ignored here
52 new TestFrontendApplicationContribution(true),
53 ];
54 const windowService = setupWindowService('never', frontendContributions);
55 assert(frontendContributions.every(contribution => !contribution.onWillStopCalled), 'contributions should not be called yet');
56 assert(windowService['collectContributionUnloadVetoes']().length === 0, 'there should be no vetoes');
57 assert(frontendContributions.every(contribution => contribution.onWillStopCalled), 'contributions should have been called');
58 });
59 it('onWillStop should be called on every contribution (ifRequired)', () => {
60 const frontendContributions = [
61 new TestFrontendApplicationContribution(true),
62 // canUnload should not stop at the previous contribution
63 new TestFrontendApplicationContribution(false),
64 ];
65 const windowService = setupWindowService('ifRequired', frontendContributions);
66 assert(frontendContributions.every(contribution => !contribution.onWillStopCalled), 'contributions should not be called yet');
67 assert(windowService['collectContributionUnloadVetoes']().length > 0, 'There should be vetoes');
68 assert(frontendContributions.every(contribution => contribution.onWillStopCalled), 'contributions should have been called');
69 });
70 it('onWillStop should be called on every contribution (always)', () => {
71 const frontendContributions = [
72 // canUnload should return false despite preventUnload not being set
73 new TestFrontendApplicationContribution(false),
74 ];
75 const windowService = setupWindowService('always', frontendContributions);
76 assert(frontendContributions.every(contribution => !contribution.onWillStopCalled), 'contributions should not be called yet');
77 assert(windowService['collectContributionUnloadVetoes']().length > 0, 'there should be vetoes');
78 assert(frontendContributions.every(contribution => contribution.onWillStopCalled), 'contributions should have been called');
79 });
80});
81//# sourceMappingURL=default-window-service.spec.js.map
\No newline at end of file