Fixes #2228. Crash when attempting to open menu bar item with action but no menu items assigned.

This commit is contained in:
BDisp
2022-11-17 15:08:59 +00:00
parent 9afdc4df3b
commit 4c8520ca08
2 changed files with 22 additions and 2 deletions

View File

@@ -1498,7 +1498,7 @@ Edit
Assert.True (menu.IsMenuOpen);
Assert.False (tf.HasFocus);
Application.Top.Redraw (Application.Top.Bounds);
TestHelpers.AssertDriverContentsAre (expectedMenu.expectedSubMenuOpen(0), output);
TestHelpers.AssertDriverContentsAre (expectedMenu.expectedSubMenuOpen (0), output);
// Right - Edit has no sub menu; this tests that no sub menu shows
Assert.True (menu.openMenu.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
@@ -1636,5 +1636,23 @@ Edit
00000000000000
00000000000000", attributes);
}
[Fact, AutoInitShutdown]
public void MenuBar_With_Action_But_Without_MenuItems_Not_Throw ()
{
var menu = new MenuBar (
menus: new []
{
new MenuBarItem { Title = "Test 1", Action = () => { } },
new MenuBarItem { Title = "Test 2", Action = () => { } },
});
Application.Top.Add (menu);
Application.Begin (Application.Top);
Assert.False (Application.Top.OnKeyDown (new KeyEvent (Key.AltMask, new KeyModifiers { Alt = true })));
Assert.True (menu.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
Assert.True (menu.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
}
}
}