Merge remote-tracking branch 'upstream/master' into ELECTRON-77

This commit is contained in:
Kiran Niranjan 2017-07-13 10:44:11 +05:30
commit b05bbd5aa7
4 changed files with 161 additions and 23 deletions

View File

@ -3,7 +3,6 @@
"minimizeOnClose" : false, "minimizeOnClose" : false,
"launchOnStartup" : true, "launchOnStartup" : true,
"alwaysOnTop" : false, "alwaysOnTop" : false,
"launchOnStartup" : true,
"notificationSettings": { "notificationSettings": {
"position": "upper-right", "position": "upper-right",
"display": "" "display": ""

View File

@ -15,9 +15,8 @@
"prebuild": "npm run rebuild && npm run browserify-preload", "prebuild": "npm run rebuild && npm run browserify-preload",
"browserify-preload": "browserify -o js/preload/_preloadMain.js -x electron --insert-global-vars=__filename,__dirname js/preload/preloadMain.js", "browserify-preload": "browserify -o js/preload/_preloadMain.js -x electron --insert-global-vars=__filename,__dirname js/preload/preloadMain.js",
"rebuild": "electron-rebuild -f", "rebuild": "electron-rebuild -f",
"test": "npm run lint && npm run copy-config && jest --verbose --testPathPattern test --runInBand", "test": "npm run lint && jest --verbose --testPathPattern test --runInBand",
"lint": "eslint --ext .js js/", "lint": "eslint --ext .js js/",
"copy-config": "ncp 'config' 'node_modules/electron/dist/Electron.app/Contents/config'",
"rename-exe": "cd dist/win-unpacked && ren Symphony.exe Symphony-Electron.exe" "rename-exe": "cd dist/win-unpacked && ren Symphony.exe Symphony-Electron.exe"
}, },
"jest": { "jest": {
@ -81,6 +80,7 @@
"eslint-plugin-react": "^6.10.0", "eslint-plugin-react": "^6.10.0",
"jest": "^19.0.2", "jest": "^19.0.2",
"ncp": "^2.0.0", "ncp": "^2.0.0",
"robotjs": "^0.4.7",
"spectron": "^3.7.2" "spectron": "^3.7.2"
}, },
"dependencies": { "dependencies": {

View File

@ -1,5 +1,11 @@
const Application = require('./spectron/spectronSetup'); const Application = require('./spectron/spectronSetup');
const {isMac} = require('../js/utils/misc.js');
const childProcess = require('child_process');
let app = new Application({}); let app = new Application({});
let robot;
let configPath;
let mIsAlwaysOnTop;
describe('Tests for Always on top', () => { describe('Tests for Always on top', () => {
@ -7,23 +13,50 @@ describe('Tests for Always on top', () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut();
beforeAll((done) => { beforeAll((done) => {
childProcess.exec(`npm rebuild robotjs --target=${process.version} --build-from-source`, function () {
robot = require('robotjs');
return app.startApplication().then((startedApp) => { return app.startApplication().then((startedApp) => {
app = startedApp; app = startedApp;
getConfigPath().then((config) => {
configPath = config;
done(); done();
});
}).catch((err) => { }).catch((err) => {
expect(err).toBeNull(); expect(err).toBeNull();
}); });
}); });
});
function getConfigPath() {
return new Promise(function (resolve, reject) {
app.client.addCommand('getUserDataPath', function () {
return this.execute(function () {
return require('electron').remote.app.getPath('userData');
})
});
app.client.getUserDataPath().then((path) => {
resolve(path.value + '/Symphony.config')
}).catch((err) => {
reject(err);
});
});
}
afterAll((done) => { afterAll((done) => {
if (app && app.isRunning()) { if (app && app.isRunning()) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
app.stop().then(() => { app.stop().then(() => {
childProcess.exec('npm run rebuild', function (err, stdout) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
done(); done();
});
}).catch((err) => { }).catch((err) => {
console.log(err); childProcess.exec('npm run rebuild', function () {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
expect(err).toBeNull();
done(); done();
}); });
});
} }
}); });
@ -32,8 +65,6 @@ describe('Tests for Always on top', () => {
return app.client.getWindowCount().then((count) => { return app.client.getWindowCount().then((count) => {
expect(count === 1).toBeTruthy(); expect(count === 1).toBeTruthy();
done(); done();
}).catch((err) => {
expect(err).toBeNull();
}); });
}).catch((err) => { }).catch((err) => {
expect(err).toBeNull(); expect(err).toBeNull();
@ -56,24 +87,100 @@ describe('Tests for Always on top', () => {
}); });
}); });
it('should bring the app to front in windows', (done) => {
if (!isMac) {
app.browserWindow.focus();
app.browserWindow.restore();
app.browserWindow.setAlwaysOnTop(true).then(() => {
app.browserWindow.isAlwaysOnTop().then((isOnTop) => {
app.browserWindow.getBounds().then((bounds) => {
robot.setMouseDelay(200);
app.browserWindow.restore().then(() => {
let x = bounds.x + 95;
let y = bounds.y + 35;
robot.moveMouseSmooth(x, y);
robot.mouseClick();
robot.setKeyboardDelay(200);
for (let i = 0; i < 4
; i++) {
robot.keyTap('down');
}
robot.keyTap('enter');
expect(isOnTop).toBeTruthy();
done();
})
});
});
}).catch((err) => {
expect(err).toBeNull();
});
} else {
done();
}
});
it('should check is always on top', () => { it('should check is always on top', () => {
return Application.readConfig(configPath).then((userData) => {
return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => { return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => {
mIsAlwaysOnTop = isAlwaysOnTop;
if (userData.alwaysOnTop) {
expect(isAlwaysOnTop).toBeTruthy();
} else {
expect(isAlwaysOnTop).toBeFalsy(); expect(isAlwaysOnTop).toBeFalsy();
}
});
}).catch((err) => { }).catch((err) => {
expect(err).toBeNull(); expect(err).toBeNull();
}); });
}); });
it('should change the always on top property', () => { it('should toggle the always on top property to true', (done) => {
return app.browserWindow.setAlwaysOnTop(true); if (isMac) {
robot.setMouseDelay(200);
robot.moveMouse(190, 0);
robot.mouseClick();
for (let i = 0; i < 8; i++) {
robot.keyTap('down');
}
robot.keyTap('enter');
done();
} else {
app.browserWindow.getBounds().then((bounds) => {
app.browserWindow.focus();
robot.setMouseDelay(200);
app.browserWindow.restore().then(() => {
let x = bounds.x + 95;
let y = bounds.y + 35;
robot.moveMouseSmooth(x, y);
robot.mouseClick();
for (let i = 0; i < 4; i++) {
robot.keyTap('down');
}
robot.keyTap('enter');
done();
});
}).catch((err) => {
expect(err).toBeNull();
});
}
}); });
it('should check is always on top to be true', () => { it('should check is always on top to be true', () => {
if (!mIsAlwaysOnTop) {
return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => { return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => {
expect(isAlwaysOnTop).toBeTruthy(); expect(isAlwaysOnTop).toBeTruthy();
}).catch((err) => { }).catch((err) => {
expect(err).toBeNull(); expect(err).toBeNull();
}); });
} else {
return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => {
expect(isAlwaysOnTop).toBeFalsy();
}).catch((err) => {
expect(err).toBeNull();
});
}
}); });
}); });

View File

@ -1,5 +1,8 @@
const Application = require('spectron').Application; const Application = require('spectron').Application;
const path = require('path'); const path = require('path');
const fs = require('fs');
const {isMac} = require('../../js/utils/misc');
const ncp = require('ncp').ncp;
class App { class App {
@ -12,6 +15,8 @@ class App {
this.options.args = [path.join(__dirname, '..', '..', 'js/main.js')]; this.options.args = [path.join(__dirname, '..', '..', 'js/main.js')];
} }
App.copyConfigPath();
this.app = new Application(this.options); this.app = new Application(this.options);
} }
@ -35,6 +40,33 @@ class App {
return 90000 return 90000
} }
static readConfig(configPath) {
return new Promise(function (resolve, reject) {
fs.readFile(configPath, function (err, data) {
if (err) {
reject(err);
}
resolve(JSON.parse(data));
});
});
}
static copyConfigPath() {
if (isMac) {
ncp('config', 'node_modules/electron/dist/Electron.app/Contents/config', function (err) {
if (err) {
throw(err);
}
});
} else {
ncp('config', 'node_modules/electron/dist/config', function (err) {
if (err) {
throw(err);
}
});
}
}
} }
module.exports = App; module.exports = App;