|
|
|
@ -137,8 +137,10 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Child_windows_should_be_closed_before_parent_OSCloseButton() |
|
|
|
[Theory] |
|
|
|
[InlineData(true)] |
|
|
|
[InlineData(false)] |
|
|
|
public void Child_windows_should_be_closed_before_parent(bool programaticClose) |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
@ -178,112 +180,16 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
window.Show(); |
|
|
|
child.Show(window); |
|
|
|
|
|
|
|
var cancel = window.PlatformImpl.Closing(); |
|
|
|
|
|
|
|
Assert.Equal(false, cancel); |
|
|
|
|
|
|
|
Assert.Equal(2, windowClosing); |
|
|
|
Assert.Equal(1, childClosing); |
|
|
|
Assert.Equal(4, windowClosed); |
|
|
|
Assert.Equal(3, childClosed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Child_windows_must_not_close_before_parent_has_chance_to_Cancel_OSCloseButton() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var window = new Window(); |
|
|
|
var child = new Window(); |
|
|
|
|
|
|
|
int count = 0; |
|
|
|
int windowClosing = 0; |
|
|
|
int childClosing = 0; |
|
|
|
int windowClosed = 0; |
|
|
|
int childClosed = 0; |
|
|
|
|
|
|
|
window.Closing += (sender, e) => |
|
|
|
{ |
|
|
|
count++; |
|
|
|
windowClosing = count; |
|
|
|
e.Cancel = true; |
|
|
|
}; |
|
|
|
|
|
|
|
child.Closing += (sender, e) => |
|
|
|
{ |
|
|
|
count++; |
|
|
|
childClosing = count; |
|
|
|
}; |
|
|
|
|
|
|
|
window.Closed += (sender, e) => |
|
|
|
if (programaticClose) |
|
|
|
{ |
|
|
|
count++; |
|
|
|
windowClosed = count; |
|
|
|
}; |
|
|
|
|
|
|
|
child.Closed += (sender, e) => |
|
|
|
{ |
|
|
|
count++; |
|
|
|
childClosed = count; |
|
|
|
}; |
|
|
|
|
|
|
|
window.Show(); |
|
|
|
child.Show(window); |
|
|
|
|
|
|
|
var cancel = window.PlatformImpl.Closing(); |
|
|
|
|
|
|
|
Assert.Equal(true, cancel); |
|
|
|
|
|
|
|
Assert.Equal(2, windowClosing); |
|
|
|
Assert.Equal(1, childClosing); |
|
|
|
Assert.Equal(0, windowClosed); |
|
|
|
Assert.Equal(0, childClosed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Child_windows_should_be_closed_before_parent_Programatically() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var window = new Window(); |
|
|
|
var child = new Window(); |
|
|
|
|
|
|
|
int count = 0; |
|
|
|
int windowClosing = 0; |
|
|
|
int childClosing = 0; |
|
|
|
int windowClosed = 0; |
|
|
|
int childClosed = 0; |
|
|
|
|
|
|
|
window.Closing += (sender, e) => |
|
|
|
{ |
|
|
|
count++; |
|
|
|
windowClosing = count; |
|
|
|
}; |
|
|
|
|
|
|
|
child.Closing += (sender, e) => |
|
|
|
{ |
|
|
|
count++; |
|
|
|
childClosing = count; |
|
|
|
}; |
|
|
|
|
|
|
|
window.Closed += (sender, e) => |
|
|
|
{ |
|
|
|
count++; |
|
|
|
windowClosed = count; |
|
|
|
}; |
|
|
|
|
|
|
|
child.Closed += (sender, e) => |
|
|
|
window.Close(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
count++; |
|
|
|
childClosed = count; |
|
|
|
}; |
|
|
|
var cancel = window.PlatformImpl.Closing(); |
|
|
|
|
|
|
|
window.Show(); |
|
|
|
child.Show(window); |
|
|
|
|
|
|
|
window.Close(); |
|
|
|
Assert.Equal(false, cancel); |
|
|
|
} |
|
|
|
|
|
|
|
Assert.Equal(2, windowClosing); |
|
|
|
Assert.Equal(1, childClosing); |
|
|
|
@ -292,8 +198,10 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Child_windows_must_not_close_before_parent_has_chance_to_Cancel_Programatically() |
|
|
|
[Theory] |
|
|
|
[InlineData(true)] |
|
|
|
[InlineData(false)] |
|
|
|
public void Child_windows_must_not_close_before_parent_has_chance_to_Cancel_OSCloseButton(bool programaticClose) |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
@ -334,7 +242,16 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
window.Show(); |
|
|
|
child.Show(window); |
|
|
|
|
|
|
|
window.Close(); |
|
|
|
if (programaticClose) |
|
|
|
{ |
|
|
|
window.Close(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var cancel = window.PlatformImpl.Closing(); |
|
|
|
|
|
|
|
Assert.Equal(true, cancel); |
|
|
|
} |
|
|
|
|
|
|
|
Assert.Equal(2, windowClosing); |
|
|
|
Assert.Equal(1, childClosing); |
|
|
|
|