Skip to content

Commit

Permalink
test with WM_ACTIVATEAPP
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak1556 committed Aug 6, 2020
1 parent 4c11d83 commit 30b01b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
1 change: 0 additions & 1 deletion shell/browser/api/electron_api_base_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ void BaseWindow::OnNewWindowForTab() {

#if defined(OS_WIN)
void BaseWindow::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
LOG(INFO) << "GOT MESSAGE " << (int)message;
if (IsWindowMessageHooked(message)) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
Expand Down
39 changes: 18 additions & 21 deletions spec-main/api-browser-window-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4292,15 +4292,16 @@ describe('BrowserWindow module', () => {
ifdescribe(process.platform === 'win32')('window message hooks', () => {
afterEach(closeAllWindows);

const WM_GETICON = 0x7f;
const WM_ACTIVATEAPP = 0x1C;

it('can hook a window message with hookWindowMessage', async () => {
const w = new BrowserWindow({ show: true, width: 256, height: 256 });
const messageReceived = new Promise<[Buffer, Buffer]>((resolve) => {
w.hookWindowMessage(WM_GETICON, (wparam: Buffer, lparam: Buffer) => {
w.hookWindowMessage(WM_ACTIVATEAPP, (wparam: Buffer, lparam: Buffer) => {
resolve([wparam, lparam]);
});
});
w.minimize();
const [wparam, lparam] = await messageReceived;
expect(wparam).to.be.an.instanceOf(Buffer);
expect(lparam).to.be.an.instanceOf(Buffer);
Expand All @@ -4311,24 +4312,22 @@ describe('BrowserWindow module', () => {
let timesCalled = 0;
{
const messageReceived = new Promise<[Buffer, Buffer]>((resolve) => {
w.hookWindowMessage(WM_GETICON, (wparam: Buffer, lparam: Buffer) => {
w.hookWindowMessage(WM_ACTIVATEAPP, (wparam: Buffer, lparam: Buffer) => {
timesCalled++;
resolve([wparam, lparam]);
});
});
w.blur();
await messageReceived;
expect(timesCalled).to.equal(1);
}
console.log('before hide/show');
w.hide();
w.show();
console.log('after hide/show');
await delay(100);
console.log('after delay');
const p = emittedOnce(w, 'focus');
w.focus();
await p;
expect(timesCalled).to.equal(2);
w.unhookWindowMessage(WM_GETICON);
w.hide();
w.show();
w.unhookWindowMessage(WM_ACTIVATEAPP);
w.blur();
w.focus();
expect(timesCalled).to.equal(2);
});

Expand All @@ -4337,24 +4336,22 @@ describe('BrowserWindow module', () => {
let timesCalled = 0;
{
const messageReceived = new Promise<[Buffer, Buffer]>((resolve) => {
w.hookWindowMessage(WM_GETICON, (wparam: Buffer, lparam: Buffer) => {
w.hookWindowMessage(WM_ACTIVATEAPP, (wparam: Buffer, lparam: Buffer) => {
timesCalled++;
resolve([wparam, lparam]);
});
});
w.minimize();
await messageReceived;
expect(timesCalled).to.equal(1);
}
console.log('before hide/show');
w.hide();
w.show();
console.log('after hide/show');
await delay(100);
console.log('after delay');
const p = emittedOnce(w, 'restore');
w.restore();
await p;
expect(timesCalled).to.equal(2);
w.unhookAllWindowMessages();
w.hide();
w.show();
w.minimize();
w.restore();
expect(timesCalled).to.equal(2);
});
});
Expand Down

0 comments on commit 30b01b4

Please sign in to comment.