Browse Source

Run sizing tests with both Show and ShowDialog.

One test now failing with `ShowDialog` due to #3843.
pull/3856/head
Steven Kirk 7 years ago
parent
commit
dc75bf512a
  1. 313
      tests/Avalonia.Controls.UnitTests/WindowTests.cs

313
tests/Avalonia.Controls.UnitTests/WindowTests.cs

@ -336,210 +336,227 @@ namespace Avalonia.Controls.UnitTests
} }
} }
[Fact] public class SizingTests
public void Child_Should_Be_Measured_With_Width_And_Height_If_SizeToContent_Is_Manual()
{ {
using (UnitTestApplication.Start(TestServices.StyledWindow)) [Fact]
public void Child_Should_Be_Measured_With_Width_And_Height_If_SizeToContent_Is_Manual()
{ {
var child = new ChildControl(); using (UnitTestApplication.Start(TestServices.StyledWindow))
var target = new Window {
{ var child = new ChildControl();
Width = 100, var target = new Window
Height = 50, {
SizeToContent = SizeToContent.Manual, Width = 100,
Content = child Height = 50,
}; SizeToContent = SizeToContent.Manual,
Content = child
};
target.Show(); Show(target);
Assert.Equal(1, child.MeasureSizes.Count); Assert.Equal(1, child.MeasureSizes.Count);
Assert.Equal(new Size(100, 50), child.MeasureSizes[0]); Assert.Equal(new Size(100, 50), child.MeasureSizes[0]);
}
} }
}
[Fact] [Fact]
public void Child_Should_Be_Measured_With_ClientSize_If_SizeToContent_Is_Manual_And_No_Width_Height_Specified() public void Child_Should_Be_Measured_With_ClientSize_If_SizeToContent_Is_Manual_And_No_Width_Height_Specified()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{ {
var windowImpl = MockWindowingPlatform.CreateWindowMock(); using (UnitTestApplication.Start(TestServices.StyledWindow))
windowImpl.Setup(x => x.ClientSize).Returns(new Size(550, 450));
var child = new ChildControl();
var target = new Window(windowImpl.Object)
{ {
SizeToContent = SizeToContent.Manual, var windowImpl = MockWindowingPlatform.CreateWindowMock();
Content = child windowImpl.Setup(x => x.ClientSize).Returns(new Size(550, 450));
};
target.Show(); var child = new ChildControl();
var target = new Window(windowImpl.Object)
{
SizeToContent = SizeToContent.Manual,
Content = child
};
Assert.Equal(1, child.MeasureSizes.Count); Show(target);
Assert.Equal(new Size(550, 450), child.MeasureSizes[0]);
Assert.Equal(1, child.MeasureSizes.Count);
Assert.Equal(new Size(550, 450), child.MeasureSizes[0]);
}
} }
}
[Fact] [Fact]
public void Child_Should_Be_Measured_With_Infinity_If_SizeToContent_Is_WidthAndHeight() public void Child_Should_Be_Measured_With_Infinity_If_SizeToContent_Is_WidthAndHeight()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{ {
var child = new ChildControl(); using (UnitTestApplication.Start(TestServices.StyledWindow))
var target = new Window
{ {
Width = 100, var child = new ChildControl();
Height = 50, var target = new Window
SizeToContent = SizeToContent.WidthAndHeight, {
Content = child Width = 100,
}; Height = 50,
SizeToContent = SizeToContent.WidthAndHeight,
Content = child
};
target.Show(); Show(target);
Assert.Equal(1, child.MeasureSizes.Count); Assert.Equal(1, child.MeasureSizes.Count);
Assert.Equal(Size.Infinity, child.MeasureSizes[0]); Assert.Equal(Size.Infinity, child.MeasureSizes[0]);
}
} }
}
[Fact] [Fact]
public void Should_Not_Have_Offset_On_Bounds_When_Content_Larger_Than_Max_Window_Size() public void Should_Not_Have_Offset_On_Bounds_When_Content_Larger_Than_Max_Window_Size()
{
// Issue #3784.
using (UnitTestApplication.Start(TestServices.StyledWindow))
{ {
var windowImpl = MockWindowingPlatform.CreateWindowMock(); // Issue #3784.
var clientSize = new Size(200, 200); using (UnitTestApplication.Start(TestServices.StyledWindow))
var maxClientSize = new Size(480, 480);
windowImpl.Setup(x => x.Resize(It.IsAny<Size>())).Callback<Size>(size =>
{ {
clientSize = size.Constrain(maxClientSize); var windowImpl = MockWindowingPlatform.CreateWindowMock();
windowImpl.Object.Resized?.Invoke(clientSize); var clientSize = new Size(200, 200);
}); var maxClientSize = new Size(480, 480);
windowImpl.Setup(x => x.ClientSize).Returns(() => clientSize); windowImpl.Setup(x => x.Resize(It.IsAny<Size>())).Callback<Size>(size =>
{
clientSize = size.Constrain(maxClientSize);
windowImpl.Object.Resized?.Invoke(clientSize);
});
var child = new Canvas windowImpl.Setup(x => x.ClientSize).Returns(() => clientSize);
{
Width = 400,
Height = 800,
};
var target = new Window(windowImpl.Object)
{
SizeToContent = SizeToContent.WidthAndHeight,
Content = child
};
target.Show(); var child = new Canvas
{
Width = 400,
Height = 800,
};
var target = new Window(windowImpl.Object)
{
SizeToContent = SizeToContent.WidthAndHeight,
Content = child
};
Show(target);
Assert.Equal(new Size(400, 480), target.Bounds.Size); Assert.Equal(new Size(400, 480), target.Bounds.Size);
// Issue #3784 causes this to be (0, 160) which makes no sense as Window has no // Issue #3784 causes this to be (0, 160) which makes no sense as Window has no
// parent control to be offset against. // parent control to be offset against.
Assert.Equal(new Point(0, 0), target.Bounds.Position); Assert.Equal(new Point(0, 0), target.Bounds.Position);
}
} }
}
[Fact] [Fact]
public void Width_Height_Should_Not_Be_NaN_After_Show_With_SizeToContent_WidthAndHeight() public void Width_Height_Should_Not_Be_NaN_After_Show_With_SizeToContent_WidthAndHeight()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{ {
var child = new Canvas using (UnitTestApplication.Start(TestServices.StyledWindow))
{ {
Width = 400, var child = new Canvas
Height = 800, {
}; Width = 400,
Height = 800,
};
var target = new Window() var target = new Window()
{ {
SizeToContent = SizeToContent.WidthAndHeight, SizeToContent = SizeToContent.WidthAndHeight,
Content = child Content = child
}; };
target.Show(); Show(target);
Assert.Equal(400, target.Width); Assert.Equal(400, target.Width);
Assert.Equal(800, target.Height); Assert.Equal(800, target.Height);
}
} }
}
[Fact] [Fact]
public void SizeToContent_Should_Not_Be_Lost_On_Show() public void SizeToContent_Should_Not_Be_Lost_On_Show()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{ {
var child = new Canvas using (UnitTestApplication.Start(TestServices.StyledWindow))
{ {
Width = 400, var child = new Canvas
Height = 800, {
}; Width = 400,
Height = 800,
};
var target = new Window() var target = new Window()
{ {
SizeToContent = SizeToContent.WidthAndHeight, SizeToContent = SizeToContent.WidthAndHeight,
Content = child Content = child
}; };
target.Show(); Show(target);
Assert.Equal(SizeToContent.WidthAndHeight, target.SizeToContent); Assert.Equal(SizeToContent.WidthAndHeight, target.SizeToContent);
}
} }
}
[Fact] [Fact]
public void Width_Height_Should_Be_Updated_When_SizeToContent_Is_WidthAndHeight() public void Width_Height_Should_Be_Updated_When_SizeToContent_Is_WidthAndHeight()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{ {
var child = new Canvas using (UnitTestApplication.Start(TestServices.StyledWindow))
{ {
Width = 400, var child = new Canvas
Height = 800, {
}; Width = 400,
Height = 800,
};
var target = new Window() var target = new Window()
{ {
SizeToContent = SizeToContent.WidthAndHeight, SizeToContent = SizeToContent.WidthAndHeight,
Content = child Content = child
}; };
target.Show(); Show(target);
Assert.Equal(400, target.Width); Assert.Equal(400, target.Width);
Assert.Equal(800, target.Height); Assert.Equal(800, target.Height);
child.Width = 410; child.Width = 410;
target.LayoutManager.ExecuteLayoutPass(); target.LayoutManager.ExecuteLayoutPass();
Assert.Equal(410, target.Width); Assert.Equal(410, target.Width);
Assert.Equal(800, target.Height); Assert.Equal(800, target.Height);
Assert.Equal(SizeToContent.WidthAndHeight, target.SizeToContent); Assert.Equal(SizeToContent.WidthAndHeight, target.SizeToContent);
}
} }
}
[Fact] [Fact]
public void Setting_Width_Should_Resize_WindowImpl() public void Setting_Width_Should_Resize_WindowImpl()
{
// Issue #3796
using (UnitTestApplication.Start(TestServices.StyledWindow))
{ {
var target = new Window() // Issue #3796
using (UnitTestApplication.Start(TestServices.StyledWindow))
{ {
Width = 400, var target = new Window()
Height = 800, {
}; Width = 400,
Height = 800,
};
target.Show(); Show(target);
Assert.Equal(400, target.Width);
Assert.Equal(800, target.Height);
Assert.Equal(400, target.Width); target.Width = 410;
Assert.Equal(800, target.Height); target.LayoutManager.ExecuteLayoutPass();
target.Width = 410; var windowImpl = Mock.Get(target.PlatformImpl);
target.LayoutManager.ExecuteLayoutPass(); windowImpl.Verify(x => x.Resize(new Size(410, 800)));
Assert.Equal(410, target.Width);
}
}
var windowImpl = Mock.Get(target.PlatformImpl); protected virtual void Show(Window window)
windowImpl.Verify(x => x.Resize(new Size(410, 800))); {
Assert.Equal(410, target.Width); window.Show();
}
}
public class DialogSizingTests : SizingTests
{
protected override void Show(Window window)
{
var owner = new Window();
window.ShowDialog(owner);
} }
} }

Loading…
Cancel
Save