SDA-3707 - Fix getting window handle for maximized windows (#1420) (#1427)

This commit is contained in:
Robin Westberg
2022-07-28 11:37:00 +02:00
committed by GitHub
parent 7d4ac3be51
commit 44f6bb5461
2 changed files with 74 additions and 44 deletions

View File

@@ -67,35 +67,16 @@ describe('hwnd handler', () => {
expect(hwnd).toBe(parent);
});
it('no rect found for parent window', () => {
const parent = Buffer.from('validhwnd', 'utf8');
const hwnd = getContentWindowHandle(parent);
expect(hwnd).toBe(parent);
});
it('no child window found', () => {
mockGetWindowRect.mockImplementationOnce((_hwnd, rect) => {
writeRect(rect, 10, 10, 100, 100);
return 1;
});
const parent = Buffer.from('validhwnd', 'utf8');
const hwnd = getContentWindowHandle(parent);
expect(mockGetWindowRect).toBeCalledTimes(1);
expect(mockGetWindowRect).toBeCalledTimes(0);
expect(mockFindWindowExA).toBeCalledTimes(1);
expect(hwnd).toBe(parent);
});
it('matching child window found', () => {
mockGetWindowRect.mockImplementationOnce((_hwnd, rect) => {
writeRect(rect, 10, 10, 100, 100);
return 1;
});
mockGetWindowRect.mockImplementationOnce((_hwnd, rect) => {
writeRect(rect, 10, 20, 100, 100);
return 1;
});
it('no rect found for child window', () => {
mockFindWindowExA.mockImplementationOnce(() => {
return 4711;
});
@@ -103,18 +84,58 @@ describe('hwnd handler', () => {
const parent = Buffer.from('validhwnd', 'utf8');
const hwnd = getContentWindowHandle(parent);
expect(mockGetWindowRect).toBeCalledTimes(1);
expect(mockFindWindowExA).toBeCalledTimes(2);
expect(hwnd).toBe(parent);
});
it('no rect found for second child window', () => {
mockGetWindowRect.mockImplementationOnce((_hwnd, rect) => {
writeRect(rect, 10, 10, 100, 10);
return 1;
});
mockFindWindowExA.mockImplementationOnce(() => {
return 4711;
});
mockFindWindowExA.mockImplementationOnce(() => {
return 42;
});
const parent = Buffer.from('validhwnd', 'utf8');
const hwnd = getContentWindowHandle(parent);
expect(mockGetWindowRect).toBeCalledTimes(2);
expect(mockFindWindowExA).toBeCalledTimes(1);
expect(mockFindWindowExA).toBeCalledTimes(3);
expect(hwnd).toBe(parent);
});
it('matching child window found', () => {
mockGetWindowRect.mockImplementationOnce((_hwnd, rect) => {
writeRect(rect, 10, 20, 100, 100);
return 1;
});
mockGetWindowRect.mockImplementationOnce((_hwnd, rect) => {
writeRect(rect, 10, 10, 100, 10);
return 1;
});
mockFindWindowExA.mockImplementationOnce(() => {
return 4711;
});
mockFindWindowExA.mockImplementationOnce(() => {
return 42;
});
const parent = Buffer.from('validhwnd', 'utf8');
const hwnd = getContentWindowHandle(parent);
expect(mockGetWindowRect).toBeCalledTimes(2);
expect(mockFindWindowExA).toBeCalledTimes(3);
expect(hwnd.readInt32LE(0)).toBe(4711);
});
it('matching child window found second', () => {
mockGetWindowRect.mockImplementationOnce((_hwnd, rect) => {
writeRect(rect, 10, 10, 100, 100);
return 1;
});
mockGetWindowRect.mockImplementationOnce((_hwnd, rect) => {
writeRect(rect, 100, 10, 100, 100);
writeRect(rect, 10, 10, 100, 10);
return 1;
});
mockGetWindowRect.mockImplementationOnce((_hwnd, rect) => {
@@ -131,16 +152,12 @@ describe('hwnd handler', () => {
const parent = Buffer.from('validhwnd', 'utf8');
const hwnd = getContentWindowHandle(parent);
expect(mockGetWindowRect).toBeCalledTimes(3);
expect(mockFindWindowExA).toBeCalledTimes(2);
expect(mockGetWindowRect).toBeCalledTimes(2);
expect(mockFindWindowExA).toBeCalledTimes(3);
expect(hwnd.readInt32LE(0)).toBe(42);
});
it('no matching child window found', () => {
mockGetWindowRect.mockImplementationOnce((_hwnd, rect) => {
writeRect(rect, 10, 10, 100, 100);
return 1;
});
mockGetWindowRect.mockImplementationOnce((_hwnd, rect) => {
writeRect(rect, 10, 10, 100, 100);
return 1;
@@ -152,7 +169,7 @@ describe('hwnd handler', () => {
const parent = Buffer.from('validhwnd', 'utf8');
const hwnd = getContentWindowHandle(parent);
expect(mockGetWindowRect).toBeCalledTimes(2);
expect(mockGetWindowRect).toBeCalledTimes(1);
expect(mockFindWindowExA).toBeCalledTimes(2);
expect(hwnd).toBe(parent);
});