update tests for menu closed event and call cancel on closePopup

This commit is contained in:
Heilig Benedek 2017-11-28 02:29:37 +01:00 committed by Cheng Zhao
parent 14b65467d8
commit ef7357dedc
2 changed files with 11 additions and 4 deletions

View file

@ -60,6 +60,8 @@ void MenuViews::PopupAt(Window* window, int x, int y, int positioning_item) {
} }
void MenuViews::ClosePopupAt(int32_t window_id) { void MenuViews::ClosePopupAt(int32_t window_id) {
if (menu_runners_[window_id])
menu_runners_[window_id]->Cancel();
menu_runners_.erase(window_id); menu_runners_.erase(window_id);
} }

View file

@ -329,25 +329,30 @@ describe('Menu module', () => {
let w = null let w = null
let menu let menu
beforeEach(() => { beforeEach((done) => {
w = new BrowserWindow({show: false, width: 200, height: 200}) w = new BrowserWindow({show: false, width: 200, height: 200})
menu = Menu.buildFromTemplate([ menu = Menu.buildFromTemplate([
{ {
label: '1' label: '1'
} }
]) ])
menu.popup(w, {x: 100, y: 100, async: true})
menu.closePopup(w) w.loadURL('data:text/html,<html>teszt</html>')
w.webContents.on('dom-ready', () => {
done()
})
}) })
afterEach(() => { afterEach(() => {
return closeWindow(w).then(() => { w = null }) return closeWindow(w).then(() => { w = null })
}) })
it('emits closed event', () => { it('emits closed event', (done) => {
menu.popup(w, {x: 100, y: 100, async: true})
menu.on('closed', () => { menu.on('closed', () => {
done() done()
}) })
menu.closePopup(w)
}) })
}) })