|
|
@@ -11,6 +11,7 @@ using Avalonia.Input.Platform;
|
|
|
using Avalonia.Layout;
|
|
|
using Avalonia.Media;
|
|
|
using Avalonia.Platform;
|
|
|
+using Avalonia.Rendering;
|
|
|
using Avalonia.UnitTests;
|
|
|
using Moq;
|
|
|
using Xunit;
|
|
|
@@ -760,18 +761,24 @@ namespace Avalonia.Controls.UnitTests
|
|
|
SelectionStart = selectionStart,
|
|
|
SelectionEnd = selectionEnd
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
+ var impl = CreateMockTopLevelImpl();
|
|
|
+ var topLevel = new TestTopLevel(impl.Object)
|
|
|
+ {
|
|
|
+ Template = CreateTopLevelTemplate()
|
|
|
+ };
|
|
|
+ topLevel.Content = target;
|
|
|
+ topLevel.ApplyTemplate();
|
|
|
+ topLevel.LayoutManager.ExecuteInitialLayoutPass();
|
|
|
+
|
|
|
target.Measure(Size.Infinity);
|
|
|
|
|
|
if (fromClipboard)
|
|
|
{
|
|
|
- AvaloniaLocator.CurrentMutable.Bind<IClipboard>().ToSingleton<ClipboardStub>();
|
|
|
-
|
|
|
- var clipboard = AvaloniaLocator.CurrentMutable.GetRequiredService<IClipboard>();
|
|
|
- clipboard.SetTextAsync(textInput).GetAwaiter().GetResult();
|
|
|
+ topLevel.Clipboard?.SetTextAsync(textInput).GetAwaiter().GetResult();
|
|
|
|
|
|
RaiseKeyEvent(target, Key.V, KeyModifiers.Control);
|
|
|
- clipboard.ClearAsync().GetAwaiter().GetResult();
|
|
|
+ topLevel.Clipboard?.ClearAsync().GetAwaiter().GetResult();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -799,11 +806,19 @@ namespace Avalonia.Controls.UnitTests
|
|
|
AcceptsReturn = true,
|
|
|
AcceptsTab = true
|
|
|
};
|
|
|
+
|
|
|
+ var impl = CreateMockTopLevelImpl();
|
|
|
+ var topLevel = new TestTopLevel(impl.Object)
|
|
|
+ {
|
|
|
+ Template = CreateTopLevelTemplate()
|
|
|
+ };
|
|
|
+ topLevel.Content = target;
|
|
|
+ topLevel.ApplyTemplate();
|
|
|
+ topLevel.LayoutManager.ExecuteInitialLayoutPass();
|
|
|
+
|
|
|
target.ApplyTemplate();
|
|
|
target.SelectionStart = 1;
|
|
|
target.SelectionEnd = 3;
|
|
|
- AvaloniaLocator.CurrentMutable
|
|
|
- .Bind<Input.Platform.IClipboard>().ToSingleton<ClipboardStub>();
|
|
|
|
|
|
RaiseKeyEvent(target, key, modifiers);
|
|
|
RaiseKeyEvent(target, Key.Z, KeyModifiers.Control); // undo
|
|
|
@@ -872,15 +887,21 @@ namespace Avalonia.Controls.UnitTests
|
|
|
AcceptsReturn= true
|
|
|
};
|
|
|
|
|
|
- target.Measure(Size.Infinity);
|
|
|
+ var impl = CreateMockTopLevelImpl();
|
|
|
+ var topLevel = new TestTopLevel(impl.Object)
|
|
|
+ {
|
|
|
+ Template = CreateTopLevelTemplate()
|
|
|
+ };
|
|
|
+ topLevel.Content = target;
|
|
|
+ topLevel.ApplyTemplate();
|
|
|
+ topLevel.LayoutManager.ExecuteInitialLayoutPass();
|
|
|
|
|
|
- AvaloniaLocator.CurrentMutable.Bind<IClipboard>().ToSingleton<ClipboardStub>();
|
|
|
+ target.Measure(Size.Infinity);
|
|
|
|
|
|
- var clipboard = AvaloniaLocator.CurrentMutable.GetRequiredService<IClipboard>();
|
|
|
- clipboard.SetTextAsync(Environment.NewLine).GetAwaiter().GetResult();
|
|
|
+ topLevel.Clipboard?.SetTextAsync(Environment.NewLine).GetAwaiter().GetResult();
|
|
|
|
|
|
RaiseKeyEvent(target, Key.V, KeyModifiers.Control);
|
|
|
- clipboard.ClearAsync().GetAwaiter().GetResult();
|
|
|
+ topLevel.Clipboard?.ClearAsync().GetAwaiter().GetResult();
|
|
|
|
|
|
RaiseTextEvent(target, Environment.NewLine);
|
|
|
|
|
|
@@ -1176,7 +1197,41 @@ namespace Avalonia.Controls.UnitTests
|
|
|
|
|
|
public Task<object> GetDataAsync(string format) => Task.FromResult((object)null);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ private class TestTopLevel : TopLevel
|
|
|
+ {
|
|
|
+ private readonly ILayoutManager _layoutManager;
|
|
|
+
|
|
|
+ public TestTopLevel(ITopLevelImpl impl, ILayoutManager layoutManager = null)
|
|
|
+ : base(impl)
|
|
|
+ {
|
|
|
+ _layoutManager = layoutManager ?? new LayoutManager(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override ILayoutManager CreateLayoutManager() => _layoutManager;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Mock<ITopLevelImpl> CreateMockTopLevelImpl()
|
|
|
+ {
|
|
|
+ var clipboard = new Mock<ITopLevelImpl>();
|
|
|
+ clipboard.Setup(r => r.CreateRenderer(It.IsAny<IRenderRoot>()))
|
|
|
+ .Returns(RendererMocks.CreateRenderer().Object);
|
|
|
+ clipboard.Setup(r => r.TryGetFeature(typeof(IClipboard)))
|
|
|
+ .Returns(new ClipboardStub());
|
|
|
+ clipboard.SetupGet(x => x.RenderScaling).Returns(1);
|
|
|
+ return clipboard;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static FuncControlTemplate<TestTopLevel> CreateTopLevelTemplate()
|
|
|
+ {
|
|
|
+ return new FuncControlTemplate<TestTopLevel>((x, scope) =>
|
|
|
+ new ContentPresenter
|
|
|
+ {
|
|
|
+ Name = "PART_ContentPresenter",
|
|
|
+ [!ContentPresenter.ContentProperty] = x[!ContentControl.ContentProperty],
|
|
|
+ }.RegisterInNameScope(scope));
|
|
|
+ }
|
|
|
+
|
|
|
private class TestContextMenu : ContextMenu
|
|
|
{
|
|
|
public TestContextMenu()
|