From 15a6a6a9c2d1f2e9e5cebd265bf81e6a321d4cc3 Mon Sep 17 00:00:00 2001 From: Samantha Houts Date: Tue, 9 May 2017 23:50:20 -0700 Subject: [PATCH] [Core] Accessibility works with XamlC (#911) * Add unit tests for a11y XAML parsing * [Core] Add Get/Set methods for XamlC * Update docs * Fix rogue blank line --- Xamarin.Forms.Core/Accessibility.cs | 42 +++++- Xamarin.Forms.Xaml.UnitTests/Accessibility.xaml | 16 ++ Xamarin.Forms.Xaml.UnitTests/Accessibility.xaml.cs | 75 ++++++++++ .../Xamarin.Forms.Xaml.UnitTests.csproj | 31 ++-- .../Xamarin.Forms/Accessibility.xml | 164 +++++++++++++++++++++ 5 files changed, 317 insertions(+), 11 deletions(-) create mode 100644 Xamarin.Forms.Xaml.UnitTests/Accessibility.xaml create mode 100644 Xamarin.Forms.Xaml.UnitTests/Accessibility.xaml.cs diff --git a/Xamarin.Forms.Core/Accessibility.cs b/Xamarin.Forms.Core/Accessibility.cs index e866d31..074d5c5 100644 --- a/Xamarin.Forms.Core/Accessibility.cs +++ b/Xamarin.Forms.Core/Accessibility.cs @@ -1,4 +1,4 @@ - + namespace Xamarin.Forms { public class Accessibility @@ -10,5 +10,45 @@ namespace Xamarin.Forms public static readonly BindableProperty LabeledByProperty = BindableProperty.Create("LabeledBy", typeof(VisualElement), typeof(Element), default(VisualElement)); public static readonly BindableProperty NameProperty = BindableProperty.Create("Name", typeof(string), typeof(Element), default(string)); + + public static string GetHint(BindableObject bindable) + { + return (string)bindable.GetValue(HintProperty); + } + + public static bool? GetIsInAccessibleTree(BindableObject bindable) + { + return (bool?)bindable.GetValue(IsInAccessibleTreeProperty); + } + + public static VisualElement GetLabeledBy(BindableObject bindable) + { + return (VisualElement)bindable.GetValue(LabeledByProperty); + } + + public static string GetName(BindableObject bindable) + { + return (string)bindable.GetValue(NameProperty); + } + + public static void SetHint(BindableObject bindable, string value) + { + bindable.SetValue(HintProperty, value); + } + + public static void SetIsInAccessibleTree(BindableObject bindable, bool? value) + { + bindable.SetValue(IsInAccessibleTreeProperty, value); + } + + public static void SetLabeledBy(BindableObject bindable, VisualElement value) + { + bindable.SetValue(LabeledByProperty, value); + } + + public static void SetName(BindableObject bindable, string value) + { + bindable.SetValue(NameProperty, value); + } } } diff --git a/Xamarin.Forms.Xaml.UnitTests/Accessibility.xaml b/Xamarin.Forms.Xaml.UnitTests/Accessibility.xaml new file mode 100644 index 0000000..6c4b32b --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Accessibility.xaml @@ -0,0 +1,16 @@ + + + + + + + \ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Accessibility.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Accessibility.xaml.cs new file mode 100644 index 0000000..2bcaab3 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Accessibility.xaml.cs @@ -0,0 +1,75 @@ +using System; +using NUnit.Framework; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Accessibility : ContentPage + { + public Accessibility() + { + InitializeComponent(); + } + + public Accessibility(bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [SetUp] + public void Setup() + { + Device.PlatformServices = new MockPlatformServices(); + Application.Current = new MockApplication(); + } + + [TearDown] + public void TearDown() + { + Device.PlatformServices = null; + Application.Current = null; + } + + [TestCase(false)] + [TestCase(true)] + public void AccessibilityName(bool useCompiledXaml) + { + var layout = new Accessibility(useCompiledXaml); + + Assert.AreEqual("Name", (string)layout.entry.GetValue(Xamarin.Forms.Accessibility.NameProperty)); + } + + [TestCase(false)] + [TestCase(true)] + public void AccessibilityHint(bool useCompiledXaml) + { + var layout = new Accessibility(useCompiledXaml); + + Assert.AreEqual("Sets your name", (string)layout.entry.GetValue(Xamarin.Forms.Accessibility.HintProperty)); + } + + [TestCase(false)] + [TestCase(true)] + public void AccessibilityIsInAccessibleTree(bool useCompiledXaml) + { + var layout = new Accessibility(useCompiledXaml); + Application.Current.MainPage = layout; + + Assert.AreEqual(true, (bool)layout.entry.GetValue(Xamarin.Forms.Accessibility.IsInAccessibleTreeProperty)); + } + + [TestCase(false)] + [TestCase(true)] + public void AccessibilityLabeledBy(bool useCompiledXaml) + { + var layout = new Accessibility(useCompiledXaml); + Application.Current.MainPage = layout; + + Assert.AreEqual(layout.label, (Element)layout.entry.GetValue(Xamarin.Forms.Accessibility.LabeledByProperty)); + } + } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj index 123a0d5..ee6b686 100644 --- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj +++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj @@ -76,6 +76,9 @@ MockPlatformServices.cs + + Accessibility.xaml + Bz43450.xaml @@ -387,19 +390,19 @@ Bz47703.xaml - - FactoryMethodMissingCtor.xaml - - - FactoryMethodMissingMethod.xaml - + + FactoryMethodMissingCtor.xaml + + + FactoryMethodMissingMethod.xaml + Bz46921.xaml - - I8.xaml - + + I8.xaml + Bz49307.xaml @@ -482,6 +485,9 @@ Bz55347.xaml + + FieldModifier.xaml + @@ -914,4 +920,9 @@ MSBuild:UpdateDesignTimeXaml - + + + MSBuild:UpdateDesignTimeXaml + + + \ No newline at end of file diff --git a/docs/Xamarin.Forms.Core/Xamarin.Forms/Accessibility.xml b/docs/Xamarin.Forms.Core/Xamarin.Forms/Accessibility.xml index fbcb785..ee40199 100644 --- a/docs/Xamarin.Forms.Core/Xamarin.Forms/Accessibility.xml +++ b/docs/Xamarin.Forms.Core/Xamarin.Forms/Accessibility.xml @@ -27,6 +27,86 @@ To be added. + + + + Method + + 2.0.0.0 + + + System.String + + + + + + To be added. + To be added. + To be added. + To be added. + + + + + + Method + + 2.0.0.0 + + + System.Nullable<System.Boolean> + + + + + + To be added. + To be added. + To be added. + To be added. + + + + + + Method + + 2.0.0.0 + + + Xamarin.Forms.VisualElement + + + + + + To be added. + To be added. + To be added. + To be added. + + + + + + Method + + 2.0.0.0 + + + System.String + + + + + + To be added. + To be added. + To be added. + To be added. + + @@ -87,5 +167,89 @@ To be added. + + + + Method + + 2.0.0.0 + + + System.Void + + + + + + + To be added. + To be added. + To be added. + To be added. + + + + + + Method + + 2.0.0.0 + + + System.Void + + + + + + + To be added. + To be added. + To be added. + To be added. + + + + + + Method + + 2.0.0.0 + + + System.Void + + + + + + + To be added. + To be added. + To be added. + To be added. + + + + + + Method + + 2.0.0.0 + + + System.Void + + + + + + + To be added. + To be added. + To be added. + To be added. + + -- 2.7.4