1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-21 17:37:01 +01:00

fix(20314): fix window.left negative value causing polifll warning (#20653)

Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
This commit is contained in:
Danica Shen 2023-08-31 15:15:09 +01:00 committed by GitHub
parent 53f585b68e
commit 90a89f3f5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -51,7 +51,12 @@ export default class NotificationManager extends EventEmitter {
const lastFocused = await this.platform.getLastFocusedWindow();
// Position window in top right corner of lastFocused window.
top = lastFocused.top;
left = lastFocused.left + (lastFocused.width - NOTIFICATION_WIDTH);
// - this is to make sure no error is triggered from polyfill
// error eg: Invalid value for bounds. Bounds must be at least 50% within visible screen space.
left = Math.max(
lastFocused.left + (lastFocused.width - NOTIFICATION_WIDTH),
0,
);
} catch (_) {
// The following properties are more than likely 0, due to being
// opened from the background chrome process for the extension that

View File

@ -35,6 +35,7 @@ jest.mock('webextension-polyfill', () => {
getAll: jest.fn(),
create: jest.fn(),
update: jest.fn(),
getLastFocused: jest.fn(),
},
};
});
@ -68,4 +69,28 @@ describe('Notification Manager', () => {
expect(setCurrentPopupIdSpy).toHaveBeenCalledTimes(1);
expect(setCurrentPopupIdSpy).toHaveBeenCalledWith(newPopupWindow.id);
});
it('should not pass negative left value for extension window created from last focused window', async () => {
const newPopupWindow = generateMockWindow();
setCurrentPopupIdSpy = jest.fn();
const createSpy = jest.fn().mockReturnValue(newPopupWindow);
browser.windows.getAll.mockReturnValue([]);
browser.windows.create = createSpy;
browser.windows.getLastFocused.mockReturnValue({
top: 0,
left: 0,
width: 120, // make sure this is smalled than NOTIFICATION_WIDTH
});
currentPopupId = undefined;
await notificationManager.showPopup(setCurrentPopupIdSpy, currentPopupId);
expect(createSpy).toHaveBeenCalledTimes(1);
expect(createSpy).toHaveBeenCalledWith({
height: 620,
left: 0, // this is critical, means error related to polyfill is not triggered
top: 0,
type: 'popup',
url: 'notification.html',
width: 360,
});
});
});