electron/spec/api-browser-window-spec.js

715 строки
20 KiB
JavaScript
Исходник Обычный вид История

2016-01-23 14:35:30 +03:00
'use strict';
2016-01-20 01:49:40 +03:00
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const os = require('os');
2016-01-12 05:40:23 +03:00
2016-01-20 01:49:40 +03:00
const remote = require('electron').remote;
const screen = require('electron').screen;
2016-01-12 05:40:23 +03:00
const app = remote.require('electron').app;
2016-01-20 01:49:40 +03:00
const ipcMain = remote.require('electron').ipcMain;
2016-02-24 13:11:09 +03:00
const ipcRenderer = require('electron').ipcRenderer;
2016-01-20 01:49:40 +03:00
const BrowserWindow = remote.require('electron').BrowserWindow;
2016-01-12 05:40:23 +03:00
2016-01-20 01:49:40 +03:00
const isCI = remote.getGlobal('isCi');
2016-01-12 05:40:23 +03:00
describe('browser-window module', function() {
var fixtures = path.resolve(__dirname, 'fixtures');
var w = null;
2016-01-12 05:40:23 +03:00
beforeEach(function() {
if (w != null) {
w.destroy();
}
w = new BrowserWindow({
2016-01-12 05:40:23 +03:00
show: false,
width: 400,
height: 400
});
});
2016-01-12 05:40:23 +03:00
afterEach(function() {
if (w != null) {
w.destroy();
}
w = null;
2016-01-12 05:40:23 +03:00
});
2016-01-12 05:40:23 +03:00
describe('BrowserWindow.close()', function() {
it('should emit unload handler', function(done) {
w.webContents.on('did-finish-load', function() {
w.close();
2016-01-12 05:40:23 +03:00
});
w.on('closed', function() {
2016-02-17 20:27:25 +03:00
var test = path.join(fixtures, 'api', 'unload');
var content = fs.readFileSync(test);
2016-01-12 05:40:23 +03:00
fs.unlinkSync(test);
assert.equal(String(content), 'unload');
done();
2016-01-12 05:40:23 +03:00
});
w.loadURL('file://' + path.join(fixtures, 'api', 'unload.html'));
2016-01-12 05:40:23 +03:00
});
it('should emit beforeunload handler', function(done) {
2016-01-12 05:40:23 +03:00
w.on('onbeforeunload', function() {
done();
2016-01-12 05:40:23 +03:00
});
w.webContents.on('did-finish-load', function() {
w.close();
2016-01-12 05:40:23 +03:00
});
w.loadURL('file://' + path.join(fixtures, 'api', 'beforeunload-false.html'));
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('window.close()', function() {
it('should emit unload handler', function(done) {
w.on('closed', function() {
2016-02-17 20:27:25 +03:00
var test = path.join(fixtures, 'api', 'close');
var content = fs.readFileSync(test);
2016-01-12 05:40:23 +03:00
fs.unlinkSync(test);
assert.equal(String(content), 'close');
done();
2016-01-12 05:40:23 +03:00
});
w.loadURL('file://' + path.join(fixtures, 'api', 'close.html'));
2016-01-12 05:40:23 +03:00
});
it('should emit beforeunload handler', function(done) {
2016-01-12 05:40:23 +03:00
w.on('onbeforeunload', function() {
done();
2016-01-12 05:40:23 +03:00
});
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'));
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('BrowserWindow.destroy()', function() {
it('prevents users to access methods of webContents', function() {
2016-02-17 20:27:25 +03:00
var webContents = w.webContents;
2016-01-12 05:40:23 +03:00
w.destroy();
assert.throws((function() {
webContents.getId();
2016-01-12 05:40:23 +03:00
}), /Object has been destroyed/);
});
});
2016-01-12 05:40:23 +03:00
describe('BrowserWindow.loadURL(url)', function() {
it('should emit did-start-loading event', function(done) {
w.webContents.on('did-start-loading', function() {
done();
2016-01-12 05:40:23 +03:00
});
w.loadURL('about:blank');
2016-01-12 05:40:23 +03:00
});
it('should emit did-fail-load event for files that do not exist', function(done) {
w.webContents.on('did-fail-load', function(event, code) {
assert.equal(code, -6);
done();
2016-01-12 05:40:23 +03:00
});
w.loadURL('file://a.txt');
2016-01-12 05:40:23 +03:00
});
it('should emit did-fail-load event for invalid URL', function(done) {
w.webContents.on('did-fail-load', function(event, code, desc) {
assert.equal(desc, 'ERR_INVALID_URL');
assert.equal(code, -300);
done();
2016-01-12 05:40:23 +03:00
});
w.loadURL('http://example:port');
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('BrowserWindow.show()', function() {
it('should focus on window', function() {
2016-01-12 05:40:23 +03:00
if (isCI) {
return;
}
2016-01-12 05:40:23 +03:00
w.show();
assert(w.isFocused());
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('BrowserWindow.showInactive()', function() {
it('should not focus on window', function() {
2016-01-12 05:40:23 +03:00
w.showInactive();
assert(!w.isFocused());
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('BrowserWindow.focus()', function() {
it('does not make the window become visible', function() {
2016-01-12 05:40:23 +03:00
assert.equal(w.isVisible(), false);
w.focus();
assert.equal(w.isVisible(), false);
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('BrowserWindow.capturePage(rect, callback)', function() {
it('calls the callback with a Buffer', function(done) {
w.capturePage({
2016-01-12 05:40:23 +03:00
x: 0,
y: 0,
width: 100,
height: 100
}, function(image) {
assert.equal(image.isEmpty(), true);
done();
2016-01-12 05:40:23 +03:00
});
});
});
2016-01-12 05:40:23 +03:00
describe('BrowserWindow.setSize(width, height)', function() {
it('sets the window size', function(done) {
var size = [300, 400];
2016-01-12 05:40:23 +03:00
w.once('resize', function() {
var newSize = w.getSize();
2016-01-12 05:40:23 +03:00
assert.equal(newSize[0], size[0]);
assert.equal(newSize[1], size[1]);
done();
2016-01-12 05:40:23 +03:00
});
w.setSize(size[0], size[1]);
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('BrowserWindow.setPosition(x, y)', function() {
it('sets the window position', function(done) {
var pos = [10, 10];
2016-01-12 05:40:23 +03:00
w.once('move', function() {
2016-02-17 20:27:25 +03:00
var newPos = w.getPosition();
2016-01-12 05:40:23 +03:00
assert.equal(newPos[0], pos[0]);
assert.equal(newPos[1], pos[1]);
done();
2016-01-12 05:40:23 +03:00
});
w.setPosition(pos[0], pos[1]);
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('BrowserWindow.setContentSize(width, height)', function() {
it('sets the content size', function() {
2016-02-17 20:27:25 +03:00
var size = [400, 400];
2016-01-12 05:40:23 +03:00
w.setContentSize(size[0], size[1]);
2016-02-17 20:27:25 +03:00
var after = w.getContentSize();
2016-01-12 05:40:23 +03:00
assert.equal(after[0], size[0]);
assert.equal(after[1], size[1]);
2016-01-12 05:40:23 +03:00
});
it('works for framless window', function() {
2016-01-12 05:40:23 +03:00
w.destroy();
w = new BrowserWindow({
show: false,
frame: false,
width: 400,
height: 400
});
2016-02-17 20:27:25 +03:00
var size = [400, 400];
2016-01-12 05:40:23 +03:00
w.setContentSize(size[0], size[1]);
2016-02-17 20:27:25 +03:00
var after = w.getContentSize();
2016-01-12 05:40:23 +03:00
assert.equal(after[0], size[0]);
assert.equal(after[1], size[1]);
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('BrowserWindow.fromId(id)', function() {
it('returns the window with id', function() {
assert.equal(w.id, BrowserWindow.fromId(w.id).id);
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('"useContentSize" option', function() {
it('make window created with content size when used', function() {
w.destroy();
w = new BrowserWindow({
show: false,
width: 400,
height: 400,
useContentSize: true
});
2016-02-17 20:27:25 +03:00
var contentSize = w.getContentSize();
2016-01-12 05:40:23 +03:00
assert.equal(contentSize[0], 400);
assert.equal(contentSize[1], 400);
2016-01-12 05:40:23 +03:00
});
2016-01-12 05:40:23 +03:00
it('make window created with window size when not used', function() {
var size = w.getSize();
2016-01-12 05:40:23 +03:00
assert.equal(size[0], 400);
assert.equal(size[1], 400);
2016-01-12 05:40:23 +03:00
});
it('works for framless window', function() {
2016-01-12 05:40:23 +03:00
w.destroy();
w = new BrowserWindow({
show: false,
frame: false,
width: 400,
height: 400,
useContentSize: true
});
2016-02-17 20:27:25 +03:00
var contentSize = w.getContentSize();
2016-01-12 05:40:23 +03:00
assert.equal(contentSize[0], 400);
assert.equal(contentSize[1], 400);
2016-02-17 20:27:25 +03:00
var size = w.getSize();
2016-01-12 05:40:23 +03:00
assert.equal(size[0], 400);
assert.equal(size[1], 400);
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('"title-bar-style" option', function() {
if (process.platform !== 'darwin') {
return;
}
if (parseInt(os.release().split('.')[0]) < 14) {
return;
}
2016-01-12 05:40:23 +03:00
it('creates browser window with hidden title bar', function() {
w.destroy();
w = new BrowserWindow({
show: false,
width: 400,
height: 400,
titleBarStyle: 'hidden'
});
2016-02-17 20:27:25 +03:00
var contentSize = w.getContentSize();
assert.equal(contentSize[1], 400);
2016-01-12 05:40:23 +03:00
});
it('creates browser window with hidden inset title bar', function() {
2016-01-12 05:40:23 +03:00
w.destroy();
w = new BrowserWindow({
show: false,
width: 400,
height: 400,
titleBarStyle: 'hidden-inset'
});
2016-02-17 20:27:25 +03:00
var contentSize = w.getContentSize();
assert.equal(contentSize[1], 400);
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('"enableLargerThanScreen" option', function() {
if (process.platform === 'linux') {
return;
}
2016-01-12 05:40:23 +03:00
beforeEach(function() {
w.destroy();
w = new BrowserWindow({
2016-01-12 05:40:23 +03:00
show: true,
width: 400,
height: 400,
enableLargerThanScreen: true
});
});
2016-01-12 05:40:23 +03:00
it('can move the window out of screen', function() {
w.setPosition(-10, -10);
2016-02-17 20:27:25 +03:00
var after = w.getPosition();
2016-01-12 05:40:23 +03:00
assert.equal(after[0], -10);
assert.equal(after[1], -10);
2016-01-12 05:40:23 +03:00
});
it('can set the window larger than screen', function() {
2016-02-17 20:27:25 +03:00
var size = screen.getPrimaryDisplay().size;
2016-01-12 05:40:23 +03:00
size.width += 100;
size.height += 100;
w.setSize(size.width, size.height);
2016-02-17 20:27:25 +03:00
var after = w.getSize();
2016-01-12 05:40:23 +03:00
assert.equal(after[0], size.width);
assert.equal(after[1], size.height);
2016-01-12 05:40:23 +03:00
});
});
2016-01-23 14:35:30 +03:00
2016-01-12 05:40:23 +03:00
describe('"web-preferences" option', function() {
afterEach(function() {
ipcMain.removeAllListeners('answer');
2016-01-12 05:40:23 +03:00
});
2016-01-12 05:40:23 +03:00
describe('"preload" option', function() {
it('loads the script before other scripts in window', function(done) {
2016-02-17 20:27:25 +03:00
var preload = path.join(fixtures, 'module', 'set-global.js');
2016-01-12 05:40:23 +03:00
ipcMain.once('answer', function(event, test) {
assert.equal(test, 'preload');
done();
2016-01-12 05:40:23 +03:00
});
w.destroy();
w = new BrowserWindow({
show: false,
webPreferences: {
preload: preload
}
});
w.loadURL('file://' + path.join(fixtures, 'api', 'preload.html'));
2016-01-12 05:40:23 +03:00
});
});
describe('"node-integration" option', function() {
it('disables node integration when specified to false', function(done) {
2016-02-17 20:27:25 +03:00
var preload = path.join(fixtures, 'module', 'send-later.js');
2016-01-12 05:40:23 +03:00
ipcMain.once('answer', function(event, test) {
assert.equal(test, 'undefined');
done();
2016-01-12 05:40:23 +03:00
});
w.destroy();
w = new BrowserWindow({
show: false,
webPreferences: {
preload: preload,
nodeIntegration: false
}
});
w.loadURL('file://' + path.join(fixtures, 'api', 'blank.html'));
2016-01-12 05:40:23 +03:00
});
});
});
2016-01-12 05:40:23 +03:00
describe('beforeunload handler', function() {
it('returning true would not prevent close', function(done) {
w.on('closed', function() {
done();
2016-01-12 05:40:23 +03:00
});
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-true.html'));
2016-01-12 05:40:23 +03:00
});
2016-01-12 05:40:23 +03:00
it('returning non-empty string would not prevent close', function(done) {
w.on('closed', function() {
done();
2016-01-12 05:40:23 +03:00
});
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-string.html'));
2016-01-12 05:40:23 +03:00
});
2016-01-12 05:40:23 +03:00
it('returning false would prevent close', function(done) {
w.on('onbeforeunload', function() {
done();
2016-01-12 05:40:23 +03:00
});
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'));
2016-01-12 05:40:23 +03:00
});
it('returning empty string would prevent close', function(done) {
2016-01-12 05:40:23 +03:00
w.on('onbeforeunload', function() {
done();
2016-01-12 05:40:23 +03:00
});
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-empty-string.html'));
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('new-window event', function() {
if (isCI && process.platform === 'darwin') {
return;
}
2016-01-12 05:40:23 +03:00
it('emits when window.open is called', function(done) {
w.webContents.once('new-window', function(e, url, frameName) {
e.preventDefault();
assert.equal(url, 'http://host/');
assert.equal(frameName, 'host');
done();
2016-01-12 05:40:23 +03:00
});
w.loadURL("file://" + fixtures + "/pages/window-open.html");
2016-01-12 05:40:23 +03:00
});
it('emits when link with target is called', function(done) {
2016-01-12 05:40:23 +03:00
this.timeout(10000);
w.webContents.once('new-window', function(e, url, frameName) {
e.preventDefault();
assert.equal(url, 'http://host/');
assert.equal(frameName, 'target');
done();
2016-01-12 05:40:23 +03:00
});
w.loadURL("file://" + fixtures + "/pages/target-name.html");
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('maximize event', function() {
if (isCI) {
return;
}
it('emits when window is maximized', function(done) {
2016-01-12 05:40:23 +03:00
this.timeout(10000);
w.once('maximize', function() {
done();
2016-01-12 05:40:23 +03:00
});
w.show();
w.maximize();
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('unmaximize event', function() {
if (isCI) {
return;
}
it('emits when window is unmaximized', function(done) {
2016-01-12 05:40:23 +03:00
this.timeout(10000);
w.once('unmaximize', function() {
done();
2016-01-12 05:40:23 +03:00
});
w.show();
w.maximize();
w.unmaximize();
2016-01-12 05:40:23 +03:00
});
});
2016-01-12 05:40:23 +03:00
describe('minimize event', function() {
if (isCI) {
return;
}
it('emits when window is minimized', function(done) {
2016-01-12 05:40:23 +03:00
this.timeout(10000);
w.once('minimize', function() {
done();
2016-01-12 05:40:23 +03:00
});
w.show();
w.minimize();
2016-01-12 05:40:23 +03:00
});
});
describe('beginFrameSubscription method', function() {
this.timeout(20000);
it('subscribes frame updates', function(done) {
let called = false;
2016-01-12 05:40:23 +03:00
w.loadURL("file://" + fixtures + "/api/blank.html");
w.webContents.beginFrameSubscription(function(data) {
// This callback might be called twice.
if (called)
return;
called = true;
2016-01-12 05:40:23 +03:00
assert.notEqual(data.length, 0);
w.webContents.endFrameSubscription();
done();
2016-01-12 05:40:23 +03:00
});
});
});
describe('savePage method', function() {
const savePageDir = path.join(fixtures, 'save_page');
const savePageHtmlPath = path.join(savePageDir, 'save_page.html');
const savePageJsPath = path.join(savePageDir, 'save_page_files', 'test.js');
const savePageCssPath = path.join(savePageDir, 'save_page_files', 'test.css');
after(function() {
try {
fs.unlinkSync(savePageCssPath);
fs.unlinkSync(savePageJsPath);
fs.unlinkSync(savePageHtmlPath);
fs.rmdirSync(path.join(savePageDir, 'save_page_files'));
fs.rmdirSync(savePageDir);
} catch (e) {
2016-01-19 22:31:47 +03:00
// Ignore error
}
});
it('should save page to disk', function(done) {
2016-01-12 05:40:23 +03:00
w.webContents.on('did-finish-load', function() {
w.webContents.savePage(savePageHtmlPath, 'HTMLComplete', function(error) {
2016-01-12 05:40:23 +03:00
assert.equal(error, null);
assert(fs.existsSync(savePageHtmlPath));
assert(fs.existsSync(savePageJsPath));
assert(fs.existsSync(savePageCssPath));
done();
2016-01-12 05:40:23 +03:00
});
});
w.loadURL("file://" + fixtures + "/pages/save_page/index.html");
2016-01-12 05:40:23 +03:00
});
});
describe('BrowserWindow options argument is optional', function() {
it('should create a window with default size (800x600)', function() {
2016-01-12 05:40:23 +03:00
w.destroy();
w = new BrowserWindow();
2016-02-17 20:27:25 +03:00
var size = w.getSize();
2016-01-12 05:40:23 +03:00
assert.equal(size[0], 800);
assert.equal(size[1], 600);
2016-01-12 05:40:23 +03:00
});
});
2016-01-23 14:35:30 +03:00
2016-03-07 21:37:01 +03:00
describe('window states', function() {
2016-03-05 03:12:14 +03:00
describe('resizable state', function() {
it('can be changed with resizable option', function() {
w.destroy();
w = new BrowserWindow({show: false, resizable: false});
assert.equal(w.isResizable(), false);
});
it('can be changed with setResizable method', function() {
assert.equal(w.isResizable(), true);
w.setResizable(false);
assert.equal(w.isResizable(), false);
w.setResizable(true);
assert.equal(w.isResizable(), true);
});
});
2016-03-05 03:15:04 +03:00
});
2016-03-05 03:12:14 +03:00
2016-03-07 20:53:20 +03:00
describe('window states (excluding Linux)', function() {
2016-01-23 14:35:30 +03:00
// Not implemented on Linux.
if (process.platform == 'linux')
return;
describe('movable state', function() {
it('can be changed with movable option', function() {
w.destroy();
w = new BrowserWindow({show: false, movable: false});
assert.equal(w.isMovable(), false);
});
it('can be changed with setMovable method', function() {
assert.equal(w.isMovable(), true);
w.setMovable(false);
assert.equal(w.isMovable(), false);
w.setMovable(true);
assert.equal(w.isMovable(), true);
});
});
describe('minimizable state', function() {
it('can be changed with minimizable option', function() {
w.destroy();
w = new BrowserWindow({show: false, minimizable: false});
assert.equal(w.isMinimizable(), false);
});
it('can be changed with setMinimizable method', function() {
assert.equal(w.isMinimizable(), true);
w.setMinimizable(false);
assert.equal(w.isMinimizable(), false);
w.setMinimizable(true);
assert.equal(w.isMinimizable(), true);
});
});
describe('maximizable state', function() {
it('can be changed with maximizable option', function() {
w.destroy();
w = new BrowserWindow({show: false, maximizable: false});
assert.equal(w.isMaximizable(), false);
});
it('can be changed with setMaximizable method', function() {
assert.equal(w.isMaximizable(), true);
w.setMaximizable(false);
assert.equal(w.isMaximizable(), false);
w.setMaximizable(true);
assert.equal(w.isMaximizable(), true);
});
it('is not affected when changing other states', function() {
w.setMaximizable(false);
assert.equal(w.isMaximizable(), false);
w.setMinimizable(false);
assert.equal(w.isMaximizable(), false);
w.setClosable(false);
assert.equal(w.isMaximizable(), false);
});
});
describe('fullscreenable state', function() {
// Only implemented on OS X.
if (process.platform != 'darwin')
return;
it('can be changed with fullscreenable option', function() {
w.destroy();
w = new BrowserWindow({show: false, fullscreenable: false});
assert.equal(w.isFullScreenable(), false);
});
it('can be changed with setFullScreenable method', function() {
assert.equal(w.isFullScreenable(), true);
w.setFullScreenable(false);
assert.equal(w.isFullScreenable(), false);
w.setFullScreenable(true);
assert.equal(w.isFullScreenable(), true);
});
});
describe('closable state', function() {
it('can be changed with closable option', function() {
w.destroy();
w = new BrowserWindow({show: false, closable: false});
assert.equal(w.isClosable(), false);
});
it('can be changed with setClosable method', function() {
assert.equal(w.isClosable(), true);
w.setClosable(false);
assert.equal(w.isClosable(), false);
w.setClosable(true);
assert.equal(w.isClosable(), true);
});
});
2016-01-23 14:40:28 +03:00
describe('hasShadow state', function() {
2016-01-23 15:03:56 +03:00
// On Window there is no shadow by default and it can not be changed
// dynamically.
2016-01-23 14:40:28 +03:00
it('can be changed with hasShadow option', function() {
w.destroy();
2016-01-23 15:03:56 +03:00
let hasShadow = process.platform == 'darwin' ? false : true;
w = new BrowserWindow({show: false, hasShadow: hasShadow});
assert.equal(w.hasShadow(), hasShadow);
2016-01-23 14:40:28 +03:00
});
it('can be changed with setHasShadow method', function() {
2016-01-23 15:03:56 +03:00
if (process.platform != 'darwin')
return;
2016-01-23 14:40:28 +03:00
assert.equal(w.hasShadow(), true);
w.setHasShadow(false);
assert.equal(w.hasShadow(), false);
w.setHasShadow(true);
assert.equal(w.hasShadow(), true);
});
});
2016-01-23 14:35:30 +03:00
});
2016-02-09 21:18:01 +03:00
describe('window.webContents.send(channel, args...)', function() {
it('throws an error when the channel is missing', function() {
2016-02-09 21:24:48 +03:00
assert.throws(function() {
2016-02-09 21:18:01 +03:00
w.webContents.send();
2016-02-09 21:34:50 +03:00
}, 'Missing required channel argument');
2016-02-09 21:24:48 +03:00
assert.throws(function() {
w.webContents.send(null);
2016-02-09 21:34:50 +03:00
}, 'Missing required channel argument');
2016-02-09 21:18:01 +03:00
});
});
describe('dev tool extensions', function () {
it('serializes the registered extensions on quit', function () {
2016-02-04 04:17:11 +03:00
var extensionName = 'foo';
var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', extensionName);
var serializedPath = path.join(app.getPath('userData'), 'DevTools Extensions');
BrowserWindow.addDevToolsExtension(extensionPath);
app.emit('will-quit');
assert.deepEqual(JSON.parse(fs.readFileSync(serializedPath)), [extensionPath]);
BrowserWindow.removeDevToolsExtension(extensionName);
app.emit('will-quit');
assert.equal(fs.existsSync(serializedPath), false);
2016-02-04 04:17:11 +03:00
});
});
2016-02-24 13:11:09 +03:00
describe('window.webContents.executeJavaScript', function() {
var expected = 'hello, world!';
var code = '(() => \"' + expected + '\")()';
it('doesnt throw when no calback is provided', function() {
const result = ipcRenderer.sendSync('executeJavaScript', code, false);
assert.equal(result, 'success');
});
it('returns result when calback is provided', function(done) {
ipcRenderer.send('executeJavaScript', code, true);
ipcRenderer.once('executeJavaScript-response', function(event, result) {
assert.equal(result, expected);
done();
});
});
});
2016-01-12 05:40:23 +03:00
});