Browse Source

Added failing leak test for TabControl/TabItem.

Removing `TabItem`s causes a leak.
Steven Kirk 4 years ago
parent
commit
3d4c17b387
1 changed files with 37 additions and 1 deletions
  1. 37 1
      tests/Avalonia.LeakTests/ControlTests.cs

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

@@ -313,7 +313,6 @@ namespace Avalonia.LeakTests
             }
         }
 
-
         [Fact]
         public void Slider_Is_Freed()
         {
@@ -347,6 +346,43 @@ namespace Avalonia.LeakTests
             }
         }
 
+        [Fact]
+        public void TabItem_Is_Freed()
+        {
+            using (Start())
+            {
+                Func<Window> run = () =>
+                {
+                    var window = new Window
+                    {
+                        Content = new TabControl
+                        {
+                            Items = new[] { new TabItem() }
+                        }
+                    };
+
+                    window.Show();
+
+                    // Do a layout and make sure that TabControl and TabItem gets added to visual tree.
+                    window.LayoutManager.ExecuteInitialLayoutPass();
+                    var tabControl = Assert.IsType<TabControl>(window.Presenter.Child);
+                    Assert.IsType<TabItem>(tabControl.Presenter.Panel.Children[0]);
+
+                    // Clear the items and ensure the TabItem is removed.
+                    tabControl.Items = null;
+                    window.LayoutManager.ExecuteLayoutPass();
+                    Assert.Empty(tabControl.Presenter.Panel.Children);
+
+                    return window;
+                };
+
+                var result = run();
+
+                dotMemory.Check(memory =>
+                    Assert.Equal(0, memory.GetObjects(where => where.Type.Is<TabItem>()).ObjectsCount));
+            }
+        }
+
         [Fact]
         public void RendererIsDisposed()
         {