|
@@ -1,4 +1,4 @@
|
|
|
-import { BrowserWindow, ipcMain, webContents, session, app, BrowserView, WebContents } from 'electron/main';
|
|
|
+import { BrowserWindow, ipcMain, webContents, session, app, BrowserView, WebContents, BaseWindow, WebContentsView } from 'electron/main';
|
|
|
|
|
|
import { expect } from 'chai';
|
|
|
|
|
@@ -2734,6 +2734,57 @@ describe('webContents module', () => {
|
|
|
expect(params.x).to.be.a('number');
|
|
|
expect(params.y).to.be.a('number');
|
|
|
});
|
|
|
+
|
|
|
+ it('emits when right clicked in a WebContentsView', async () => {
|
|
|
+ const w = new BaseWindow({ show: false });
|
|
|
+
|
|
|
+ const mainView = new WebContentsView({
|
|
|
+ webPreferences: {
|
|
|
+ preload: path.join(__dirname, 'preload.js')
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ const draggablePage = path.join(fixturesPath, 'pages', 'draggable-page.html');
|
|
|
+ await mainView.webContents.loadFile(draggablePage);
|
|
|
+
|
|
|
+ w.contentView.addChildView(mainView);
|
|
|
+
|
|
|
+ const { width, height } = w.getContentBounds();
|
|
|
+ mainView.setBounds({ x: 0, y: 0, width, height });
|
|
|
+
|
|
|
+ const promise = once(mainView.webContents, 'context-menu') as Promise<[any, Electron.ContextMenuParams]>;
|
|
|
+
|
|
|
+ // Simulate right-click to create context-menu event.
|
|
|
+ const opts = { x: 0, y: 0, button: 'right' as const };
|
|
|
+ mainView.webContents.sendInputEvent({ ...opts, type: 'mouseDown' });
|
|
|
+ mainView.webContents.sendInputEvent({ ...opts, type: 'mouseUp' });
|
|
|
+
|
|
|
+ const [, params] = await promise;
|
|
|
+
|
|
|
+ expect(params.pageURL).to.equal(mainView.webContents.getURL());
|
|
|
+ expect(params.frame).to.be.an('object');
|
|
|
+ expect(params.x).to.be.a('number');
|
|
|
+ expect(params.y).to.be.a('number');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('emits when right clicked in a BrowserWindow with vibrancy', async () => {
|
|
|
+ const w = new BrowserWindow({ show: false, vibrancy: 'titlebar' });
|
|
|
+ await w.loadFile(path.join(fixturesPath, 'pages', 'draggable-page.html'));
|
|
|
+
|
|
|
+ const promise = once(w.webContents, 'context-menu') as Promise<[any, Electron.ContextMenuParams]>;
|
|
|
+
|
|
|
+ // Simulate right-click to create context-menu event.
|
|
|
+ const opts = { x: 0, y: 0, button: 'right' as const };
|
|
|
+ w.webContents.sendInputEvent({ ...opts, type: 'mouseDown' });
|
|
|
+ w.webContents.sendInputEvent({ ...opts, type: 'mouseUp' });
|
|
|
+
|
|
|
+ const [, params] = await promise;
|
|
|
+
|
|
|
+ expect(params.pageURL).to.equal(w.webContents.getURL());
|
|
|
+ expect(params.frame).to.be.an('object');
|
|
|
+ expect(params.x).to.be.a('number');
|
|
|
+ expect(params.y).to.be.a('number');
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
describe('close() method', () => {
|