mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +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:
parent
53f585b68e
commit
90a89f3f5b
@ -51,7 +51,12 @@ export default class NotificationManager extends EventEmitter {
|
|||||||
const lastFocused = await this.platform.getLastFocusedWindow();
|
const lastFocused = await this.platform.getLastFocusedWindow();
|
||||||
// Position window in top right corner of lastFocused window.
|
// Position window in top right corner of lastFocused window.
|
||||||
top = lastFocused.top;
|
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 (_) {
|
} catch (_) {
|
||||||
// The following properties are more than likely 0, due to being
|
// The following properties are more than likely 0, due to being
|
||||||
// opened from the background chrome process for the extension that
|
// opened from the background chrome process for the extension that
|
||||||
|
@ -35,6 +35,7 @@ jest.mock('webextension-polyfill', () => {
|
|||||||
getAll: jest.fn(),
|
getAll: jest.fn(),
|
||||||
create: jest.fn(),
|
create: jest.fn(),
|
||||||
update: jest.fn(),
|
update: jest.fn(),
|
||||||
|
getLastFocused: jest.fn(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -68,4 +69,28 @@ describe('Notification Manager', () => {
|
|||||||
expect(setCurrentPopupIdSpy).toHaveBeenCalledTimes(1);
|
expect(setCurrentPopupIdSpy).toHaveBeenCalledTimes(1);
|
||||||
expect(setCurrentPopupIdSpy).toHaveBeenCalledWith(newPopupWindow.id);
|
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,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user