1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | const inversify_1 = require("inversify");
|
19 | const common_1 = require("../../common");
|
20 | const core_preferences_1 = require("../core-preferences");
|
21 | const frontend_application_1 = require("../frontend-application");
|
22 | const default_window_service_1 = require("./default-window-service");
|
23 | const assert = require("assert");
|
24 | describe('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_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 |
|
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 |
|
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 |
|
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 |
|
\ | No newline at end of file |