diff --git a/.editorconfig b/.editorconfig index c7a381b730..25e0135725 100644 --- a/.editorconfig +++ b/.editorconfig @@ -137,7 +137,7 @@ space_within_single_line_array_initializer_braces = true csharp_wrap_before_ternary_opsigns = false # Xaml files -[*.xaml] +[*.{xaml,axaml}] indent_size = 2 # Xml project files diff --git a/Avalonia.sln b/Avalonia.sln index 96d35e1bb9..0dae88db96 100644 --- a/Avalonia.sln +++ b/Avalonia.sln @@ -234,7 +234,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniMvvm", "samples\MiniMvv EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntegrationTestApp", "samples\IntegrationTestApp\IntegrationTestApp.csproj", "{676D6BFD-029D-4E43-BFC7-3892265CE251}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.IntegrationTests.Win32", "tests\Avalonia.IntegrationTests.Win32\Avalonia.IntegrationTests.Win32.csproj", "{F2CE566B-E7F6-447A-AB1A-3F574A6FE43A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.IntegrationTests.Win32", "tests\Avalonia.IntegrationTests.Win32\Avalonia.IntegrationTests.Win32.csproj", "{F2CE566B-E7F6-447A-AB1A-3F574A6FE43A}" EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution @@ -2235,6 +2235,7 @@ Global {29132311-1848-4FD6-AE0C-4FF841151BD3} = {9B9E3891-2366-4253-A952-D08BCEB71098} {7D2D3083-71DD-4CC9-8907-39A0D86FB322} = {3743B0F2-CC41-4F14-A8C8-267F579BF91E} {39D7B147-1A5B-47C2-9D01-21FB7C47C4B3} = {9B9E3891-2366-4253-A952-D08BCEB71098} + {86C53C40-57AA-45B8-AD42-FAE0EFDF0F2B} = {A689DEF5-D50F-4975-8B72-124C9EB54066} {854568D5-13D1-4B4F-B50D-534DC7EFD3C9} = {86C53C40-57AA-45B8-AD42-FAE0EFDF0F2B} {638580B0-7910-40EF-B674-DCB34DA308CD} = {A0CC0258-D18C-4AB3-854F-7101680FC3F9} {CBC4FF2F-92D4-420B-BE21-9FE0B930B04E} = {B39A8919-9F95-48FE-AD7B-76E08B509888} diff --git a/samples/IntegrationTestApp/MainWindow.axaml b/samples/IntegrationTestApp/MainWindow.axaml index f70e3ab040..098b4dc3aa 100644 --- a/samples/IntegrationTestApp/MainWindow.axaml +++ b/samples/IntegrationTestApp/MainWindow.axaml @@ -9,31 +9,40 @@ + + + + Unchecked + Checked + ThreeState + + + - - - Foo - Bar - - - Foo - Bar - - - Foo - Bar - - + + + Foo + Bar + + + Foo + Bar + + + Foo + Bar + + diff --git a/src/Avalonia.Controls/Automation/Peers/ToggleButtonAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/ToggleButtonAutomationPeer.cs index b103df3165..4c410d8654 100644 --- a/src/Avalonia.Controls/Automation/Peers/ToggleButtonAutomationPeer.cs +++ b/src/Avalonia.Controls/Automation/Peers/ToggleButtonAutomationPeer.cs @@ -35,5 +35,8 @@ namespace Avalonia.Automation.Peers { return AutomationControlType.Button; } + + protected override bool IsContentElementCore() => true; + protected override bool IsControlElementCore() => true; } } diff --git a/tests/Avalonia.IntegrationTests.Win32/CheckBoxTests.cs b/tests/Avalonia.IntegrationTests.Win32/CheckBoxTests.cs new file mode 100644 index 0000000000..ebf7408eab --- /dev/null +++ b/tests/Avalonia.IntegrationTests.Win32/CheckBoxTests.cs @@ -0,0 +1,72 @@ +using OpenQA.Selenium.Appium.Windows; +using Xunit; + +namespace Avalonia.IntegrationTests.Win32 +{ + [Collection("Default")] + public class CheckBoxTests + { + private WindowsDriver _session; + + public CheckBoxTests(TestAppFixture fixture) + { + _session = fixture.Session; + + var tabs = _session.FindElementByAccessibilityId("MainTabs"); + var tab = tabs.FindElementByName("CheckBox"); + tab.Click(); + } + + [Fact] + public void UncheckedCheckBox() + { + var checkBox = _session.FindElementByAccessibilityId("UncheckedCheckBox"); + + Assert.Equal("Unchecked", checkBox.Text); + Assert.False(checkBox.Selected); + Assert.Equal("0", checkBox.GetAttribute("Toggle.ToggleState")); + + checkBox.Click(); + + Assert.True(checkBox.Selected); + Assert.Equal("1", checkBox.GetAttribute("Toggle.ToggleState")); + } + + [Fact] + public void CheckedCheckBox() + { + var checkBox = _session.FindElementByAccessibilityId("CheckedCheckBox"); + + Assert.Equal("Checked", checkBox.Text); + Assert.True(checkBox.Selected); + Assert.Equal("1", checkBox.GetAttribute("Toggle.ToggleState")); + + checkBox.Click(); + + Assert.False(checkBox.Selected); + Assert.Equal("0", checkBox.GetAttribute("Toggle.ToggleState")); + } + + [Fact] + public void ThreeStateCheckBox() + { + var checkBox = _session.FindElementByAccessibilityId("ThreeStateCheckBox"); + + Assert.Equal("ThreeState", checkBox.Text); + Assert.Equal("2", checkBox.GetAttribute("Toggle.ToggleState")); + + checkBox.Click(); + + Assert.False(checkBox.Selected); + Assert.Equal("0", checkBox.GetAttribute("Toggle.ToggleState")); + + checkBox.Click(); + + Assert.True(checkBox.Selected); + Assert.Equal("1", checkBox.GetAttribute("Toggle.ToggleState")); + + checkBox.Click(); + Assert.Equal("2", checkBox.GetAttribute("Toggle.ToggleState")); + } + } +} diff --git a/tests/Avalonia.IntegrationTests.Win32/TestAppFixture.cs b/tests/Avalonia.IntegrationTests.Win32/TestAppFixture.cs index 6337ff1c6f..fe2daa3cd0 100644 --- a/tests/Avalonia.IntegrationTests.Win32/TestAppFixture.cs +++ b/tests/Avalonia.IntegrationTests.Win32/TestAppFixture.cs @@ -1,5 +1,7 @@ using System; +using System.Globalization; using System.IO; +using System.Runtime.InteropServices; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Windows; @@ -19,10 +21,19 @@ namespace Avalonia.IntegrationTests.Win32 Session = new WindowsDriver( new Uri(WindowsApplicationDriverUrl), opts); + + // https://github.com/microsoft/WinAppDriver/issues/1025 + SetForegroundWindow(new IntPtr(int.Parse( + Session.WindowHandles[0].Substring(2), + NumberStyles.AllowHexSpecifier))); } public WindowsDriver Session { get; } public void Dispose() => Session.Close(); + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool SetForegroundWindow(IntPtr hWnd); } }