diff --git a/src/System.Windows.Forms/src/PublicAPI.Unshipped.txt b/src/System.Windows.Forms/src/PublicAPI.Unshipped.txt index e69de29bb2d..556fb2f410f 100644 --- a/src/System.Windows.Forms/src/PublicAPI.Unshipped.txt +++ b/src/System.Windows.Forms/src/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +~override System.Windows.Forms.TrackBar.CreateAccessibilityInstance() -> System.Windows.Forms.AccessibleObject \ No newline at end of file diff --git a/src/System.Windows.Forms/src/Resources/SR.resx b/src/System.Windows.Forms/src/Resources/SR.resx index 936df4dc4cd..3916789d57d 100644 --- a/src/System.Windows.Forms/src/Resources/SR.resx +++ b/src/System.Windows.Forms/src/Resources/SR.resx @@ -6764,4 +6764,13 @@ Stack trace where the illegal operation occurred was: The current accessibility object is only for the ListView in {0}, {1} or {2} view - + + Large decrease + + + Large increase + + + Position + + \ No newline at end of file diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.cs.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.cs.xlf index 273e7d8f50d..2fcb449aa9b 100644 --- a/src/System.Windows.Forms/src/Resources/xlf/SR.cs.xlf +++ b/src/System.Windows.Forms/src/Resources/xlf/SR.cs.xlf @@ -10401,6 +10401,16 @@ Trasování zásobníku, kde došlo k neplatné operaci: LargeChange: Hodnota {0} musí být větší nebo rovna 0. + + Large decrease + Large decrease + + + + Large increase + Large increase + + The maximum value for the position of the slider on the TrackBar. Maximální hodnota pozice posuvníku v objektu TrackBar. @@ -10421,6 +10431,11 @@ Trasování zásobníku, kde došlo k neplatné operaci: Orientace ovládacího prvku. + + Position + Position + + The number of positions the slider moves in response to keyboard input (arrow keys). Počet pozic, o něž se posune posuvník po vstupu z klávesnice (klávesy se šipkou). diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.de.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.de.xlf index 8e187daf61b..c798fe9f1ca 100644 --- a/src/System.Windows.Forms/src/Resources/xlf/SR.de.xlf +++ b/src/System.Windows.Forms/src/Resources/xlf/SR.de.xlf @@ -10401,6 +10401,16 @@ Stapelüberwachung, in der der unzulässige Vorgang auftrat: LargeChange: Der Wert {0} muss größer als oder gleich 0 sein. + + Large decrease + Large decrease + + + + Large increase + Large increase + + The maximum value for the position of the slider on the TrackBar. Der maximale Wert für die Schiebereglerposition auf der TrackBar. @@ -10421,6 +10431,11 @@ Stapelüberwachung, in der der unzulässige Vorgang auftrat: Die Ausrichtung des Steuerelements. + + Position + Position + + The number of positions the slider moves in response to keyboard input (arrow keys). Die Anzahl der Positionen, um die der Schieberegler bei Tastatureingaben (Pfeiltasten) verschoben wird. diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.es.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.es.xlf index d925828ceba..f0780b0df6c 100644 --- a/src/System.Windows.Forms/src/Resources/xlf/SR.es.xlf +++ b/src/System.Windows.Forms/src/Resources/xlf/SR.es.xlf @@ -10401,6 +10401,16 @@ El seguimiento de la pila donde tuvo lugar la operación no válida fue: LargeChange: el valor '{0}' debe ser mayor o igual que 0. + + Large decrease + Large decrease + + + + Large increase + Large increase + + The maximum value for the position of the slider on the TrackBar. Valor máximo para la posición del control deslizante en la barra de seguimiento. @@ -10421,6 +10431,11 @@ El seguimiento de la pila donde tuvo lugar la operación no válida fue: Orientación del control. + + Position + Position + + The number of positions the slider moves in response to keyboard input (arrow keys). Número de posiciones que se mueve el control deslizante como respuesta a una acción del teclado (teclas de dirección). diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.fr.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.fr.xlf index 2a4afca391f..606301c8591 100644 --- a/src/System.Windows.Forms/src/Resources/xlf/SR.fr.xlf +++ b/src/System.Windows.Forms/src/Resources/xlf/SR.fr.xlf @@ -10401,6 +10401,16 @@ Cette opération non conforme s'est produite sur la trace de la pile : LargeChange : la valeur '{0}' doit être supérieure ou égale à 0. + + Large decrease + Large decrease + + + + Large increase + Large increase + + The maximum value for the position of the slider on the TrackBar. La valeur maximale pour la position du curseur sur le TrackBar. @@ -10421,6 +10431,11 @@ Cette opération non conforme s'est produite sur la trace de la pile : L'orientation du contrôle. + + Position + Position + + The number of positions the slider moves in response to keyboard input (arrow keys). Déplacement du curseur en réponse à une entrée au clavier (touches de direction). diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.it.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.it.xlf index 293c24f3ff5..547caa2863d 100644 --- a/src/System.Windows.Forms/src/Resources/xlf/SR.it.xlf +++ b/src/System.Windows.Forms/src/Resources/xlf/SR.it.xlf @@ -10401,6 +10401,16 @@ Traccia dello stack da cui si è verificata l'operazione non valida: LargeChange: il valore '{0}' deve essere maggiore o uguale a 0. + + Large decrease + Large decrease + + + + Large increase + Large increase + + The maximum value for the position of the slider on the TrackBar. Il valore massimo per la posizione del dispositivo di scorrimento nel controllo TrackBar. @@ -10421,6 +10431,11 @@ Traccia dello stack da cui si è verificata l'operazione non valida: L'orientamento del controllo + + Position + Position + + The number of positions the slider moves in response to keyboard input (arrow keys). Il numero di posizioni di cui viene spostato il dispositivo di scorrimento in seguito alla pressione dei tasti di direzione. diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.ja.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.ja.xlf index 595ff587dc6..4b05ccee0f2 100644 --- a/src/System.Windows.Forms/src/Resources/xlf/SR.ja.xlf +++ b/src/System.Windows.Forms/src/Resources/xlf/SR.ja.xlf @@ -10401,6 +10401,16 @@ Stack trace where the illegal operation occurred was: LargeChange: 値 '{0}' は 0 以上でなければなりません。 + + Large decrease + Large decrease + + + + Large increase + Large increase + + The maximum value for the position of the slider on the TrackBar. トラック バー上のスライダー位置の最大値です。 @@ -10421,6 +10431,11 @@ Stack trace where the illegal operation occurred was: コントロールの向きです。 + + Position + Position + + The number of positions the slider moves in response to keyboard input (arrow keys). キーボードの入力 (方向キー) に対して、スライダーが移動するポジションの数です。 diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.ko.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.ko.xlf index f5a83b16d83..bca8400ffa3 100644 --- a/src/System.Windows.Forms/src/Resources/xlf/SR.ko.xlf +++ b/src/System.Windows.Forms/src/Resources/xlf/SR.ko.xlf @@ -10401,6 +10401,16 @@ Stack trace where the illegal operation occurred was: LargeChange: '{0}' 값은 0보다 크거나 같아야 합니다. + + Large decrease + Large decrease + + + + Large increase + Large increase + + The maximum value for the position of the slider on the TrackBar. TrackBar에서 슬라이더 위치의 최대값입니다. @@ -10421,6 +10431,11 @@ Stack trace where the illegal operation occurred was: 컨트롤의 방향입니다. + + Position + Position + + The number of positions the slider moves in response to keyboard input (arrow keys). 키보드 입력(화살표 키)에 대한 응답으로 슬라이더 위치가 이동되는 값입니다. diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.pl.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.pl.xlf index b1ed74ffc31..ea8069f6531 100644 --- a/src/System.Windows.Forms/src/Resources/xlf/SR.pl.xlf +++ b/src/System.Windows.Forms/src/Resources/xlf/SR.pl.xlf @@ -10401,6 +10401,16 @@ Stos śledzenia, w którym wystąpiła zabroniona operacja: LargeChange: wartość '{0}' musi być większa od lub równa 0. + + Large decrease + Large decrease + + + + Large increase + Large increase + + The maximum value for the position of the slider on the TrackBar. Maksymalna wartość dla pozycji suwaka w elemencie TrackBar. @@ -10421,6 +10431,11 @@ Stos śledzenia, w którym wystąpiła zabroniona operacja: Orientacja formantu. + + Position + Position + + The number of positions the slider moves in response to keyboard input (arrow keys). Liczba pozycji, o jaką zostanie przesunięty suwak w odpowiedzi na wprowadzanie z klawiatury (klawisze strzałek). diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.pt-BR.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.pt-BR.xlf index c7445731a89..92e8e4c33c7 100644 --- a/src/System.Windows.Forms/src/Resources/xlf/SR.pt-BR.xlf +++ b/src/System.Windows.Forms/src/Resources/xlf/SR.pt-BR.xlf @@ -10401,6 +10401,16 @@ Rastreamento de pilha em que a operação ilegal ocorreu: LargeChange: o valor '{0}' deve ser maior ou igual a 0. + + Large decrease + Large decrease + + + + Large increase + Large increase + + The maximum value for the position of the slider on the TrackBar. O valor máximo para a posição do controle deslizante em TrackBar. @@ -10421,6 +10431,11 @@ Rastreamento de pilha em que a operação ilegal ocorreu: A orientação do controle. + + Position + Position + + The number of positions the slider moves in response to keyboard input (arrow keys). O número de posições que o controle deslizante se move em resposta à entrada de teclado (teclas de direção). diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.ru.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.ru.xlf index da367c2e4fb..b66382be8d1 100644 --- a/src/System.Windows.Forms/src/Resources/xlf/SR.ru.xlf +++ b/src/System.Windows.Forms/src/Resources/xlf/SR.ru.xlf @@ -10402,6 +10402,16 @@ Stack trace where the illegal operation occurred was: LargeChange: значение '{0}' должно быть больше или равно 0. + + Large decrease + Large decrease + + + + Large increase + Large increase + + The maximum value for the position of the slider on the TrackBar. Максимальное значение для положения движка на TrackBar. @@ -10422,6 +10432,11 @@ Stack trace where the illegal operation occurred was: Ориентация элемента управления. + + Position + Position + + The number of positions the slider moves in response to keyboard input (arrow keys). Число позиций, на которое перемещается ползунок в ответ на нажатие клавиш со стрелками на клавиатуре. diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.tr.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.tr.xlf index 7b543fd2cb3..cd976c8cb8b 100644 --- a/src/System.Windows.Forms/src/Resources/xlf/SR.tr.xlf +++ b/src/System.Windows.Forms/src/Resources/xlf/SR.tr.xlf @@ -10401,6 +10401,16 @@ Geçersiz işlemin gerçekleştiği yığın izi: LargeChange: '{0}' değeri sıfırdan büyük veya eşit olmalıdır. + + Large decrease + Large decrease + + + + Large increase + Large increase + + The maximum value for the position of the slider on the TrackBar. TrackBar üzerinde kaydırıcının en büyük konum değeri. @@ -10421,6 +10431,11 @@ Geçersiz işlemin gerçekleştiği yığın izi: Denetimin yönlendirmesi. + + Position + Position + + The number of positions the slider moves in response to keyboard input (arrow keys). Klavyeden yapılan girişlere (ok tuşları) karşılık kaydırıcının hareket edeceği konum sayısı. diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hans.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hans.xlf index f253fe006f8..edc6be8d7a4 100644 --- a/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hans.xlf +++ b/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hans.xlf @@ -10401,6 +10401,16 @@ Stack trace where the illegal operation occurred was: LargeChange: 值“{0}”必须大于或等于 0。 + + Large decrease + Large decrease + + + + Large increase + Large increase + + The maximum value for the position of the slider on the TrackBar. TrackBar 上滑块位置的最大值。 @@ -10421,6 +10431,11 @@ Stack trace where the illegal operation occurred was: 控件的方向。 + + Position + Position + + The number of positions the slider moves in response to keyboard input (arrow keys). 滑块为响应键盘输入(箭头键)而移动的位置数。 diff --git a/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hant.xlf b/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hant.xlf index c2c7cee14ed..0846ec57a47 100644 --- a/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hant.xlf +++ b/src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hant.xlf @@ -10401,6 +10401,16 @@ Stack trace where the illegal operation occurred was: LargeChange: 值 '{0}' 必須大於或等於 0。 + + Large decrease + Large decrease + + + + Large increase + Large increase + + The maximum value for the position of the slider on the TrackBar. TrackBar 上滑桿位置的最大值。 @@ -10421,6 +10431,11 @@ Stack trace where the illegal operation occurred was: 控制項的方向。 + + Position + Position + + The number of positions the slider moves in response to keyboard input (arrow keys). 回應鍵盤輸入 (方向鍵),滑桿移動的位置數值。 diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarAccessibleObject.cs new file mode 100644 index 00000000000..59d8ff1f80b --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarAccessibleObject.cs @@ -0,0 +1,205 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Drawing; +using static Interop; + +namespace System.Windows.Forms +{ + public partial class TrackBar + { + internal class TrackBarAccessibleObject : ControlAccessibleObject + { + private readonly TrackBar _owningTrackBar; + private TrackBarFirstButtonAccessibleObject? _firstButtonAccessibleObject; + private TrackBarLastButtonAccessibleObject? _lastButtonAccessibleObject; + private TrackBarThumbAccessibleObject? _thumbAccessibleObject; + + public TrackBarAccessibleObject(TrackBar owningTrackBar) : base(owningTrackBar) + { + _owningTrackBar = owningTrackBar; + } + + public override Rectangle Bounds + { + get + { + if (!_owningTrackBar.IsHandleCreated) + { + return Rectangle.Empty; + } + + int left = 0; + int top = 0; + int width = 0; + int height = 0; + + // The "NativeMethods.CHILDID_SELF" constant returns to the id of the trackbar, + // which allows to use the native "accLocation" method to get the "Bounds" property + GetSystemIAccessibleInternal()?.accLocation(out left, out top, out width, out height, NativeMethods.CHILDID_SELF); + + return new(left, top, width, height); + } + } + + public override string DefaultAction => _owningTrackBar.AccessibleDefaultActionDescription; + + public override AccessibleRole Role + => Owner.AccessibleRole != AccessibleRole.Default + ? Owner.AccessibleRole + : AccessibleRole.Slider; + + public override AccessibleStates State + + // The "NativeMethods.CHILDID_SELF" constant returns to the id of the trackbar, + // which allows to use the native "get_accState" method to get the "State" property + => GetSystemIAccessibleInternal()?.get_accState(NativeMethods.CHILDID_SELF) is object accState + ? (AccessibleStates)accState + : AccessibleStates.None; + + internal TrackBarFirstButtonAccessibleObject FirstButtonAccessibleObject + => _firstButtonAccessibleObject ??= new(_owningTrackBar); + + internal bool IsMirrored + => _owningTrackBar.RightToLeft == RightToLeft.Yes && _owningTrackBar.RightToLeftLayout; + + internal TrackBarLastButtonAccessibleObject LastButtonAccessibleObject + => _lastButtonAccessibleObject ??= new(_owningTrackBar); + + internal bool RTLLayoutDisabled + => _owningTrackBar.RightToLeft == RightToLeft.Yes && !_owningTrackBar.RightToLeftLayout; + + internal override int[]? RuntimeId + { + get + { + if (!_owningTrackBar.IsHandleCreated) + { + return base.RuntimeId; + } + + var runtimeId = new int[2]; + runtimeId[0] = RuntimeIDFirstItem; + runtimeId[1] = PARAM.ToInt(_owningTrackBar.InternalHandle); + + return runtimeId; + } + } + + internal TrackBarThumbAccessibleObject ThumbAccessibleObject + => _thumbAccessibleObject ??= new TrackBarThumbAccessibleObject(_owningTrackBar); + + public override AccessibleObject? GetChild(int index) + { + if (!_owningTrackBar.IsHandleCreated) + { + return null; + } + + return index switch + { + 0 => FirstButtonAccessibleObject.IsDisplayed ? FirstButtonAccessibleObject : ThumbAccessibleObject, + 1 => FirstButtonAccessibleObject.IsDisplayed ? ThumbAccessibleObject : LastButtonAccessibleObject, + 2 => FirstButtonAccessibleObject.IsDisplayed && LastButtonAccessibleObject.IsDisplayed + ? LastButtonAccessibleObject + : null, + _ => null + }; + } + + public override int GetChildCount() + { + if (!_owningTrackBar.IsHandleCreated) + { + return -1; + } + + // Both buttons cannot be hidden at the same time. Even if the minimum and maximum values are equal, + // the placeholder for one of the buttons will still be displayed + return FirstButtonAccessibleObject.IsDisplayed && LastButtonAccessibleObject.IsDisplayed + ? 3 + : 2; + } + + public override AccessibleObject? HitTest(int x, int y) + { + if (!_owningTrackBar.IsHandleCreated) + { + return null; + } + + Point point = new(x, y); + if (ThumbAccessibleObject.Bounds.Contains(point)) + { + return ThumbAccessibleObject; + } + + if (FirstButtonAccessibleObject.IsDisplayed && FirstButtonAccessibleObject.Bounds.Contains(point)) + { + return FirstButtonAccessibleObject; + } + + if (LastButtonAccessibleObject.IsDisplayed && LastButtonAccessibleObject.Bounds.Contains(point)) + { + return LastButtonAccessibleObject; + } + + return null; + } + + internal override UiaCore.IRawElementProviderFragment? ElementProviderFromPoint(double x, double y) + { + AccessibleObject? element = HitTest((int)x, (int)y); + + return element ?? base.ElementProviderFromPoint(x, y); + } + + internal override UiaCore.IRawElementProviderFragment? FragmentNavigate(UiaCore.NavigateDirection direction) + { + if (!_owningTrackBar.IsHandleCreated) + { + return null; + } + + return direction switch + { + UiaCore.NavigateDirection.FirstChild => GetChild(0), + UiaCore.NavigateDirection.LastChild => LastButtonAccessibleObject.IsDisplayed + ? LastButtonAccessibleObject + : ThumbAccessibleObject, + _ => base.FragmentNavigate(direction) + }; + } + + internal override object? GetPropertyValue(UiaCore.UIA propertyID) + => propertyID switch + { + UiaCore.UIA.ControlTypePropertyId => _owningTrackBar.AccessibleRole == AccessibleRole.Default + ? UiaCore.UIA.SliderControlTypeId + : base.GetPropertyValue(propertyID), + UiaCore.UIA.RuntimeIdPropertyId => RuntimeId, + UiaCore.UIA.AutomationIdPropertyId => _owningTrackBar.Name, + UiaCore.UIA.IsEnabledPropertyId => _owningTrackBar.Enabled, + UiaCore.UIA.IsOffscreenPropertyId => (State & AccessibleStates.Offscreen) == AccessibleStates.Offscreen, + UiaCore.UIA.HasKeyboardFocusPropertyId => _owningTrackBar.Focused, + UiaCore.UIA.NamePropertyId => Name, + UiaCore.UIA.NativeWindowHandlePropertyId => _owningTrackBar.InternalHandle, + UiaCore.UIA.IsValuePatternAvailablePropertyId => IsPatternSupported(UiaCore.UIA.ValuePatternId), + UiaCore.UIA.IsKeyboardFocusablePropertyId + // This is necessary for compatibility with MSAA proxy: + // IsKeyboardFocusable = true regardless the control is enabled/disabled. + => true, + _ => base.GetPropertyValue(propertyID) + }; + + internal override bool IsPatternSupported(UiaCore.UIA patternId) + => patternId switch + { + UiaCore.UIA.ValuePatternId => true, + UiaCore.UIA.LegacyIAccessiblePatternId => true, + _ => base.IsPatternSupported(patternId) + }; + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarChildAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarChildAccessibleObject.cs new file mode 100644 index 00000000000..9d0dd106ac0 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarChildAccessibleObject.cs @@ -0,0 +1,111 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Drawing; +using static Interop; + +namespace System.Windows.Forms +{ + public partial class TrackBar + { + internal abstract class TrackBarChildAccessibleObject : AccessibleObject + { + public TrackBarChildAccessibleObject(TrackBar owningTrackBar) + { + OwningTrackBar = owningTrackBar ?? throw new ArgumentNullException(nameof(owningTrackBar)); + } + + public override Rectangle Bounds + { + get + { + if (!OwningTrackBar.IsHandleCreated || !IsDisplayed) + { + return Rectangle.Empty; + } + + int left = 0; + int top = 0; + int width = 0; + int height = 0; + + // The "GetChildId" method returns to the id of the trackbar element, + // which allows to use the native "accLocation" method to get the "Bounds" property + ParentInternal.GetSystemIAccessibleInternal()?.accLocation(out left, out top, out width, out height, GetChildId()); + + return new(left, top, width, height); + } + } + + public override string? Help => ParentInternal.GetSystemIAccessibleInternal()?.get_accHelp(GetChildId()); + + public override AccessibleRole Role + => ParentInternal.GetSystemIAccessibleInternal()?.get_accRole(GetChildId()) is object accRole + ? (AccessibleRole)accRole + : AccessibleRole.None; + + public override AccessibleStates State + => ParentInternal.GetSystemIAccessibleInternal()?.get_accState(GetChildId()) is object accState + ? (AccessibleStates)accState + : AccessibleStates.None; + + internal override UiaCore.IRawElementProviderFragmentRoot? FragmentRoot => ParentInternal; + + internal virtual bool IsDisplayed => OwningTrackBar.Visible; + + internal TrackBar OwningTrackBar { get; private set; } + + internal TrackBarAccessibleObject ParentInternal => (TrackBarAccessibleObject)OwningTrackBar.AccessibilityObject; + + internal override int[]? RuntimeId + { + get + { + if (!OwningTrackBar.IsHandleCreated) + { + return base.RuntimeId; + } + + var runtimeId = new int[3]; + runtimeId[0] = RuntimeIDFirstItem; + runtimeId[1] = PARAM.ToInt(OwningTrackBar.InternalHandle); + runtimeId[2] = GetChildId(); + + return runtimeId; + } + } + + internal override UiaCore.IRawElementProviderFragment? FragmentNavigate(UiaCore.NavigateDirection direction) + => direction switch + { + UiaCore.NavigateDirection.Parent => ParentInternal, + _ => base.FragmentNavigate(direction) + }; + + internal override object? GetPropertyValue(UiaCore.UIA propertyID) + => propertyID switch + { + UiaCore.UIA.RuntimeIdPropertyId => RuntimeId, + UiaCore.UIA.ControlTypePropertyId => UiaCore.UIA.ButtonControlTypeId, + UiaCore.UIA.IsEnabledPropertyId => OwningTrackBar.Enabled, + UiaCore.UIA.NamePropertyId => Name, + UiaCore.UIA.HelpTextPropertyId => Help ?? string.Empty, + UiaCore.UIA.IsPasswordPropertyId => false, + UiaCore.UIA.IsOffscreenPropertyId => (State & AccessibleStates.Offscreen) == AccessibleStates.Offscreen, + UiaCore.UIA.HasKeyboardFocusPropertyId => false, + UiaCore.UIA.IsKeyboardFocusablePropertyId => false, + UiaCore.UIA.AccessKeyPropertyId => string.Empty, + _ => base.GetPropertyValue(propertyID) + }; + + internal override bool IsPatternSupported(UiaCore.UIA patternId) + => patternId switch + { + UiaCore.UIA.LegacyIAccessiblePatternId => true, + UiaCore.UIA.InvokePatternId => true, + _ => base.IsPatternSupported(patternId) + }; + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarFirstButtonAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarFirstButtonAccessibleObject.cs new file mode 100644 index 00000000000..0443e42014f --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarFirstButtonAccessibleObject.cs @@ -0,0 +1,67 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using static Interop; + +namespace System.Windows.Forms +{ + public partial class TrackBar + { + internal class TrackBarFirstButtonAccessibleObject : TrackBarChildAccessibleObject + { + public TrackBarFirstButtonAccessibleObject(TrackBar owningTrackBar) : base(owningTrackBar) + { } + + public override string DefaultAction => SR.AccessibleActionPress; + + public override string? Name + => OwningTrackBar.Orientation == Orientation.Horizontal + && (OwningTrackBar.RightToLeft == RightToLeft.No || ParentInternal.IsMirrored) + ? SR.TrackBarLargeDecreaseButtonName + : SR.TrackBarLargeIncreaseButtonName; + + internal override bool IsDisplayed + { + get + { + if (!OwningTrackBar.IsHandleCreated || !base.IsDisplayed) + { + return false; + } + + return OwningTrackBar.Orientation == Orientation.Vertical || ParentInternal.RTLLayoutDisabled + ? OwningTrackBar.Maximum != OwningTrackBar.Value + : OwningTrackBar.Minimum != OwningTrackBar.Value; + } + } + + internal override UiaCore.IRawElementProviderFragment? FragmentNavigate(UiaCore.NavigateDirection direction) + { + if (!OwningTrackBar.IsHandleCreated || !IsDisplayed) + { + return null; + } + + return direction switch + { + UiaCore.NavigateDirection.PreviousSibling => null, + UiaCore.NavigateDirection.NextSibling => ParentInternal.ThumbAccessibleObject, + _ => base.FragmentNavigate(direction) + }; + } + + internal override int GetChildId() => 1; + + internal override void Invoke() + { + if (OwningTrackBar.IsHandleCreated) + { + // The "GetChildId" method returns to the id of the trackbar element, + // which allows to use the native "accDoDefaultAction" method when the "Invoke" method is called + ParentInternal.GetSystemIAccessibleInternal()?.accDoDefaultAction(GetChildId()); + } + } + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarLastButtonAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarLastButtonAccessibleObject.cs new file mode 100644 index 00000000000..90ea07944b6 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarLastButtonAccessibleObject.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using static Interop; + +namespace System.Windows.Forms +{ + public partial class TrackBar + { + internal class TrackBarLastButtonAccessibleObject : TrackBarChildAccessibleObject + { + public TrackBarLastButtonAccessibleObject(TrackBar owningTrackBar) : base(owningTrackBar) + { } + + public override string DefaultAction => SR.AccessibleActionPress; + + public override string? Name + => OwningTrackBar.Orientation == Orientation.Horizontal + && (OwningTrackBar.RightToLeft == RightToLeft.No || ParentInternal.IsMirrored) + ? SR.TrackBarLargeIncreaseButtonName + : SR.TrackBarLargeDecreaseButtonName; + + public override AccessibleStates State + => !OwningTrackBar.IsHandleCreated || IsDisplayed + ? AccessibleStates.None + : AccessibleStates.Invisible; + + internal override bool IsDisplayed + { + get + { + if (!OwningTrackBar.IsHandleCreated || !base.IsDisplayed) + { + return false; + } + + if (OwningTrackBar.Minimum == OwningTrackBar.Maximum) + { + return true; + } + + return OwningTrackBar.Orientation == Orientation.Vertical || ParentInternal.RTLLayoutDisabled + ? OwningTrackBar.Minimum != OwningTrackBar.Value + : OwningTrackBar.Maximum != OwningTrackBar.Value; + } + } + + internal override UiaCore.IRawElementProviderFragment? FragmentNavigate(UiaCore.NavigateDirection direction) + { + if (!OwningTrackBar.IsHandleCreated || !IsDisplayed) + { + return null; + } + + return direction switch + { + UiaCore.NavigateDirection.PreviousSibling => ParentInternal.ThumbAccessibleObject, + UiaCore.NavigateDirection.NextSibling => null, + _ => base.FragmentNavigate(direction) + }; + } + + internal override int GetChildId() => 3; + + internal override void Invoke() + { + if (OwningTrackBar.IsHandleCreated) + { + // The "GetChildId" method returns to the id of the trackbar element, + // which allows to use the native "accDoDefaultAction" method when the "Invoke" method is called + ParentInternal.GetSystemIAccessibleInternal()?.accDoDefaultAction(GetChildId()); + } + } + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarThumbAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarThumbAccessibleObject.cs new file mode 100644 index 00000000000..f36da3d787a --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.TrackBarThumbAccessibleObject.cs @@ -0,0 +1,50 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using static Interop; + +namespace System.Windows.Forms +{ + public partial class TrackBar + { + internal class TrackBarThumbAccessibleObject : TrackBarChildAccessibleObject + { + public TrackBarThumbAccessibleObject(TrackBar owningTrackBar) : base(owningTrackBar) + { } + + public override string? Name => SR.TrackBarPositionButtonName; + + internal override UiaCore.IRawElementProviderFragment? FragmentNavigate(UiaCore.NavigateDirection direction) + { + if (!OwningTrackBar.IsHandleCreated) + { + return null; + } + + return direction switch + { + UiaCore.NavigateDirection.PreviousSibling => ParentInternal.FirstButtonAccessibleObject.IsDisplayed ? ParentInternal.FirstButtonAccessibleObject : null, + UiaCore.NavigateDirection.NextSibling => ParentInternal.LastButtonAccessibleObject.IsDisplayed ? ParentInternal.LastButtonAccessibleObject : null, + _ => base.FragmentNavigate(direction) + }; + } + + internal override int GetChildId() => 2; + + internal override object? GetPropertyValue(UiaCore.UIA propertyID) + => propertyID switch + { + UiaCore.UIA.ControlTypePropertyId => UiaCore.UIA.ThumbControlTypeId, + _ => base.GetPropertyValue(propertyID) + }; + + internal override bool IsPatternSupported(UiaCore.UIA patternId) + => patternId switch + { + UiaCore.UIA.InvokePatternId => false, + _ => base.IsPatternSupported(patternId) + }; + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.cs index 9801465674f..5e640727947 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.cs @@ -26,7 +26,7 @@ namespace System.Windows.Forms [DefaultBindingProperty(nameof(Value))] [Designer("System.Windows.Forms.Design.TrackBarDesigner, " + AssemblyRef.SystemDesign)] [SRDescription(nameof(SR.DescriptionTrackBar))] - public class TrackBar : Control, ISupportInitialize + public partial class TrackBar : Control, ISupportInitialize { private static readonly object s_scrollEvent = new object(); private static readonly object s_valueChangedEvent = new object(); @@ -488,6 +488,8 @@ public int SmallChange } } + internal override bool SupportsUiaProviders => true; + [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [Bindable(false)] @@ -718,6 +720,8 @@ private void ConstrainValue() } } + protected override AccessibleObject CreateAccessibilityInstance() => new TrackBarAccessibleObject(this); + protected override void CreateHandle() { if (!RecreatingHandle) @@ -913,6 +917,10 @@ protected override void OnMouseWheel(MouseEventArgs e) /// protected virtual void OnValueChanged(EventArgs e) { + // UIA events: + AccessibilityObject.RaiseAutomationPropertyChangedEvent(UiaCore.UIA.ValueValuePropertyId, Name, Name); + AccessibilityObject.RaiseAutomationEvent(UiaCore.UIA.AutomationPropertyChangedEventId); + ((EventHandler)Events[s_valueChangedEvent])?.Invoke(this, e); } diff --git a/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/MainFormControlsTabOrder.cs b/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/MainFormControlsTabOrder.cs index 5472e813947..c69e7964818 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/MainFormControlsTabOrder.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/MainFormControlsTabOrder.cs @@ -33,6 +33,7 @@ public enum MainFormControlsTabOrder ErrorProviderButton, TaskDialogButton, MessageBoxButton, - ToolStripsButton + ToolStripsButton, + TrackBarsButton } } diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs index d887e610807..d6e9baf1f10 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs @@ -168,6 +168,10 @@ public MainForm() { MainFormControlsTabOrder.ToolStripsButton, new InitInfo("ToolStrips", (obj, e) => new ToolStripTests().Show(this)) + }, + { + MainFormControlsTabOrder.TrackBarsButton, + new InitInfo("TrackBars", (obj, e) => new TrackBars().Show(this)) } }; diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/TrackBars.Designer.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/TrackBars.Designer.cs new file mode 100644 index 00000000000..48b05513b92 --- /dev/null +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/TrackBars.Designer.cs @@ -0,0 +1,207 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace WinformsControlsTest +{ + partial class TrackBars + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.trackBar1 = new System.Windows.Forms.TrackBar(); + this.rbHorizontal = new System.Windows.Forms.RadioButton(); + this.rbVertical = new System.Windows.Forms.RadioButton(); + this.gbOrientation = new System.Windows.Forms.GroupBox(); + this.chbRightToLeft = new System.Windows.Forms.CheckBox(); + this.chbRightToLeftLayout = new System.Windows.Forms.CheckBox(); + this.lblTrackBarValue = new System.Windows.Forms.Label(); + this.numericMinimum = new System.Windows.Forms.NumericUpDown(); + this.numericMaximum = new System.Windows.Forms.NumericUpDown(); + this.lblMinimum = new System.Windows.Forms.Label(); + this.lblMaximum = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit(); + this.gbOrientation.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericMinimum)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericMaximum)).BeginInit(); + this.SuspendLayout(); + // + // trackBar1 + // + this.trackBar1.Location = new System.Drawing.Point(413, 67); + this.trackBar1.Name = "trackBar1"; + this.trackBar1.Size = new System.Drawing.Size(350, 350); + this.trackBar1.TabIndex = 0; + this.trackBar1.Value = 5; + this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll); + // + // rbHorizontal + // + this.rbHorizontal.AutoSize = true; + this.rbHorizontal.Checked = true; + this.rbHorizontal.Location = new System.Drawing.Point(20, 35); + this.rbHorizontal.Name = "rbHorizontal"; + this.rbHorizontal.Size = new System.Drawing.Size(100, 24); + this.rbHorizontal.TabIndex = 1; + this.rbHorizontal.TabStop = true; + this.rbHorizontal.Text = "Horizontal"; + this.rbHorizontal.UseVisualStyleBackColor = true; + this.rbHorizontal.CheckedChanged += new System.EventHandler(this.rbHorizontal_CheckedChanged); + // + // rbVertical + // + this.rbVertical.AutoSize = true; + this.rbVertical.Location = new System.Drawing.Point(20, 74); + this.rbVertical.Name = "rbVertical"; + this.rbVertical.Size = new System.Drawing.Size(79, 24); + this.rbVertical.TabIndex = 2; + this.rbVertical.Text = "Vertical"; + this.rbVertical.UseVisualStyleBackColor = true; + this.rbVertical.CheckedChanged += new System.EventHandler(this.rbVertical_CheckedChanged); + // + // gbOrientation + // + this.gbOrientation.Controls.Add(this.rbHorizontal); + this.gbOrientation.Controls.Add(this.rbVertical); + this.gbOrientation.Location = new System.Drawing.Point(56, 67); + this.gbOrientation.Name = "gbOrientation"; + this.gbOrientation.Size = new System.Drawing.Size(250, 125); + this.gbOrientation.TabIndex = 3; + this.gbOrientation.TabStop = false; + this.gbOrientation.Text = "Orientation"; + // + // chbRightToLeft + // + this.chbRightToLeft.AutoSize = true; + this.chbRightToLeft.Location = new System.Drawing.Point(56, 223); + this.chbRightToLeft.Name = "chbRightToLeft"; + this.chbRightToLeft.Size = new System.Drawing.Size(107, 24); + this.chbRightToLeft.TabIndex = 4; + this.chbRightToLeft.Text = "RightToLeft"; + this.chbRightToLeft.UseVisualStyleBackColor = true; + this.chbRightToLeft.CheckedChanged += new System.EventHandler(this.chbRightToLeft_CheckedChanged); + // + // chbRightToLeftLayout + // + this.chbRightToLeftLayout.AutoSize = true; + this.chbRightToLeftLayout.Location = new System.Drawing.Point(56, 279); + this.chbRightToLeftLayout.Name = "chbRightToLeftLayout"; + this.chbRightToLeftLayout.Size = new System.Drawing.Size(151, 24); + this.chbRightToLeftLayout.TabIndex = 5; + this.chbRightToLeftLayout.Text = "RightToLeftLayout"; + this.chbRightToLeftLayout.UseVisualStyleBackColor = true; + this.chbRightToLeftLayout.CheckedChanged += new System.EventHandler(this.chbRightToLeftLayout_CheckedChanged); + // + // lblTrackBarValue + // + this.lblTrackBarValue.AutoSize = true; + this.lblTrackBarValue.Location = new System.Drawing.Point(422, 26); + this.lblTrackBarValue.Name = "lblTrackBarValue"; + this.lblTrackBarValue.Size = new System.Drawing.Size(50, 20); + this.lblTrackBarValue.TabIndex = 6; + this.lblTrackBarValue.Text = "label1"; + // + // numericMinimum + // + this.numericMinimum.Location = new System.Drawing.Point(56, 359); + this.numericMinimum.Name = "numericMinimum"; + this.numericMinimum.Size = new System.Drawing.Size(150, 27); + this.numericMinimum.TabIndex = 7; + this.numericMinimum.ValueChanged += new System.EventHandler(this.numericMinimum_ValueChanged); + // + // numericMaximum + // + this.numericMaximum.Location = new System.Drawing.Point(56, 418); + this.numericMaximum.Name = "numericMaximum"; + this.numericMaximum.Size = new System.Drawing.Size(150, 27); + this.numericMaximum.TabIndex = 8; + this.numericMaximum.Value = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericMaximum.ValueChanged += new System.EventHandler(this.numericMaximum_ValueChanged); + // + // lblMinimum + // + this.lblMinimum.AutoSize = true; + this.lblMinimum.Location = new System.Drawing.Point(56, 336); + this.lblMinimum.Name = "lblMinimum"; + this.lblMinimum.Size = new System.Drawing.Size(72, 20); + this.lblMinimum.TabIndex = 9; + this.lblMinimum.Text = "Minimum"; + // + // lblMaximum + // + this.lblMaximum.AutoSize = true; + this.lblMaximum.Location = new System.Drawing.Point(56, 395); + this.lblMaximum.Name = "lblMaximum"; + this.lblMaximum.Size = new System.Drawing.Size(75, 20); + this.lblMaximum.TabIndex = 10; + this.lblMaximum.Text = "Maximum"; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(826, 468); + this.Controls.Add(this.lblMaximum); + this.Controls.Add(this.lblMinimum); + this.Controls.Add(this.numericMaximum); + this.Controls.Add(this.numericMinimum); + this.Controls.Add(this.lblTrackBarValue); + this.Controls.Add(this.chbRightToLeftLayout); + this.Controls.Add(this.chbRightToLeft); + this.Controls.Add(this.gbOrientation); + this.Controls.Add(this.trackBar1); + this.Name = "TrackBars"; + this.Text = "TrackBars"; + ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit(); + this.gbOrientation.ResumeLayout(false); + this.gbOrientation.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericMinimum)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericMaximum)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TrackBar trackBar1; + private System.Windows.Forms.RadioButton rbHorizontal; + private System.Windows.Forms.RadioButton rbVertical; + private System.Windows.Forms.GroupBox gbOrientation; + private System.Windows.Forms.CheckBox chbRightToLeft; + private System.Windows.Forms.CheckBox chbRightToLeftLayout; + private System.Windows.Forms.Label lblTrackBarValue; + private System.Windows.Forms.NumericUpDown numericMinimum; + private System.Windows.Forms.NumericUpDown numericMaximum; + private System.Windows.Forms.Label lblMinimum; + private System.Windows.Forms.Label lblMaximum; + } +} + diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/TrackBars.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/TrackBars.cs new file mode 100644 index 00000000000..318c9ac9903 --- /dev/null +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/TrackBars.cs @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Windows.Forms; + +namespace WinformsControlsTest +{ + public partial class TrackBars : Form + { + public TrackBars() + { + InitializeComponent(); + UpdateValueLabel(); + } + + private void rbHorizontal_CheckedChanged(object sender, EventArgs e) + { + trackBar1.Orientation = Orientation.Horizontal; + } + + private void rbVertical_CheckedChanged(object sender, EventArgs e) + { + trackBar1.Orientation = Orientation.Vertical; + } + + private void chbRightToLeft_CheckedChanged(object sender, EventArgs e) + { + trackBar1.RightToLeft = chbRightToLeft.Checked ? RightToLeft.Yes : RightToLeft.No; + } + + private void numericMinimum_ValueChanged(object sender, EventArgs e) + { + trackBar1.Minimum = Decimal.ToInt32(numericMinimum.Value); + numericMaximum.Minimum = numericMinimum.Value; + UpdateValueLabel(); + } + + private void numericMaximum_ValueChanged(object sender, EventArgs e) + { + trackBar1.Maximum = Decimal.ToInt32(numericMaximum.Value); + numericMinimum.Maximum = numericMaximum.Value; + UpdateValueLabel(); + } + + private void trackBar1_Scroll(object sender, EventArgs e) + { + UpdateValueLabel(); + } + + private void chbRightToLeftLayout_CheckedChanged(object sender, EventArgs e) + { + trackBar1.RightToLeftLayout = chbRightToLeftLayout.Checked; + } + + private void UpdateValueLabel() + { + lblTrackBarValue.Text = $"Value {trackBar1.Value}"; + } + } +} diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/TrackBars.resx b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/TrackBars.resx new file mode 100644 index 00000000000..667ea1506c8 --- /dev/null +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/TrackBars.resx @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + diff --git a/src/System.Windows.Forms/tests/TestUtilities/TrackBarTestHelper.cs b/src/System.Windows.Forms/tests/TestUtilities/TrackBarTestHelper.cs new file mode 100644 index 00000000000..4d0fa58efa9 --- /dev/null +++ b/src/System.Windows.Forms/tests/TestUtilities/TrackBarTestHelper.cs @@ -0,0 +1,175 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; + +namespace System.Windows.Forms.TestUtilities +{ + /// + /// This class contains methods that return a list of parameters for unit tests. + /// These methods have been moved to a static class since we have several test classes that use the same test parameters. + /// Thus, we reduce the amount of copy-paste and we can be sure that all tests use the same data sets. + /// + public static class TrackBarTestHelper + { + private const int Maximum = 10; + private const int Minumim = 0; + + public static IEnumerable TrackBarAccessibleObject_ButtonsAreDisplayed_TestData() + { + foreach (Orientation orientation in Enum.GetValues(typeof(Orientation))) + { + foreach (RightToLeft rightToLeft in new RightToLeft[] { RightToLeft.Yes, RightToLeft.No }) + { + foreach (bool rightToLeftLayout in new[] { true, false }) + { + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, Minumim, Maximum, /*value*/ 5 }; + } + } + } + } + + public static IEnumerable TrackBarAccessibleObject_FirstButtonIsDisplayed_TestData() + { + foreach (Orientation orientation in Enum.GetValues(typeof(Orientation))) + { + foreach (RightToLeft rightToLeft in new RightToLeft[] { RightToLeft.Yes, RightToLeft.No }) + { + foreach (bool rightToLeftLayout in new[] { true, false }) + { + bool isMirrored = rightToLeft == RightToLeft.Yes && rightToLeftLayout; + + // Depending on orientation and RTL settings, the first button can be shown + // or hidden when the trackbar value is at minimum or maximum. + int value = orientation == Orientation.Horizontal && (rightToLeft == RightToLeft.No || isMirrored) + ? Maximum + : Minumim; + + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, Minumim, Maximum, /*value*/ 5 }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, Minumim, Maximum, value }; + } + } + } + } + + public static IEnumerable TrackBarAccessibleObject_FirstButtonIsHidden_TestData() + { + foreach (Orientation orientation in Enum.GetValues(typeof(Orientation))) + { + foreach (RightToLeft rightToLeft in new RightToLeft[] { RightToLeft.Yes, RightToLeft.No }) + { + foreach (bool rightToLeftLayout in new[] { true, false }) + { + bool isMirrored = rightToLeft == RightToLeft.Yes && rightToLeftLayout; + + // Depending on orientation and RTL settings, the first button can be shown + // or hidden when the trackbar value is at minimum or maximum. + int value = orientation == Orientation.Horizontal && (rightToLeft == RightToLeft.No || isMirrored) + ? Minumim + : Maximum; + + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, Minumim, Maximum, value }; + } + } + } + } + + public static IEnumerable TrackBarAccessibleObject_LastButtonIsDisplayed_TestData() + { + foreach (Orientation orientation in Enum.GetValues(typeof(Orientation))) + { + foreach (RightToLeft rightToLeft in new RightToLeft[] { RightToLeft.Yes, RightToLeft.No }) + { + foreach (bool rightToLeftLayout in new[] { true, false }) + { + bool isMirrored = rightToLeft == RightToLeft.Yes && rightToLeftLayout; + + // Depending on orientation and RTL settings, the first button can be shown + // or hidden when the trackbar value is at minimum or maximum. + int value = orientation == Orientation.Horizontal && (rightToLeft == RightToLeft.No || isMirrored) + ? Minumim + : Maximum; + + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, Minumim, Maximum, /*value*/ 5 }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, Minumim, Maximum, value }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, Minumim, /*maximum*/ 0, /*value*/ 0 }; + } + } + } + } + + public static IEnumerable TrackBarAccessibleObject_LastButtonIsHidden_TestData() + { + foreach (Orientation orientation in Enum.GetValues(typeof(Orientation))) + { + foreach (RightToLeft rightToLeft in new RightToLeft[] { RightToLeft.Yes, RightToLeft.No }) + { + foreach (bool rightToLeftLayout in new[] { true, false }) + { + bool isMirrored = rightToLeft == RightToLeft.Yes && rightToLeftLayout; + + // Depending on orientation and RTL settings, the first button can be shown + // or hidden when the trackbar value is at minimum or maximum. + int value = orientation == Orientation.Horizontal && (rightToLeft == RightToLeft.No || isMirrored) + ? Maximum + : Minumim; + + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, Minumim, Maximum, value }; + } + } + } + } + + public static IEnumerable TrackBarAccessibleObject_MinimumEqualsMaximum_TestData() + { + foreach (Orientation orientation in Enum.GetValues(typeof(Orientation))) + { + foreach (RightToLeft rightToLeft in new RightToLeft[] { RightToLeft.Yes, RightToLeft.No }) + { + foreach (bool rightToLeftLayout in new[] { true, false }) + { + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, 0, 0, 0 }; + } + } + } + } + + public static IEnumerable TrackBarAccessibleObject_TestData() + { + foreach (Orientation orientation in Enum.GetValues(typeof(Orientation))) + { + foreach (RightToLeft rightToLeft in new RightToLeft[] { RightToLeft.Yes, RightToLeft.No }) + { + foreach (bool rightToLeftLayout in new[] { true, false }) + { + foreach (bool createControl in new[] { true, false }) + { + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, createControl, Minumim, Maximum, /*value*/ 5 }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, createControl, Minumim, Maximum, /*value*/ 0 }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, createControl, Minumim, Maximum, /*value*/ 10 }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, createControl, Minumim, /*maximum*/ 0, /*value*/ 0 }; + } + } + } + } + } + + public static IEnumerable TrackBarAccessibleObject_WithoutCreateControl_TestData() + { + foreach (Orientation orientation in Enum.GetValues(typeof(Orientation))) + { + foreach (RightToLeft rightToLeft in new RightToLeft[] { RightToLeft.Yes, RightToLeft.No }) + { + foreach (bool rightToLeftLayout in new[] { true, false }) + { + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, Minumim, Maximum, /*value*/ 5 }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, Minumim, Maximum, /*value*/ 0 }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, Minumim, Maximum, /*value*/ 10 }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, Minumim, /*maximum*/ 0, /*value*/ 0 }; + } + } + } + } + } +} diff --git a/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBar.TrackBarAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBar.TrackBarAccessibleObjectTests.cs new file mode 100644 index 00000000000..9d5615f8975 --- /dev/null +++ b/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBar.TrackBarAccessibleObjectTests.cs @@ -0,0 +1,416 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Drawing; +using System.Runtime.InteropServices; +using System.Windows.Forms.TestUtilities; +using Xunit; +using static Interop; + +namespace System.Windows.Forms.Tests.AccessibleObjects +{ + public class TrackBarAccessibleObjectTests : IClassFixture + { + [WinFormsFact] + public void TrackBarAccessibilityObject_Properties_ReturnsExpected_IfHandleIsCreated() + { + using var ownerControl = new TrackBar + { + Value = 5, + }; + + ownerControl.CreateControl(); + Control.ControlAccessibleObject accessibilityObject = Assert.IsAssignableFrom(ownerControl.AccessibilityObject); + + Assert.Equal(ownerControl.Size, accessibilityObject.Bounds.Size); + Assert.Null(accessibilityObject.DefaultAction); + Assert.Null(accessibilityObject.Description); + Assert.True(ownerControl.IsHandleCreated); + Assert.Equal(ownerControl.Handle, accessibilityObject.Handle); + Assert.Null(accessibilityObject.Help); + Assert.Null(accessibilityObject.KeyboardShortcut); + Assert.Null(accessibilityObject.Name); + Assert.Equal(AccessibleRole.Slider, accessibilityObject.Role); + Assert.Same(ownerControl, accessibilityObject.Owner); + Assert.NotNull(accessibilityObject.Parent); + Assert.Equal(AccessibleStates.Focusable, accessibilityObject.State); + Assert.Equal("50", accessibilityObject.Value); + } + + [WinFormsFact] + public void TrackBarAccessibilityObject_Properties_ReturnsExpected_IfHandleIsNotCreated() + { + using var ownerControl = new TrackBar + { + Value = 5, + }; + + Control.ControlAccessibleObject accessibilityObject = Assert.IsAssignableFrom(ownerControl.AccessibilityObject); + + Assert.Equal(Rectangle.Empty.Size, accessibilityObject.Bounds.Size); + Assert.Null(accessibilityObject.DefaultAction); + Assert.Null(accessibilityObject.Description); + Assert.Null(accessibilityObject.Help); + Assert.Null(accessibilityObject.KeyboardShortcut); + Assert.Null(accessibilityObject.Name); + Assert.Equal(AccessibleRole.Slider, accessibilityObject.Role); + Assert.Same(ownerControl, accessibilityObject.Owner); + Assert.Null(accessibilityObject.Parent); + Assert.Equal(AccessibleStates.None, accessibilityObject.State); + Assert.Equal(string.Empty, accessibilityObject.Value); + Assert.False(ownerControl.IsHandleCreated); + Assert.Equal(ownerControl.Handle, accessibilityObject.Handle); + } + + [WinFormsTheory] + [InlineData("100", 10, "100", true)] + [InlineData("50", 5, "50", true)] + [InlineData("54", 5, "50", true)] + [InlineData("56", 5, "50", true)] + [InlineData("0", 0, "0", true)] + [InlineData("100", 0, "", false)] + [InlineData("50", 0, "", false)] + [InlineData("54", 0, "", false)] + [InlineData("56", 0, "", false)] + [InlineData("0", 0, "", false)] + public void TrackBarAccessibilityObject_Value_Set_GetReturnsExpected(string value, int expected, string expectedValueString, bool createControl) + { + using var ownerControl = new TrackBar(); + if (createControl) + { + ownerControl.CreateControl(); + } + + Assert.Equal(createControl, ownerControl.IsHandleCreated); + + Control.ControlAccessibleObject accessibilityObject = Assert.IsAssignableFrom(ownerControl.AccessibilityObject); + + Assert.Equal(createControl, ownerControl.IsHandleCreated); + + accessibilityObject.Value = value; + + Assert.Equal(expectedValueString, accessibilityObject.Value); + Assert.Equal(expected, ownerControl.Value); + + // Set same. + accessibilityObject.Value = value; + + Assert.Equal(expectedValueString, accessibilityObject.Value); + Assert.Equal(expected, ownerControl.Value); + } + + [WinFormsTheory] + [InlineData(null)] + [InlineData("")] + [InlineData("NotAnInt")] + public void TrackBarAccessibilityObject_Value_SetInvalid_ThrowsCOMException_IfHandleIsCreated(string value) + { + using var ownerControl = new TrackBar + { + Value = 5 + }; + + ownerControl.CreateControl(); + Control.ControlAccessibleObject accessibilityObject = Assert.IsAssignableFrom(ownerControl.AccessibilityObject); + + Assert.Throws(() => accessibilityObject.Value = value); + Assert.Equal("50", accessibilityObject.Value); + Assert.Equal(5, ownerControl.Value); + } + + [WinFormsTheory] + [InlineData(null)] + [InlineData("")] + [InlineData("NotAnInt")] + public void TrackBarAccessibilityObject_Value_SetInvalid_ThrowsCOMException_IfHandleIsNotCreated(string value) + { + using var ownerControl = new TrackBar + { + Value = 5 + }; + + Control.ControlAccessibleObject accessibilityObject = Assert.IsAssignableFrom(ownerControl.AccessibilityObject); + accessibilityObject.Value = value; + + Assert.Equal(string.Empty, accessibilityObject.Value); + Assert.Equal(5, ownerControl.Value); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_ButtonsAreDisplayed_TestData))] + public void TrackBarAccessibilityObject_GetChildCount_ReturnsThree_IfAllButtonsAreDisplayed(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarAccessibleObject accessibilityObject = Assert.IsAssignableFrom(trackBar.AccessibilityObject); + + // All control elements (thumb and left/right buttons) are displayed + Assert.Equal(3, accessibilityObject.GetChildCount()); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_FirstButtonIsHidden_TestData))] + public void TrackBarAccessibilityObject_GetChildCount_ReturnsTwo_IfFirstButtonIsHidden(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarAccessibleObject accessibilityObject = Assert.IsAssignableFrom(trackBar.AccessibilityObject); + + // Only thumb and left/right button are displayed + Assert.Equal(2, accessibilityObject.GetChildCount()); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_LastButtonIsHidden_TestData))] + public void TrackBarAccessibilityObject_GetChildCount_ReturnsTwo_IfLastButtonIsHidden(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarAccessibleObject accessibilityObject = Assert.IsAssignableFrom(trackBar.AccessibilityObject); + + // Only thumb and left/right button are displayed + Assert.Equal(2, accessibilityObject.GetChildCount()); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_MinimumEqualsMaximum_TestData))] + public void TrackBarAccessibilityObject_GetChildCount_ReturnsTwo_MinimumEqualsMaximum(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarAccessibleObject accessibilityObject = Assert.IsAssignableFrom(trackBar.AccessibilityObject); + + // Only thumb and left/right button are displayed. + // The left/right button is displayed even if the minimum is equal to the maximum + Assert.Equal(2, accessibilityObject.GetChildCount()); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_WithoutCreateControl_TestData))] + public void TrackBarAccessibilityObject_GetChildCount_ReturnsMinusOne_IfHandleIsNotCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: false, value, minimum, maximum); + TrackBar.TrackBarAccessibleObject accessibilityObject = Assert.IsAssignableFrom(trackBar.AccessibilityObject); + + Assert.Equal(-1, accessibilityObject.GetChildCount()); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_ButtonsAreDisplayed_TestData))] + public void TrackBarAccessibilityObject_GetChild_ReturnsExpected_ButtonsAreDisplayed(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarAccessibleObject accessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + + Assert.Null(accessibleObject.GetChild(-1)); + Assert.Equal(accessibleObject.FirstButtonAccessibleObject, accessibleObject.GetChild(0)); + Assert.Equal(accessibleObject.ThumbAccessibleObject, accessibleObject.GetChild(1)); + Assert.Equal(accessibleObject.LastButtonAccessibleObject, accessibleObject.GetChild(2)); + Assert.Null(accessibleObject.GetChild(3)); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_FirstButtonIsHidden_TestData))] + public void TrackBarAccessibilityObject_GetChild_ReturnsExpected_FirstButtonIsHidden(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarAccessibleObject accessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + + Assert.Null(accessibleObject.GetChild(-1)); + Assert.Equal(accessibleObject.ThumbAccessibleObject, accessibleObject.GetChild(0)); + Assert.Equal(accessibleObject.LastButtonAccessibleObject, accessibleObject.GetChild(1)); + Assert.Null(accessibleObject.GetChild(2)); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_LastButtonIsHidden_TestData))] + public void TrackBarAccessibilityObject_GetChild_ReturnsExpected_LastButtonIsHidden(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarAccessibleObject accessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + + Assert.Null(accessibleObject.GetChild(-1)); + Assert.Equal(accessibleObject.FirstButtonAccessibleObject, accessibleObject.GetChild(0)); + Assert.Equal(accessibleObject.ThumbAccessibleObject, accessibleObject.GetChild(1)); + Assert.Null(accessibleObject.GetChild(2)); + Assert.Null(accessibleObject.GetChild(3)); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_WithoutCreateControl_TestData))] + public void TrackBarAccessibilityObject_GetChild_ReturnsNull_IfHandleNotCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: false, value, minimum, maximum); + TrackBar.TrackBarAccessibleObject accessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + + Assert.Null(accessibleObject.GetChild(-1)); + Assert.Null(accessibleObject.GetChild(0)); + Assert.Null(accessibleObject.GetChild(1)); + Assert.Null(accessibleObject.GetChild(2)); + Assert.Null(accessibleObject.GetChild(3)); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsFact] + public void TrackBarAccessibilityObject_ControlType_IsSlider_IfAccessibleRoleIsDefault() + { + using TrackBar trackBar = new(); + + // AccessibleRole is not set = Default + object actual = trackBar.AccessibilityObject.GetPropertyValue(UiaCore.UIA.ControlTypePropertyId); + + Assert.Equal(UiaCore.UIA.SliderControlTypeId, actual); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsFact] + public void TrackBarAccessibilityObject_Role_IsStatusBar_ByDefault() + { + using TrackBar trackBar = new(); + + // AccessibleRole is not set = Default + Assert.Equal(AccessibleRole.Slider, trackBar.AccessibilityObject.Role); + Assert.False(trackBar.IsHandleCreated); + } + + public static IEnumerable TrackBarAccessibleObject_GetPropertyValue_ControlType_IsExpected_ForCustomRole_TestData() + { + Array roles = Enum.GetValues(typeof(AccessibleRole)); + + foreach (AccessibleRole role in roles) + { + if (role == AccessibleRole.Default) + { + continue; // The test checks custom roles + } + + yield return new object[] { role }; + } + } + + [WinFormsTheory] + [MemberData(nameof(TrackBarAccessibleObject_GetPropertyValue_ControlType_IsExpected_ForCustomRole_TestData))] + public void TrackBarAccessibleObject_GetPropertyValue_ControlType_IsExpected_ForCustomRole(AccessibleRole role) + { + using TrackBar trackBar = new(); + trackBar.AccessibleRole = role; + + object actual = trackBar.AccessibilityObject.GetPropertyValue(UiaCore.UIA.ControlTypePropertyId); + UiaCore.UIA expected = AccessibleRoleControlTypeMap.GetControlType(role); + + Assert.Equal(expected, actual); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [InlineData("Test Description")] + [InlineData(null)] + public void TrackBarAccessibilityObject_DefaultAction_ReturnExpected(string defaultAction) + { + using TrackBar trackBar = new(); + trackBar.AccessibleDefaultActionDescription = defaultAction; + + Assert.Equal(defaultAction, trackBar.AccessibilityObject.DefaultAction); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_ButtonsAreDisplayed_TestData))] + public void TrackBarAccessibilityObject_FragmentNavigate_Child_ReturnsExpected_ButtonsAreDisplayed(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarAccessibleObject accessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + + Assert.Equal(accessibleObject.FirstButtonAccessibleObject, accessibleObject.FragmentNavigate(UiaCore.NavigateDirection.FirstChild)); + Assert.Equal(accessibleObject.LastButtonAccessibleObject, accessibleObject.FragmentNavigate(UiaCore.NavigateDirection.LastChild)); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_FirstButtonIsHidden_TestData))] + public void TrackBarAccessibilityObject_FragmentNavigate_Child_ReturnsExpected_IfFirstButtonIsHidden(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarAccessibleObject accessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + + Assert.Equal(accessibleObject.ThumbAccessibleObject, accessibleObject.FragmentNavigate(UiaCore.NavigateDirection.FirstChild)); + Assert.Equal(accessibleObject.LastButtonAccessibleObject, accessibleObject.FragmentNavigate(UiaCore.NavigateDirection.LastChild)); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_LastButtonIsHidden_TestData))] + public void TrackBarAccessibilityObject_FragmentNavigate_Child_ReturnsExpected_IfLastButtonIsHidden(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarAccessibleObject accessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + + Assert.Equal(accessibleObject.FirstButtonAccessibleObject, accessibleObject.FragmentNavigate(UiaCore.NavigateDirection.FirstChild)); + Assert.Equal(accessibleObject.ThumbAccessibleObject, accessibleObject.FragmentNavigate(UiaCore.NavigateDirection.LastChild)); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_WithoutCreateControl_TestData))] + public void TrackBarAccessibilityObject_FragmentNavigate_Child_ReturnsNull_IfHandleNotCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: false, value, minimum, maximum); + TrackBar.TrackBarAccessibleObject accessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + + Assert.Null(accessibleObject.FragmentNavigate(UiaCore.NavigateDirection.FirstChild)); + Assert.Null(accessibleObject.FragmentNavigate(UiaCore.NavigateDirection.LastChild)); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsFact] + public void TrackBarAccessibilityObject_IsPatternSupported_ReturnsExpected() + { + using TrackBar trackBar = new(); + + Assert.True(trackBar.AccessibilityObject.IsPatternSupported(UiaCore.UIA.ValuePatternId)); + Assert.True(trackBar.AccessibilityObject.IsPatternSupported(UiaCore.UIA.LegacyIAccessiblePatternId)); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [InlineData(true)] + [InlineData(false)] + public void TrackBarAccessibilityObject_GetPropertyValue_IsEnabledProperty_ReturnsExpected(bool enabled) + { + using TrackBar trackBar = new() + { + Enabled = enabled + }; + + Assert.Equal(enabled, trackBar.AccessibilityObject.GetPropertyValue(UiaCore.UIA.IsEnabledPropertyId)); + Assert.False(trackBar.IsHandleCreated); + } + + private TrackBar GetTrackBar(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int value, int minimum, int maximum) + { + TrackBar trackBar = new() + { + Value = value, + Maximum = maximum, + Minimum = minimum, + LargeChange = 3, + Orientation = orientation, + RightToLeft = rightToLeft, + RightToLeftLayout = rightToLeftLayout + }; + + if (createControl) + { + trackBar.CreateControl(); + } + + return trackBar; + } + } +} diff --git a/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBar.TrackBarFirstButtonAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBar.TrackBarFirstButtonAccessibleObjectTests.cs new file mode 100644 index 00000000000..a550502f9a7 --- /dev/null +++ b/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBar.TrackBarFirstButtonAccessibleObjectTests.cs @@ -0,0 +1,387 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms.TestUtilities; +using Xunit; +using static Interop; + +namespace System.Windows.Forms.Tests.AccessibleObjects +{ + public class TrackBar_TrackBarFirstButtonAccessibleObjectTests : IClassFixture + { + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_FirstButtonIsDisplayed_TestData))] + public void TrackBarFirstButtonAccessibleObject_Bounds_ReturnsNotEmptyRectangle_IfButtonIsDisplayed(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.NotEqual(Rectangle.Empty, accessibleObject.Bounds); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_FirstButtonIsHidden_TestData))] + public void TrackBarFirstButtonAccessibleObject_Bounds_ReturnsEmptyRectangle_IfButtonIsHidden(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.Equal(Rectangle.Empty, accessibleObject.Bounds); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_WithoutCreateControl_TestData))] + public void TrackBarFirstButtonAccessibleObject_Bounds_ReturnsEmptyRectangle_IfHandleIsNotCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: false, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.Equal(Rectangle.Empty, accessibleObject.Bounds); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarFirstButtonAccessibleObject_DefaultAction_ReturnActionPress(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.Equal(SR.AccessibleActionPress, accessibleObject.DefaultAction); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarFirstButtonAccessibleObject_Help_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.Null(accessibleObject.Help); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + public static IEnumerable TrackBarAccessibleObject_DecreaseButtonName_TestData() + { + foreach (RightToLeft rightToLeft in new RightToLeft[] { RightToLeft.Yes, RightToLeft.No }) + { + foreach (bool rightToLeftLayout in new[] { true, false }) + { + if (rightToLeft == RightToLeft.Yes && rightToLeftLayout == false) + { + continue; + } + + foreach (bool createControl in new[] { true, false }) + { + yield return new object[] { Orientation.Horizontal, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 10, /*value*/ 5 }; + yield return new object[] { Orientation.Horizontal, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 10, /*value*/ 0 }; + yield return new object[] { Orientation.Horizontal, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 10, /*value*/ 10 }; + yield return new object[] { Orientation.Horizontal, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 0, /*value*/ 0 }; + } + } + } + } + + [WinFormsTheory] + [MemberData(nameof(TrackBarAccessibleObject_DecreaseButtonName_TestData))] + public void TrackBarFirstButtonAccessibleObject_Name_ReturnDescreaseName(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.Equal(SR.TrackBarLargeDecreaseButtonName, accessibleObject.Name); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + public static IEnumerable TrackBarAccessibleObject_IncreaseButtonName_TestData() + { + foreach (Orientation orientation in Enum.GetValues(typeof(Orientation))) + { + foreach (RightToLeft rightToLeft in new RightToLeft[] { RightToLeft.Yes, RightToLeft.No }) + { + foreach (bool rightToLeftLayout in new[] { true, false }) + { + if (orientation == Orientation.Vertical || (rightToLeft == RightToLeft.Yes && rightToLeftLayout == false)) + { + foreach (bool createControl in new[] { true, false }) + { + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 10, /*value*/ 5 }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 10, /*value*/ 0 }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 10, /*value*/ 10 }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 0, /*value*/ 0 }; + } + } + } + } + } + } + + [WinFormsTheory] + [MemberData(nameof(TrackBarAccessibleObject_IncreaseButtonName_TestData))] + public void TrackBarFirstButtonAccessibleObject_Name_ReturnIncreaseName(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.Equal(SR.TrackBarLargeIncreaseButtonName, accessibleObject.Name); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarFirstButtonAccessibleObject_Role_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + AccessibleRole accessibleRole = createControl ? AccessibleRole.PushButton : AccessibleRole.None; + + Assert.Equal(accessibleRole, accessibleObject.Role); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarFirstButtonAccessibleObject_State_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + AccessibleStates expectedState = accessibleObject.IsDisplayed || !trackBar.IsHandleCreated + ? AccessibleStates.None + : AccessibleStates.Invisible; + + Assert.Equal(expectedState, accessibleObject.State); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_FirstButtonIsHidden_TestData))] + public void TrackBarFirstButtonAccessibleObject_FragmentNavigate_ReturnsNull_IfFirstButtonIsHidden(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.Parent)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.PreviousSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.LastChild)); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_FirstButtonIsDisplayed_TestData))] + public void TrackBarFirstButtonAccessibleObject_FragmentNavigate_ReturnsExpected_IfFirstButtonIsDisplayed(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + var trackBarAccessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = trackBarAccessibleObject.FirstButtonAccessibleObject; + + Assert.Equal(trackBarAccessibleObject, accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.Parent)); + Assert.Equal(trackBarAccessibleObject.ThumbAccessibleObject, accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.PreviousSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.LastChild)); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_WithoutCreateControl_TestData))] + public void TrackBarFirstButtonAccessibleObject_FragmentNavigate_ReturnsNull_IfHandleIsNotCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: false, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.Parent)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.PreviousSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.LastChild)); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarFirstButtonAccessibleObject_GetChildCount_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.Equal(-1, accessibleObject.GetChildCount()); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarFirstButtonAccessibleObject_GetChild_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.Null(accessibleObject.GetChild(-1)); + Assert.Null(accessibleObject.GetChild(0)); + Assert.Null(accessibleObject.GetChild(1)); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [InlineData(Orientation.Vertical, RightToLeft.Yes, true)] + [InlineData(Orientation.Vertical, RightToLeft.Yes, false)] + [InlineData(Orientation.Vertical, RightToLeft.No, true)] + [InlineData(Orientation.Vertical, RightToLeft.No, false)] + [InlineData(Orientation.Horizontal, RightToLeft.Yes, false)] + public void TrackBarFirstButtonAccessibleObject_Invoke_Increase_WorkCorrectly(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value: 5, 0, 10); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.Equal(5, trackBar.Value); + + accessibleObject.Invoke(); + + Assert.Equal(8, trackBar.Value); + + accessibleObject.Invoke(); + + Assert.Equal(10, trackBar.Value); + + accessibleObject.Invoke(); + + Assert.Equal(10, trackBar.Value); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [InlineData(Orientation.Horizontal, RightToLeft.No, true)] + [InlineData(Orientation.Horizontal, RightToLeft.No, false)] + [InlineData(Orientation.Horizontal, RightToLeft.Yes, true)] + public void TrackBarFirstButtonAccessibleObject_Invoke_Decrease_WorkCorrectly(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value: 5, 0, 10); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.Equal(5, trackBar.Value); + + accessibleObject.Invoke(); + + Assert.Equal(2, trackBar.Value); + + accessibleObject.Invoke(); + + Assert.Equal(0, trackBar.Value); + + accessibleObject.Invoke(); + + Assert.Equal(0, trackBar.Value); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_WithoutCreateControl_TestData))] + public void TrackBarFirstButtonAccessibleObject_Invoke_DoesNotWork_IfHandleIsNotCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: false, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.Equal(value, trackBar.Value); + + accessibleObject.Invoke(); + + Assert.Equal(value, trackBar.Value); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarFirstButtonAccessibleObject_InvokePattern_DoesNotSupport(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.True(accessibleObject.IsPatternSupported(Interop.UiaCore.UIA.InvokePatternId)); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarFirstButtonAccessibleObject_GetPropertyValue_IsEnabledProperty_ReturnsTrue_OwnerEnabled(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + trackBar.Enabled = true; + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.True((bool)accessibleObject.GetPropertyValue(UiaCore.UIA.IsEnabledPropertyId)); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarFirstButtonAccessibleObject_GetPropertyValue_IsEnabledProperty_ReturnsFalse_OwnerDisabled(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + trackBar.Enabled = false; + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.False((bool)accessibleObject.GetPropertyValue(UiaCore.UIA.IsEnabledPropertyId)); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_FirstButtonIsDisplayed_TestData))] + public void TrackBarFirstButtonAccessibleObject_IsDisplayed_ReturnsTrue_OwnerVisible(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + trackBar.Visible = true; + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.True(accessibleObject.IsDisplayed); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_FirstButtonIsDisplayed_TestData))] + public void TrackBarFirstButtonAccessibleObject_IsDisplayed_ReturnsFalse_OwnerInvisible(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + trackBar.Visible = false; + TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar); + + Assert.False(accessibleObject.IsDisplayed); + Assert.True(trackBar.IsHandleCreated); + } + + private TrackBar GetTrackBar(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int value, int minimum, int maximum) + { + TrackBar trackBar = new() + { + Value = value, + Maximum = maximum, + Minimum = minimum, + LargeChange = 3, + Orientation = orientation, + RightToLeft = rightToLeft, + RightToLeftLayout = rightToLeftLayout + }; + + if (createControl) + { + trackBar.CreateControl(); + } + + return trackBar; + } + + private TrackBar.TrackBarFirstButtonAccessibleObject GetTrackBarFirstButton(TrackBar trackBar) + { + TrackBar.TrackBarAccessibleObject trackBarAccessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + + return trackBarAccessibleObject.FirstButtonAccessibleObject; + } + } +} diff --git a/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBar.TrackBarLastButtonAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBar.TrackBarLastButtonAccessibleObjectTests.cs new file mode 100644 index 00000000000..a0c04e12a36 --- /dev/null +++ b/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBar.TrackBarLastButtonAccessibleObjectTests.cs @@ -0,0 +1,388 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms.TestUtilities; +using Xunit; +using static Interop; + +namespace System.Windows.Forms.Tests.AccessibleObjects +{ + public class TrackBar_TrackBarLastButtonAccessibleObjectTests : IClassFixture + { + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_LastButtonIsDisplayed_TestData))] + public void TrackBarLastButtonAccessibleObject_Bounds_ReturnsNotEmptyRectangle_IfButtonIsDisplayed(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.NotEqual(Rectangle.Empty, accessibleObject.Bounds); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_LastButtonIsHidden_TestData))] + public void TrackBarLastButtonAccessibleObject_Bounds_ReturnsEmptyRectangle_IfButtonIsHidden(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.Equal(Rectangle.Empty, accessibleObject.Bounds); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_WithoutCreateControl_TestData))] + public void TrackBarLastButtonAccessibleObject_Bounds_ReturnsEmptyRectangle_IfHandleIsNotCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: false, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.Equal(Rectangle.Empty, accessibleObject.Bounds); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarLastButtonAccessibleObject_DefaultAction_ReturnActionPress(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.Equal(SR.AccessibleActionPress, accessibleObject.DefaultAction); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarLastButtonAccessibleObject_Help_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.Null(accessibleObject.Help); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + public static IEnumerable TrackBarAccessibleObject_IncreaseButtonName_TestData() + { + foreach (RightToLeft rightToLeft in new RightToLeft[] { RightToLeft.Yes, RightToLeft.No }) + { + foreach (bool rightToLeftLayout in new[] { true, false }) + { + if (rightToLeft == RightToLeft.Yes && rightToLeftLayout == false) + { + continue; + } + + foreach (bool createControl in new[] { true, false }) + { + yield return new object[] { Orientation.Horizontal, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 10, /*value*/ 5 }; + yield return new object[] { Orientation.Horizontal, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 10, /*value*/ 0 }; + yield return new object[] { Orientation.Horizontal, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 10, /*value*/ 10 }; + yield return new object[] { Orientation.Horizontal, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 0, /*value*/ 0 }; + } + } + } + } + + [WinFormsTheory] + [MemberData(nameof(TrackBarAccessibleObject_IncreaseButtonName_TestData))] + public void TrackBarFirstButtonAccessibleObject_Name_ReturnIncreaseName(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.Equal(SR.TrackBarLargeIncreaseButtonName, accessibleObject.Name); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + public static IEnumerable TrackBarAccessibleObject_DecreaseButtonName_TestData() + { + foreach (Orientation orientation in Enum.GetValues(typeof(Orientation))) + { + foreach (RightToLeft rightToLeft in new RightToLeft[] { RightToLeft.Yes, RightToLeft.No }) + { + foreach (bool rightToLeftLayout in new[] { true, false }) + { + if (orientation == Orientation.Vertical || (rightToLeft == RightToLeft.Yes && rightToLeftLayout == false)) + { + foreach (bool createControl in new[] { true, false }) + { + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 10, /*value*/ 5 }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 10, /*value*/ 0 }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 10, /*value*/ 10 }; + yield return new object[] { orientation, rightToLeft, rightToLeftLayout, createControl, /*minumim*/ 0, /*maximum*/ 0, /*value*/ 0 }; + } + } + } + } + } + } + + [WinFormsTheory] + [MemberData(nameof(TrackBarAccessibleObject_DecreaseButtonName_TestData))] + public void TrackBarLLastButtonAccessibleObject_Name_ReturnDecreaseName(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.Equal(SR.TrackBarLargeDecreaseButtonName, accessibleObject.Name); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarLastButtonAccessibleObject_Role_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + AccessibleRole accessibleRole = createControl ? AccessibleRole.PushButton : AccessibleRole.None; + + Assert.Equal(accessibleRole, accessibleObject.Role); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarLastButtonAccessibleObject_State_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + var bounds = accessibleObject.Bounds; + AccessibleStates expectedState = accessibleObject.IsDisplayed || !trackBar.IsHandleCreated + ? AccessibleStates.None + : AccessibleStates.Invisible; + + Assert.Equal(expectedState, accessibleObject.State); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_LastButtonIsHidden_TestData))] + public void TrackBarLastButtonAccessibleObject_FragmentNavigate_ReturnsNull_IfButtonIsHidden(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.Parent)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.PreviousSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.LastChild)); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_WithoutCreateControl_TestData))] + public void TrackBarLastButtonAccessibleObject_FragmentNavigate_ReturnsNull_IfHandleIsNotCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: false, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.Parent)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.PreviousSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.LastChild)); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_LastButtonIsDisplayed_TestData))] + public void TrackBarLastButtonAccessibleObject_FragmentNavigate_ReturnsExpected_IfButtonIsDisplayed(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + var trackBarAccessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = trackBarAccessibleObject.LastButtonAccessibleObject; + + Assert.Equal(trackBarAccessibleObject, accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.Parent)); + Assert.Equal(trackBarAccessibleObject.ThumbAccessibleObject, accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.PreviousSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.LastChild)); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarLastButtonAccessibleObject_GetChildCount_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.Equal(-1, accessibleObject.GetChildCount()); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarLastButtonAccessibleObject_GetChild_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.Null(accessibleObject.GetChild(-1)); + Assert.Null(accessibleObject.GetChild(0)); + Assert.Null(accessibleObject.GetChild(1)); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [InlineData(Orientation.Vertical, RightToLeft.Yes, true)] + [InlineData(Orientation.Vertical, RightToLeft.Yes, false)] + [InlineData(Orientation.Vertical, RightToLeft.No, true)] + [InlineData(Orientation.Vertical, RightToLeft.No, false)] + [InlineData(Orientation.Horizontal, RightToLeft.Yes, false)] + public void TrackBarLastButtonAccessibleObject_Invoke_Decrease_WorkCorrectly(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value: 5, 0, 10); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.Equal(5, trackBar.Value); + + accessibleObject.Invoke(); + + Assert.Equal(2, trackBar.Value); + + accessibleObject.Invoke(); + + Assert.Equal(0, trackBar.Value); + + accessibleObject.Invoke(); + + Assert.Equal(0, trackBar.Value); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [InlineData(Orientation.Horizontal, RightToLeft.No, true)] + [InlineData(Orientation.Horizontal, RightToLeft.No, false)] + [InlineData(Orientation.Horizontal, RightToLeft.Yes, true)] + public void TrackBarLastButtonAccessibleObject_Invoke_Increase_WorkCorrectly(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value: 5, 0, 10); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.Equal(5, trackBar.Value); + + accessibleObject.Invoke(); + + Assert.Equal(8, trackBar.Value); + + accessibleObject.Invoke(); + + Assert.Equal(10, trackBar.Value); + + accessibleObject.Invoke(); + + Assert.Equal(10, trackBar.Value); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_WithoutCreateControl_TestData))] + public void TrackBarLastButtonAccessibleObject_Invoke_DoesNotWork_IfHandleIsNotCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: false, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.Equal(value, trackBar.Value); + + accessibleObject.Invoke(); + + Assert.Equal(value, trackBar.Value); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarLastButtonAccessibleObject_InvokePattern_DoesNotSupport(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.True(accessibleObject.IsPatternSupported(Interop.UiaCore.UIA.InvokePatternId)); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarLastButtonAccessibleObject_GetPropertyValue_IsEnabledProperty_ReturnsTrue_OwnerEnabled(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + trackBar.Enabled = true; + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.True((bool)accessibleObject.GetPropertyValue(UiaCore.UIA.IsEnabledPropertyId)); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarLastButtonAccessibleObject_GetPropertyValue_IsEnabledProperty_ReturnsFalse_OwnerDisabled(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + trackBar.Enabled = false; + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.False((bool)accessibleObject.GetPropertyValue(UiaCore.UIA.IsEnabledPropertyId)); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_LastButtonIsDisplayed_TestData))] + public void TrackBarLastButtonAccessibleObject_IsDisplayed_ReturnsTrue_OwnerVisible(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + trackBar.Visible = true; + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.True(accessibleObject.IsDisplayed); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_LastButtonIsDisplayed_TestData))] + public void TrackBarLastButtonAccessibleObject_IsDisplayed_ReturnsFalse_OwnerInvisible(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + trackBar.Visible = false; + TrackBar.TrackBarLastButtonAccessibleObject accessibleObject = GetTrackBarLastButton(trackBar); + + Assert.False(accessibleObject.IsDisplayed); + Assert.True(trackBar.IsHandleCreated); + } + + private TrackBar GetTrackBar(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int value, int minimum, int maximum) + { + TrackBar trackBar = new() + { + Value = value, + Maximum = maximum, + Minimum = minimum, + LargeChange = 3, + Orientation = orientation, + RightToLeft = rightToLeft, + RightToLeftLayout = rightToLeftLayout + }; + + if (createControl) + { + trackBar.CreateControl(); + } + + return trackBar; + } + + private TrackBar.TrackBarLastButtonAccessibleObject GetTrackBarLastButton(TrackBar trackBar) + { + TrackBar.TrackBarAccessibleObject trackBarAccessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + + return trackBarAccessibleObject.LastButtonAccessibleObject; + } + } +} diff --git a/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBar.TrackBarThumbAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBar.TrackBarThumbAccessibleObjectTests.cs new file mode 100644 index 00000000000..24f24ce73a7 --- /dev/null +++ b/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBar.TrackBarThumbAccessibleObjectTests.cs @@ -0,0 +1,266 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Drawing; +using System.Windows.Forms.TestUtilities; +using Xunit; +using static Interop; + +namespace System.Windows.Forms.Tests.AccessibleObjects +{ + public class TrackBar_TrackBarThumbAccessibleObjectTests : IClassFixture + { + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_WithoutCreateControl_TestData))] + public void TrackBarThumbAccessibleObject_Bounds_ReturnsEmptyRectangle_IfHandleIsNotCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: false, value, minimum, maximum); + TrackBar.TrackBarThumbAccessibleObject accessibleObject = GetTrackBarThumb(trackBar); + + Assert.Equal(Rectangle.Empty, accessibleObject.Bounds); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_WithoutCreateControl_TestData))] + public void TrackBarThumbAccessibleObject_Bounds_ReturnsRectangle_IfHandleIsCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + TrackBar.TrackBarThumbAccessibleObject accessibleObject = GetTrackBarThumb(trackBar); + + Assert.NotEqual(Rectangle.Empty, accessibleObject.Bounds); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarThumbAccessibleObject_DefaultAction_ReturnActionPress(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarThumbAccessibleObject accessibleObject = GetTrackBarThumb(trackBar); + + Assert.Null(accessibleObject.DefaultAction); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarThumbAccessibleObject_Help_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarThumbAccessibleObject accessibleObject = GetTrackBarThumb(trackBar); + + Assert.Null(accessibleObject.Help); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarThumbAccessibleObject_Name_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarThumbAccessibleObject accessibleObject = GetTrackBarThumb(trackBar); + + Assert.Equal(SR.TrackBarPositionButtonName, accessibleObject.Name); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarThumbAccessibleObject_Role_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarThumbAccessibleObject accessibleObject = GetTrackBarThumb(trackBar); + AccessibleRole accessibleRole = createControl ? AccessibleRole.Indicator : AccessibleRole.None; + + Assert.Equal(accessibleRole, accessibleObject.Role); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarThumbAccessibleObject_State_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarThumbAccessibleObject accessibleObject = GetTrackBarThumb(trackBar); + Assert.Equal(AccessibleStates.None, accessibleObject.State); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_ButtonsAreDisplayed_TestData))] + public void TrackBarThumbAccessibleObject_FragmentNavigate_ReturnExpected_IfButtonsIsDisplayed(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + var trackBarAccessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + TrackBar.TrackBarThumbAccessibleObject accessibleObject = trackBarAccessibleObject.ThumbAccessibleObject; + + Assert.Equal(trackBarAccessibleObject, accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.Parent)); + Assert.Equal(trackBarAccessibleObject.LastButtonAccessibleObject, accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling)); + Assert.Equal(trackBarAccessibleObject.FirstButtonAccessibleObject, accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.PreviousSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.LastChild)); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_FirstButtonIsHidden_TestData))] + public void TrackBarThumbAccessibleObject_FragmentNavigate_ReturnExpected_IfFirstButtonIsDisplayed(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + var trackBarAccessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + TrackBar.TrackBarThumbAccessibleObject accessibleObject = trackBarAccessibleObject.ThumbAccessibleObject; + + Assert.Equal(trackBarAccessibleObject, accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.Parent)); + Assert.Equal(trackBarAccessibleObject.LastButtonAccessibleObject, accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.PreviousSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.LastChild)); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_LastButtonIsHidden_TestData))] + public void TrackBarThumbAccessibleObject_FragmentNavigate_ReturnExpected_IfLastButtonIsDisplayed(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum); + var trackBarAccessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + TrackBar.TrackBarThumbAccessibleObject accessibleObject = trackBarAccessibleObject.ThumbAccessibleObject; + + Assert.Equal(trackBarAccessibleObject, accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.Parent)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling)); + Assert.Equal(trackBarAccessibleObject.FirstButtonAccessibleObject, accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.PreviousSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.LastChild)); + Assert.True(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_WithoutCreateControl_TestData))] + public void TrackBarThumbAccessibleObject_FragmentNavigate_ReturnNull_IfHandleIsNotCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: false, value, minimum, maximum); + var trackBarAccessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + TrackBar.TrackBarThumbAccessibleObject accessibleObject = trackBarAccessibleObject.ThumbAccessibleObject; + + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.Parent)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.PreviousSibling)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild)); + Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.LastChild)); + Assert.False(trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarThumbAccessibleObject_GetChildCount_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarThumbAccessibleObject accessibleObject = GetTrackBarThumb(trackBar); + + Assert.Equal(-1, accessibleObject.GetChildCount()); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarThumbAccessibleObject_GetChild_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarThumbAccessibleObject accessibleObject = GetTrackBarThumb(trackBar); + + Assert.Null(accessibleObject.GetChild(-1)); + Assert.Null(accessibleObject.GetChild(0)); + Assert.Null(accessibleObject.GetChild(1)); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarThumbAccessibleObject_InvokePattern_DoesNotSupport(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + TrackBar.TrackBarThumbAccessibleObject accessibleObject = GetTrackBarThumb(trackBar); + + Assert.False(accessibleObject.IsPatternSupported(Interop.UiaCore.UIA.InvokePatternId)); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarThumbAccessibleObject_GetPropertyValue_IsEnabledProperty_ReturnsTrue_OwnerEnabled(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + trackBar.Enabled = true; + TrackBar.TrackBarThumbAccessibleObject accessibleObject = GetTrackBarThumb(trackBar); + + Assert.True((bool)accessibleObject.GetPropertyValue(UiaCore.UIA.IsEnabledPropertyId)); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarThumbAccessibleObject_GetPropertyValue_IsEnabledProperty_ReturnsFalse_OwnerDisabled(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + trackBar.Enabled = false; + TrackBar.TrackBarThumbAccessibleObject accessibleObject = GetTrackBarThumb(trackBar); + + Assert.False((bool)accessibleObject.GetPropertyValue(UiaCore.UIA.IsEnabledPropertyId)); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarThumbAccessibleObject_IsDisplayed_ReturnsTrue_OwnerVisible(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + trackBar.Visible = true; + TrackBar.TrackBarThumbAccessibleObject accessibleObject = GetTrackBarThumb(trackBar); + + Assert.True(accessibleObject.IsDisplayed); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + [WinFormsTheory] + [CommonMemberData(typeof(TrackBarTestHelper), nameof(TrackBarTestHelper.TrackBarAccessibleObject_TestData))] + public void TrackBarThumbAccessibleObject_IsDisplayed_ReturnsFalse_OwnerInvisible(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value) + { + using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum); + trackBar.Visible = false; + TrackBar.TrackBarThumbAccessibleObject accessibleObject = GetTrackBarThumb(trackBar); + + Assert.False(accessibleObject.IsDisplayed); + Assert.Equal(createControl, trackBar.IsHandleCreated); + } + + private TrackBar GetTrackBar(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int value, int minimum, int maximum) + { + TrackBar trackBar = new() + { + Value = value, + Maximum = maximum, + Minimum = minimum, + LargeChange = 3, + Orientation = orientation, + RightToLeft = rightToLeft, + RightToLeftLayout = rightToLeftLayout + }; + + if (createControl) + { + trackBar.CreateControl(); + } + + return trackBar; + } + + private TrackBar.TrackBarThumbAccessibleObject GetTrackBarThumb(TrackBar trackBar) + { + TrackBar.TrackBarAccessibleObject trackBarAccessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject; + + return trackBarAccessibleObject.ThumbAccessibleObject; + } + } +} diff --git a/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBarAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBarAccessibleObjectTests.cs deleted file mode 100644 index d9b684717a4..00000000000 --- a/src/System.Windows.Forms/tests/UnitTests/AccessibleObjects/TrackBarAccessibleObjectTests.cs +++ /dev/null @@ -1,208 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Collections.Generic; -using System.Drawing; -using System.Runtime.InteropServices; -using Accessibility; -using Xunit; -using static Interop; - -namespace System.Windows.Forms.Tests.AccessibleObjects -{ - public class TrackBarAccessibleObjectTests : IClassFixture - { - [WinFormsFact] - public void TrackBarAccessibilityObject_Properties_ReturnsExpected_IfHandleIsCreated() - { - using var ownerControl = new TrackBar - { - Value = 5, - }; - - ownerControl.CreateControl(); - Control.ControlAccessibleObject accessibilityObject = Assert.IsAssignableFrom(ownerControl.AccessibilityObject); - Assert.Equal(ownerControl.Size, accessibilityObject.Bounds.Size); - Assert.Null(accessibilityObject.DefaultAction); - Assert.Null(accessibilityObject.Description); - Assert.True(ownerControl.IsHandleCreated); - Assert.Equal(ownerControl.Handle, accessibilityObject.Handle); - Assert.Null(accessibilityObject.Help); - Assert.Null(accessibilityObject.KeyboardShortcut); - Assert.Null(accessibilityObject.Name); - Assert.Equal(AccessibleRole.Slider, accessibilityObject.Role); - Assert.Same(ownerControl, accessibilityObject.Owner); - Assert.NotNull(accessibilityObject.Parent); - Assert.Equal(AccessibleStates.Focusable, accessibilityObject.State); - Assert.Equal("50", accessibilityObject.Value); - } - - [WinFormsFact] - public void TrackBarAccessibilityObject_Properties_ReturnsExpected_IfHandleIsNotCreated() - { - using var ownerControl = new TrackBar - { - Value = 5, - }; - - Control.ControlAccessibleObject accessibilityObject = Assert.IsAssignableFrom(ownerControl.AccessibilityObject); - Assert.Equal(Rectangle.Empty.Size, accessibilityObject.Bounds.Size); - Assert.Null(accessibilityObject.DefaultAction); - Assert.Null(accessibilityObject.Description); - Assert.Null(accessibilityObject.Help); - Assert.Null(accessibilityObject.KeyboardShortcut); - Assert.Null(accessibilityObject.Name); - Assert.Equal(AccessibleRole.None, accessibilityObject.Role); - Assert.Same(ownerControl, accessibilityObject.Owner); - Assert.Null(accessibilityObject.Parent); - Assert.Equal(AccessibleStates.None, accessibilityObject.State); - Assert.Equal(string.Empty, accessibilityObject.Value); - Assert.False(ownerControl.IsHandleCreated); - Assert.Equal(ownerControl.Handle, accessibilityObject.Handle); - } - - [WinFormsTheory] - [InlineData("100", 10, "100", true)] - [InlineData("50", 5, "50", true)] - [InlineData("54", 5, "50", true)] - [InlineData("56", 5, "50", true)] - [InlineData("0", 0, "0", true)] - [InlineData("100", 0, "", false)] - [InlineData("50", 0, "", false)] - [InlineData("54", 0, "", false)] - [InlineData("56", 0, "", false)] - [InlineData("0", 0, "", false)] - public void TrackBarAccessibilityObject_Value_Set_GetReturnsExpected(string value, int expected, string expectedValueString, bool createControl) - { - using var ownerControl = new TrackBar(); - if (createControl) - { - ownerControl.CreateControl(); - } - - Assert.Equal(createControl, ownerControl.IsHandleCreated); - Control.ControlAccessibleObject accessibilityObject = Assert.IsAssignableFrom(ownerControl.AccessibilityObject); - Assert.Equal(createControl, ownerControl.IsHandleCreated); - accessibilityObject.Value = value; - Assert.Equal(expectedValueString, accessibilityObject.Value); - Assert.Equal(expected, ownerControl.Value); - - // Set same. - accessibilityObject.Value = value; - Assert.Equal(expectedValueString, accessibilityObject.Value); - Assert.Equal(expected, ownerControl.Value); - } - - [WinFormsTheory] - [InlineData(null)] - [InlineData("")] - [InlineData("NotAnInt")] - public void TrackBarAccessibilityObject_Value_SetInvalid_ThrowsCOMException_IfHandleIsCreated(string value) - { - using var ownerControl = new TrackBar - { - Value = 5 - }; - - ownerControl.CreateControl(); - Control.ControlAccessibleObject accessibilityObject = Assert.IsAssignableFrom(ownerControl.AccessibilityObject); - Assert.Throws(() => accessibilityObject.Value = value); - Assert.Equal("50", accessibilityObject.Value); - Assert.Equal(5, ownerControl.Value); - } - - [WinFormsTheory] - [InlineData(null)] - [InlineData("")] - [InlineData("NotAnInt")] - public void TrackBarAccessibilityObject_Value_SetInvalid_ThrowsCOMException_IfHandleIsNotCreated(string value) - { - using var ownerControl = new TrackBar - { - Value = 5 - }; - - Control.ControlAccessibleObject accessibilityObject = Assert.IsAssignableFrom(ownerControl.AccessibilityObject); - accessibilityObject.Value = value; - Assert.Equal(string.Empty, accessibilityObject.Value); - Assert.Equal(5, ownerControl.Value); - } - - [WinFormsTheory] - [InlineData(true, 3)] - [InlineData(false, 0)] - public void TrackBarAccessibilityObject_GetChildCount_ReturnsExpected(bool createControl, int expectedChildACount) - { - using var ownerControl = new TrackBar - { - Value = 5 - }; - - if (createControl) - { - ownerControl.CreateControl(); - } - - Control.ControlAccessibleObject accessibilityObject = Assert.IsAssignableFrom(ownerControl.AccessibilityObject); - IAccessible iAccessible = accessibilityObject; - Assert.Equal(expectedChildACount, iAccessible.accChildCount); - Assert.Equal(-1, accessibilityObject.GetChildCount()); - } - - [WinFormsFact] - public void TrackBarAccessibilityObject_ControlType_IsSlider_IfAccessibleRoleIsDefault() - { - using TrackBar trackBar = new TrackBar(); - trackBar.CreateControl(); - // AccessibleRole is not set = Default - - object actual = trackBar.AccessibilityObject.GetPropertyValue(UiaCore.UIA.ControlTypePropertyId); - - Assert.Equal(UiaCore.UIA.SliderControlTypeId, actual); - Assert.True(trackBar.IsHandleCreated); - } - - [WinFormsFact] - public void TrackBarAccessibilityObject_Role_IsStatusBar_ByDefault() - { - using TrackBar trackBar = new TrackBar(); - trackBar.CreateControl(); - // AccessibleRole is not set = Default - - AccessibleRole actual = trackBar.AccessibilityObject.Role; - - Assert.Equal(AccessibleRole.Slider, actual); - Assert.True(trackBar.IsHandleCreated); - } - - public static IEnumerable TrackBarAccessibleObject_GetPropertyValue_ControlType_IsExpected_ForCustomRole_TestData() - { - Array roles = Enum.GetValues(typeof(AccessibleRole)); - - foreach (AccessibleRole role in roles) - { - if (role == AccessibleRole.Default) - { - continue; // The test checks custom roles - } - - yield return new object[] { role }; - } - } - - [WinFormsTheory] - [MemberData(nameof(TrackBarAccessibleObject_GetPropertyValue_ControlType_IsExpected_ForCustomRole_TestData))] - public void TrackBarAccessibleObject_GetPropertyValue_ControlType_IsExpected_ForCustomRole(AccessibleRole role) - { - using TrackBar trackBar = new TrackBar(); - trackBar.AccessibleRole = role; - - object actual = trackBar.AccessibilityObject.GetPropertyValue(UiaCore.UIA.ControlTypePropertyId); - UiaCore.UIA expected = AccessibleRoleControlTypeMap.GetControlType(role); - - Assert.Equal(expected, actual); - Assert.False(trackBar.IsHandleCreated); - } - } -}