[MM-18152] Desktop notifications (#1040)

* temp

* add in html5 notification tests

* strip out custom permissions handling

* disable middle click

* validate as URI instead of URL

allow’s custom protocol’s to pass through

* add context isolation to new window requests

* add new permissions handling

* prevent setting user to away from quit/shutdown

* dispatch desktop notifications from renderer

* remove test code

* log desktop notification errors

* should deny as a last resort

* only trigger callback once
This commit is contained in:
Dean Whillier
2019-09-23 14:59:12 -04:00
committed by GitHub
parent 77d823a076
commit 761ef8d0e6
14 changed files with 116 additions and 468 deletions

View File

@@ -1,92 +0,0 @@
// Copyright (c) 2015-2016 Yuya Ochiai
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import fs from 'fs';
import path from 'path';
import env from '../modules/environment';
import PermissionManager from '../../src/main/PermissionManager';
const permissionFile = path.join(env.userDataDir, 'permission.json');
const ORIGIN1 = 'https://example.com';
const PERMISSION1 = 'notifications';
const ORIGIN2 = 'https://example2.com';
const PERMISSION2 = 'test';
const DENIED = 'denied';
const GRANTED = 'granted';
describe('PermissionManager', function() {
beforeEach(function(done) {
fs.unlink(permissionFile, () => {
done();
});
});
it('should grant a permission for an origin', function() {
const manager = new PermissionManager(permissionFile);
manager.isGranted(ORIGIN1, PERMISSION1).should.be.false;
manager.isDenied(ORIGIN1, PERMISSION1).should.be.false;
manager.grant(ORIGIN1, PERMISSION1);
manager.isGranted(ORIGIN1, PERMISSION1).should.be.true;
manager.isDenied(ORIGIN1, PERMISSION1).should.be.false;
manager.isGranted(ORIGIN2, PERMISSION1).should.be.false;
manager.isGranted(ORIGIN1, PERMISSION2).should.be.false;
});
it('should deny a permission for an origin', function() {
const manager = new PermissionManager(permissionFile);
manager.isGranted(ORIGIN1, PERMISSION1).should.be.false;
manager.isDenied(ORIGIN1, PERMISSION1).should.be.false;
manager.deny(ORIGIN1, PERMISSION1);
manager.isGranted(ORIGIN1, PERMISSION1).should.be.false;
manager.isDenied(ORIGIN1, PERMISSION1).should.be.true;
manager.isDenied(ORIGIN2, PERMISSION1).should.be.false;
manager.isDenied(ORIGIN1, PERMISSION2).should.be.false;
});
it('should save permissions to the file', function() {
const manager = new PermissionManager(permissionFile);
manager.deny(ORIGIN1, PERMISSION1);
manager.grant(ORIGIN2, PERMISSION2);
JSON.parse(fs.readFileSync(permissionFile)).should.deep.equal({
[ORIGIN1]: {
[PERMISSION1]: DENIED,
},
[ORIGIN2]: {
[PERMISSION2]: GRANTED,
},
});
});
it('should restore permissions from the file', function() {
fs.writeFileSync(permissionFile, JSON.stringify({
[ORIGIN1]: {
[PERMISSION1]: DENIED,
},
[ORIGIN2]: {
[PERMISSION2]: GRANTED,
},
}));
const manager = new PermissionManager(permissionFile);
manager.isDenied(ORIGIN1, PERMISSION1).should.be.true;
manager.isGranted(ORIGIN2, PERMISSION2).should.be.true;
});
it('should allow permissions for trusted URLs', function() {
fs.writeFileSync(permissionFile, JSON.stringify({}));
const manager = new PermissionManager(permissionFile, [ORIGIN1, ORIGIN2]);
manager.isGranted(ORIGIN1, PERMISSION1).should.be.true;
manager.isGranted(ORIGIN2, PERMISSION2).should.be.true;
});
});