fix: ensure context-menu emitted for draggable regions (#44800)

* fix: ensure context-menu emitted for draggable regions

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: address suggestions from review

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2024-11-22 09:27:32 -05:00 committed by GitHub
parent 5b9fbb2e19
commit 1329e22fce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 84 additions and 21 deletions

View file

@ -2715,6 +2715,25 @@ describe('webContents module', () => {
expect(params.x).to.be.a('number');
expect(params.y).to.be.a('number');
});
it('emits when right-clicked in page in a draggable region', async () => {
const w = new BrowserWindow({ show: false });
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', () => {

22
spec/fixtures/pages/draggable-page.html vendored Normal file
View file

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Draggable Page</title>
<style>
.draggable {
-webkit-app-region: drag;
height: 100vh;
width: 100vw;
margin: 0;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div class="draggable"></div>
</body>
</html>