|
|
|
@ -4,9 +4,11 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Runtime.Remoting.Contexts; |
|
|
|
using Avalonia.Controls; |
|
|
|
using Avalonia.Controls.Templates; |
|
|
|
using Avalonia.Diagnostics; |
|
|
|
using Avalonia.Input; |
|
|
|
using Avalonia.Layout; |
|
|
|
using Avalonia.Platform; |
|
|
|
using Avalonia.Rendering; |
|
|
|
@ -370,9 +372,133 @@ namespace Avalonia.LeakTests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Control_With_Style_RenderTransform_Is_Freed() |
|
|
|
{ |
|
|
|
// # Issue #3545
|
|
|
|
using (Start()) |
|
|
|
{ |
|
|
|
Func<Window> run = () => |
|
|
|
{ |
|
|
|
var window = new Window |
|
|
|
{ |
|
|
|
Styles = |
|
|
|
{ |
|
|
|
new Style(x => x.OfType<Canvas>()) |
|
|
|
{ |
|
|
|
Setters = |
|
|
|
{ |
|
|
|
new Setter |
|
|
|
{ |
|
|
|
Property = Visual.RenderTransformProperty, |
|
|
|
Value = new RotateTransform(45), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
Content = new Canvas() |
|
|
|
}; |
|
|
|
|
|
|
|
window.Show(); |
|
|
|
|
|
|
|
// Do a layout and make sure that Canvas gets added to visual tree with
|
|
|
|
// its render transform.
|
|
|
|
window.LayoutManager.ExecuteInitialLayoutPass(window); |
|
|
|
var canvas = Assert.IsType<Canvas>(window.Presenter.Child); |
|
|
|
Assert.IsType<RotateTransform>(canvas.RenderTransform); |
|
|
|
|
|
|
|
// Clear the content and ensure the Canvas 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<Canvas>()).ObjectsCount)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
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()) |
|
|
|
{ |
|
|
|
void BuildAndShowContextMenu(Control control) |
|
|
|
{ |
|
|
|
var contextMenu = new ContextMenu |
|
|
|
{ |
|
|
|
Items = new[] |
|
|
|
{ |
|
|
|
new MenuItem { Header = "Foo" }, |
|
|
|
new MenuItem { Header = "Foo" }, |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
contextMenu.Open(control); |
|
|
|
contextMenu.Close(); |
|
|
|
} |
|
|
|
|
|
|
|
var window = new Window(); |
|
|
|
window.Show(); |
|
|
|
|
|
|
|
Assert.Same(window, FocusManager.Instance.Current); |
|
|
|
|
|
|
|
BuildAndShowContextMenu(window); |
|
|
|
BuildAndShowContextMenu(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)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private IDisposable Start() |
|
|
|
{ |
|
|
|
return UnitTestApplication.Start(TestServices.StyledWindow); |
|
|
|
return UnitTestApplication.Start(TestServices.StyledWindow.With( |
|
|
|
focusManager: new FocusManager(), |
|
|
|
keyboardDevice: () => new KeyboardDevice(), |
|
|
|
inputManager: new InputManager())); |
|
|
|
} |
|
|
|
|
|
|
|
private class Node |
|
|
|
|