1 changed files with 229 additions and 253 deletions
@ -1,253 +1,229 @@ |
|||||
////using System.Linq;
|
using System; |
||||
////using Avalonia.Automation.Peers;
|
using System.Linq; |
||||
////using Avalonia.Automation.Platform;
|
using Avalonia.Automation.Peers; |
||||
////using Avalonia.Automation.Provider;
|
using Avalonia.Automation.Provider; |
||||
////using Avalonia.Controls.Presenters;
|
using Avalonia.Controls.Presenters; |
||||
////using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Templates; |
||||
////using Avalonia.Controls.Templates;
|
using Avalonia.Platform; |
||||
////using Avalonia.Platform;
|
using Avalonia.UnitTests; |
||||
////using Avalonia.UnitTests;
|
using Avalonia.VisualTree; |
||||
////using Avalonia.VisualTree;
|
using Xunit; |
||||
////using Moq;
|
|
||||
////using Xunit;
|
#nullable enable |
||||
|
|
||||
////namespace Avalonia.Controls.UnitTests.Automation
|
namespace Avalonia.Controls.UnitTests.Automation |
||||
////{
|
{ |
||||
//// public class ControlAutomationPeerTests
|
public class ControlAutomationPeerTests |
||||
//// {
|
{ |
||||
//// private static Mock<IAutomationNodeFactory> _factory;
|
public class Children |
||||
|
{ |
||||
//// public ControlAutomationPeerTests()
|
[Fact] |
||||
//// {
|
public void Creates_Children_For_Controls_In_Visual_Tree() |
||||
//// _factory = new Mock<IAutomationNodeFactory>();
|
{ |
||||
//// _factory.Setup(x => x.CreateNode(It.IsAny<AutomationPeer>()))
|
var panel = new Panel |
||||
//// .Returns(() => Mock.Of<IAutomationNode>(x => x.Factory == _factory));
|
{ |
||||
//// }
|
Children = |
||||
|
{ |
||||
//// public class Children
|
new Border(), |
||||
//// {
|
new Border(), |
||||
//// [Fact]
|
}, |
||||
//// public void Creates_Children_For_Controls_In_Visual_Tree()
|
}; |
||||
//// {
|
|
||||
//// var panel = new Panel
|
var target = CreatePeer(panel); |
||||
//// {
|
|
||||
//// Children =
|
Assert.Equal( |
||||
//// {
|
panel.GetVisualChildren(), |
||||
//// new Border(),
|
target.GetChildren().Cast<ControlAutomationPeer>().Select(x => x.Owner)); |
||||
//// new Border(),
|
} |
||||
//// },
|
|
||||
//// };
|
[Fact] |
||||
|
public void Creates_Children_when_Controls_Attached_To_Visual_Tree() |
||||
//// var factory = CreateFactory();
|
{ |
||||
//// var target = CreatePeer(factory, panel);
|
var contentControl = new ContentControl |
||||
|
{ |
||||
//// Assert.Equal(
|
Template = new FuncControlTemplate<ContentControl>((o, ns) => |
||||
//// panel.GetVisualChildren(),
|
new ContentPresenter |
||||
//// target.GetChildren().Cast<ControlAutomationPeer>().Select(x => x.Owner));
|
{ |
||||
//// }
|
Name = "PART_ContentPresenter", |
||||
|
[!ContentPresenter.ContentProperty] = o[!ContentControl.ContentProperty], |
||||
//// [Fact]
|
}), |
||||
//// public void Creates_Children_when_Controls_Attached_To_Visual_Tree()
|
Content = new Border(), |
||||
//// {
|
}; |
||||
//// var contentControl = new ContentControl
|
|
||||
//// {
|
var target = CreatePeer(contentControl); |
||||
//// Template = new FuncControlTemplate<ContentControl>((o, ns) =>
|
|
||||
//// new ContentPresenter
|
Assert.Empty(target.GetChildren()); |
||||
//// {
|
|
||||
//// Name = "PART_ContentPresenter",
|
contentControl.Measure(Size.Infinity); |
||||
//// [!ContentPresenter.ContentProperty] = o[!ContentControl.ContentProperty],
|
|
||||
//// }),
|
Assert.Equal(1, target.GetChildren().Count); |
||||
//// Content = new Border(),
|
} |
||||
//// };
|
|
||||
|
[Fact] |
||||
//// var factory = CreateFactory();
|
public void Updates_Children_When_VisualChildren_Added() |
||||
//// var target = CreatePeer(factory, contentControl);
|
{ |
||||
|
var panel = new Panel |
||||
//// Assert.Empty(target.GetChildren());
|
{ |
||||
|
Children = |
||||
//// contentControl.Measure(Size.Infinity);
|
{ |
||||
|
new Border(), |
||||
//// Assert.Equal(1, target.GetChildren().Count);
|
new Border(), |
||||
//// }
|
}, |
||||
|
}; |
||||
//// [Fact]
|
|
||||
//// public void Updates_Children_When_VisualChildren_Added()
|
var target = CreatePeer(panel); |
||||
//// {
|
var children = target.GetChildren(); |
||||
//// var panel = new Panel
|
|
||||
//// {
|
Assert.Equal(2, children.Count); |
||||
//// Children =
|
|
||||
//// {
|
panel.Children.Add(new Decorator()); |
||||
//// new Border(),
|
|
||||
//// new Border(),
|
children = target.GetChildren(); |
||||
//// },
|
Assert.Equal(3, children.Count); |
||||
//// };
|
} |
||||
|
|
||||
//// var factory = CreateFactory();
|
[Fact] |
||||
//// var target = CreatePeer(factory, panel);
|
public void Updates_Children_When_VisualChildren_Removed() |
||||
//// var children = target.GetChildren();
|
{ |
||||
|
var panel = new Panel |
||||
//// Assert.Equal(2, children.Count);
|
{ |
||||
|
Children = |
||||
//// panel.Children.Add(new Decorator());
|
{ |
||||
|
new Border(), |
||||
//// children = target.GetChildren();
|
new Border(), |
||||
//// Assert.Equal(3, children.Count);
|
}, |
||||
//// }
|
}; |
||||
|
|
||||
//// [Fact]
|
var target = CreatePeer(panel); |
||||
//// public void Updates_Children_When_VisualChildren_Removed()
|
var children = target.GetChildren(); |
||||
//// {
|
|
||||
//// var panel = new Panel
|
Assert.Equal(2, children.Count); |
||||
//// {
|
|
||||
//// Children =
|
panel.Children.RemoveAt(1); |
||||
//// {
|
|
||||
//// new Border(),
|
children = target.GetChildren(); |
||||
//// new Border(),
|
Assert.Equal(1, children.Count); |
||||
//// },
|
} |
||||
//// };
|
|
||||
|
[Fact] |
||||
//// var factory = CreateFactory();
|
public void Updates_Children_When_Visibility_Changes() |
||||
//// var target = CreatePeer(factory, panel);
|
{ |
||||
//// var children = target.GetChildren();
|
var panel = new Panel |
||||
|
{ |
||||
//// Assert.Equal(2, children.Count);
|
Children = |
||||
|
{ |
||||
//// panel.Children.RemoveAt(1);
|
new Border(), |
||||
|
new Border(), |
||||
//// children = target.GetChildren();
|
}, |
||||
//// Assert.Equal(1, children.Count);
|
}; |
||||
//// }
|
|
||||
|
var target = CreatePeer(panel); |
||||
//// [Fact]
|
var children = target.GetChildren(); |
||||
//// public void Updates_Children_When_Visibility_Changes()
|
|
||||
//// {
|
Assert.Equal(2, children.Count); |
||||
//// var panel = new Panel
|
|
||||
//// {
|
panel.Children[1].IsVisible = false; |
||||
//// Children =
|
children = target.GetChildren(); |
||||
//// {
|
Assert.Equal(1, children.Count); |
||||
//// new Border(),
|
|
||||
//// new Border(),
|
panel.Children[1].IsVisible = true; |
||||
//// },
|
children = target.GetChildren(); |
||||
//// };
|
Assert.Equal(2, children.Count); |
||||
|
} |
||||
//// var factory = CreateFactory();
|
} |
||||
//// var target = CreatePeer(factory, panel);
|
|
||||
//// var children = target.GetChildren();
|
public class Parent |
||||
|
{ |
||||
//// Assert.Equal(2, children.Count);
|
[Fact] |
||||
|
public void Connects_Peer_To_Tree_When_GetParent_Called() |
||||
//// panel.Children[1].IsVisible = false;
|
{ |
||||
//// children = target.GetChildren();
|
var border = new Border(); |
||||
//// Assert.Equal(1, children.Count);
|
var tree = new Decorator |
||||
|
{ |
||||
//// panel.Children[1].IsVisible = true;
|
Child = new Decorator |
||||
//// children = target.GetChildren();
|
{ |
||||
//// Assert.Equal(2, children.Count);
|
Child = border, |
||||
//// }
|
} |
||||
//// }
|
}; |
||||
|
|
||||
//// public class Parent
|
// We're accessing Border directly without going via its ancestors. Because the tree
|
||||
//// {
|
// is built lazily, ensure that calling GetParent causes the ancestor tree to be built.
|
||||
//// [Fact]
|
var target = CreatePeer(border); |
||||
//// public void Connects_Peer_To_Tree_When_GetParent_Called()
|
|
||||
//// {
|
var parentPeer = Assert.IsAssignableFrom<ControlAutomationPeer>(target.GetParent()); |
||||
//// var border = new Border();
|
Assert.Same(border.GetVisualParent(), parentPeer.Owner); |
||||
//// var tree = new Decorator
|
} |
||||
//// {
|
|
||||
//// Child = new Decorator
|
[Fact] |
||||
//// {
|
public void Parent_Updated_When_Moved_To_Separate_Visual_Tree() |
||||
//// Child = border,
|
{ |
||||
//// }
|
var border = new Border(); |
||||
//// };
|
var root1 = new Decorator { Child = border }; |
||||
|
var root2 = new Decorator(); |
||||
//// var factory = CreateFactory();
|
var target = CreatePeer(border); |
||||
|
|
||||
//// // We're accessing Border directly without going via its ancestors. Because the tree
|
var parentPeer = Assert.IsAssignableFrom<ControlAutomationPeer>(target.GetParent()); |
||||
//// // is built lazily, ensure that calling GetParent causes the ancestor tree to be built.
|
Assert.Same(root1, parentPeer.Owner); |
||||
//// var target = CreatePeer(factory, border);
|
|
||||
|
root1.Child = null; |
||||
//// var parentPeer = Assert.IsAssignableFrom<ControlAutomationPeer>(target.GetParent());
|
|
||||
//// Assert.Same(border.GetVisualParent(), parentPeer.Owner);
|
Assert.Null(target.GetParent()); |
||||
//// }
|
|
||||
|
root2.Child = border; |
||||
//// [Fact]
|
|
||||
//// public void Parent_Updated_When_Moved_To_Separate_Visual_Tree()
|
parentPeer = Assert.IsAssignableFrom<ControlAutomationPeer>(target.GetParent()); |
||||
//// {
|
Assert.Same(root2, parentPeer.Owner); |
||||
//// var border = new Border();
|
} |
||||
//// var root1 = new Decorator { Child = border };
|
} |
||||
//// var root2 = new Decorator();
|
|
||||
//// var factory = CreateFactory();
|
private static AutomationPeer CreatePeer(Control control) |
||||
//// var target = CreatePeer(factory, border);
|
{ |
||||
|
return ControlAutomationPeer.CreatePeerForElement(control); |
||||
//// var parentPeer = Assert.IsAssignableFrom<ControlAutomationPeer>(target.GetParent());
|
} |
||||
//// Assert.Same(root1, parentPeer.Owner);
|
|
||||
|
private class TestControl : Control |
||||
//// root1.Child = null;
|
{ |
||||
|
protected override AutomationPeer OnCreateAutomationPeer() |
||||
//// Assert.Null(target.GetParent());
|
{ |
||||
|
return new TestAutomationPeer(this); |
||||
//// root2.Child = border;
|
} |
||||
|
} |
||||
//// parentPeer = Assert.IsAssignableFrom<ControlAutomationPeer>(target.GetParent());
|
|
||||
//// Assert.Same(root2, parentPeer.Owner);
|
private class AutomationTestRoot : TestRoot |
||||
//// }
|
{ |
||||
//// }
|
protected override AutomationPeer OnCreateAutomationPeer() |
||||
|
{ |
||||
//// private static IAutomationNodeFactory CreateFactory()
|
return new TestRootAutomationPeer(this); |
||||
//// {
|
} |
||||
//// var factory = new Mock<IAutomationNodeFactory>();
|
} |
||||
//// factory.Setup(x => x.CreateNode(It.IsAny<AutomationPeer>()))
|
|
||||
//// .Returns(() => Mock.Of<IAutomationNode>(x => x.Factory == factory.Object));
|
private class TestAutomationPeer : ControlAutomationPeer |
||||
//// return factory.Object;
|
{ |
||||
//// }
|
public TestAutomationPeer( Control owner) |
||||
|
: base(owner) |
||||
//// private static AutomationPeer CreatePeer(IAutomationNodeFactory factory, Control control)
|
{ |
||||
//// {
|
} |
||||
//// return ControlAutomationPeer.GetOrCreatePeer(factory, control);
|
} |
||||
//// }
|
|
||||
|
private class TestRootAutomationPeer : ControlAutomationPeer, IRootProvider |
||||
//// private class TestControl : Control
|
{ |
||||
//// {
|
public TestRootAutomationPeer(Control owner) |
||||
//// protected override AutomationPeer OnCreateAutomationPeer(IAutomationNodeFactory factory)
|
: base(owner) |
||||
//// {
|
{ |
||||
//// return new TestAutomationPeer(factory, this);
|
} |
||||
//// }
|
|
||||
//// }
|
public ITopLevelImpl PlatformImpl => throw new System.NotImplementedException(); |
||||
|
public event EventHandler? FocusChanged; |
||||
//// private class AutomationTestRoot : TestRoot
|
|
||||
//// {
|
public AutomationPeer GetFocus() |
||||
//// protected override AutomationPeer OnCreateAutomationPeer(IAutomationNodeFactory factory)
|
{ |
||||
//// {
|
throw new System.NotImplementedException(); |
||||
//// return new TestRootAutomationPeer(factory, this);
|
} |
||||
//// }
|
|
||||
//// }
|
public AutomationPeer GetPeerFromPoint(Point p) |
||||
|
{ |
||||
//// private class TestAutomationPeer : ControlAutomationPeer
|
throw new System.NotImplementedException(); |
||||
//// {
|
} |
||||
//// public TestAutomationPeer(IAutomationNodeFactory factory, Control owner)
|
} |
||||
//// : base(factory, owner)
|
} |
||||
//// {
|
} |
||||
//// }
|
|
||||
//// }
|
|
||||
|
|
||||
//// private class TestRootAutomationPeer : ControlAutomationPeer, IRootProvider
|
|
||||
//// {
|
|
||||
//// public TestRootAutomationPeer(IAutomationNodeFactory factory, Control owner)
|
|
||||
//// : base(factory, owner)
|
|
||||
//// {
|
|
||||
//// }
|
|
||||
|
|
||||
//// public ITopLevelImpl PlatformImpl => throw new System.NotImplementedException();
|
|
||||
|
|
||||
//// public AutomationPeer GetFocus()
|
|
||||
//// {
|
|
||||
//// throw new System.NotImplementedException();
|
|
||||
//// }
|
|
||||
|
|
||||
//// public AutomationPeer GetPeerFromPoint(Point p)
|
|
||||
//// {
|
|
||||
//// throw new System.NotImplementedException();
|
|
||||
//// }
|
|
||||
//// }
|
|
||||
//// }
|
|
||||
////}
|
|
||||
|
|||||
Loading…
Reference in new issue