Browse Source

Added another failing ContextMenu leak test.

Steven Kirk 5 years ago
parent
commit
c4da0f75b8
1 changed files with 37 additions and 1 deletions
  1. 37 1
      tests/Avalonia.LeakTests/ControlTests.cs

+ 37 - 1
tests/Avalonia.LeakTests/ControlTests.cs

@@ -422,7 +422,43 @@ namespace Avalonia.LeakTests
         }
 
         [Fact]
-        public void Context_MenuItems_Are_Freed()
+        public void Attached_ContextMenu_Is_Freed()
+        {
+            using (Start())
+            {
+                void AttachShowAndDetachContextMenu(Control control)
+                {
+                    var contextMenu = new ContextMenu
+                    {
+                        Items = new[]
+                        {
+                            new MenuItem { Header = "Foo" },
+                            new MenuItem { Header = "Foo" },
+                        }
+                    };
+
+                    control.ContextMenu = contextMenu;
+                    contextMenu.Open(control);
+                    contextMenu.Close();
+                    control.ContextMenu = null;
+                }
+
+                var window = new Window();
+                window.Show();
+
+                Assert.Same(window, FocusManager.Instance.Current);
+
+                AttachShowAndDetachContextMenu(window);
+
+                dotMemory.Check(memory =>
+                    Assert.Equal(0, memory.GetObjects(where => where.Type.Is<ContextMenu>()).ObjectsCount));
+                dotMemory.Check(memory =>
+                    Assert.Equal(0, memory.GetObjects(where => where.Type.Is<MenuItem>()).ObjectsCount));
+            }
+        }
+
+        [Fact]
+        public void Standalone_ContextMenu_Is_Freed()
         {
             using (Start())
             {