|
|
|
@ -7,6 +7,7 @@ using System.Linq; |
|
|
|
using JetBrains.dotMemoryUnit; |
|
|
|
using Perspex.Controls; |
|
|
|
using Perspex.Controls.Templates; |
|
|
|
using Perspex.VisualTree; |
|
|
|
using Xunit; |
|
|
|
using Xunit.Abstractions; |
|
|
|
|
|
|
|
@ -81,6 +82,112 @@ namespace Perspex.LeakTests |
|
|
|
Assert.Equal(0, memory.GetObjects(where => where.Type.Is<Canvas>()).ObjectsCount)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void ScrollViewer_With_Content_Is_Freed() |
|
|
|
{ |
|
|
|
Func<Window> run = () => |
|
|
|
{ |
|
|
|
var window = new Window |
|
|
|
{ |
|
|
|
Content = new ScrollViewer |
|
|
|
{ |
|
|
|
Content = new Canvas() |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
// Do a layout and make sure that ScrollViewer gets added to visual tree and its
|
|
|
|
// template applied.
|
|
|
|
window.LayoutManager.ExecuteLayoutPass(); |
|
|
|
Assert.IsType<ScrollViewer>(window.Presenter.Child); |
|
|
|
Assert.IsType<Canvas>(((ScrollViewer)window.Presenter.Child).Presenter.Child); |
|
|
|
|
|
|
|
// Clear the content and ensure the ScrollViewer is removed.
|
|
|
|
window.Content = null; |
|
|
|
window.LayoutManager.ExecuteLayoutPass(); |
|
|
|
Assert.Null(window.Presenter.Child); |
|
|
|
|
|
|
|
return window; |
|
|
|
}; |
|
|
|
|
|
|
|
var result = run(); |
|
|
|
|
|
|
|
dotMemory.Check(memory => |
|
|
|
Assert.Equal(0, memory.GetObjects(where => where.Type.Is<TextBox>()).ObjectsCount)); |
|
|
|
dotMemory.Check(memory => |
|
|
|
Assert.Equal(0, memory.GetObjects(where => where.Type.Is<Canvas>()).ObjectsCount)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void TextBox_Is_Freed() |
|
|
|
{ |
|
|
|
Func<Window> run = () => |
|
|
|
{ |
|
|
|
var window = new Window |
|
|
|
{ |
|
|
|
Content = new TextBox() |
|
|
|
}; |
|
|
|
|
|
|
|
// Do a layout and make sure that TextBox gets added to visual tree and its
|
|
|
|
// template applied.
|
|
|
|
window.LayoutManager.ExecuteLayoutPass(); |
|
|
|
Assert.IsType<TextBox>(window.Presenter.Child); |
|
|
|
Assert.NotEqual(0, window.Presenter.Child.GetVisualChildren().Count()); |
|
|
|
|
|
|
|
// Clear the content and ensure the TextBox is removed.
|
|
|
|
window.Content = null; |
|
|
|
window.LayoutManager.ExecuteLayoutPass(); |
|
|
|
Assert.Null(window.Presenter.Child); |
|
|
|
|
|
|
|
return window; |
|
|
|
}; |
|
|
|
|
|
|
|
var result = run(); |
|
|
|
|
|
|
|
dotMemory.Check(memory => |
|
|
|
Assert.Equal(0, memory.GetObjects(where => where.Type.Is<TextBox>()).ObjectsCount)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void TextBox_With_Xaml_Binding_Is_Freed() |
|
|
|
{ |
|
|
|
Func<Window> run = () => |
|
|
|
{ |
|
|
|
var window = new Window |
|
|
|
{ |
|
|
|
DataContext = new Node { Name = "foo" }, |
|
|
|
Content = new TextBox() |
|
|
|
}; |
|
|
|
|
|
|
|
var binding = new Perspex.Markup.Xaml.Data.Binding |
|
|
|
{ |
|
|
|
Path = "Name" |
|
|
|
}; |
|
|
|
|
|
|
|
binding.Bind((TextBox)window.Content, TextBox.TextProperty); |
|
|
|
|
|
|
|
// Do a layout and make sure that TextBox gets added to visual tree and its
|
|
|
|
// Text property set.
|
|
|
|
window.LayoutManager.ExecuteLayoutPass(); |
|
|
|
Assert.IsType<TextBox>(window.Presenter.Child); |
|
|
|
Assert.Equal("foo", ((TextBox)window.Presenter.Child).Text); |
|
|
|
|
|
|
|
// Clear the content and DataContext and ensure the TextBox is removed.
|
|
|
|
window.Content = null; |
|
|
|
window.DataContext = null; |
|
|
|
window.LayoutManager.ExecuteLayoutPass(); |
|
|
|
Assert.Null(window.Presenter.Child); |
|
|
|
|
|
|
|
return window; |
|
|
|
}; |
|
|
|
|
|
|
|
var result = run(); |
|
|
|
|
|
|
|
dotMemory.Check(memory => |
|
|
|
Assert.Equal(0, memory.GetObjects(where => where.Type.Is<TextBox>()).ObjectsCount)); |
|
|
|
dotMemory.Check(memory => |
|
|
|
Assert.Equal(0, memory.GetObjects(where => where.Type.Is<Node>()).ObjectsCount)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void TreeView_Is_Freed() |
|
|
|
{ |
|
|
|
|