Fixing DataGridView's scrollbars shouldn't include their control type in their accessible names (#3038)

* ScrollBar accessible object class
* Accessible objects for scroll bar child classes
* Added unit tests for new accessible objects
This commit is contained in:
Aleksandr Beliaev 2020-07-08 03:37:15 +03:00 коммит произвёл GitHub
Родитель fd49490709
Коммит 152c8e12b6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
24 изменённых файлов: 432 добавлений и 4 удалений

Просмотреть файл

@ -7,3 +7,6 @@ System.Windows.Forms.ListViewGroup.TitleImageKey.set -> void
~System.Windows.Forms.ListView.GroupImageList.get -> System.Windows.Forms.ImageList
~System.Windows.Forms.ListView.GroupImageList.set -> void
~override System.Windows.Forms.PictureBox.CreateAccessibilityInstance() -> System.Windows.Forms.AccessibleObject
override System.Windows.Forms.HScrollBar.CreateAccessibilityInstance() -> System.Windows.Forms.AccessibleObject!
override System.Windows.Forms.ScrollBar.CreateAccessibilityInstance() -> System.Windows.Forms.AccessibleObject!
override System.Windows.Forms.VScrollBar.CreateAccessibilityInstance() -> System.Windows.Forms.AccessibleObject!

Просмотреть файл

@ -6647,6 +6647,12 @@ Stack trace where the illegal operation occurred was:
<data name="TaskDialogCanUpdateStateOnlyWhenShown" xml:space="preserve">
<value>Can only update the state of a task dialog while it is shown.</value>
</data>
<data name="HScrollBarDefaultAccessibleName" xml:space="preserve">
<value>Horizontal</value>
</data>
<data name="VScrollBarDefaultAccessibleName" xml:space="preserve">
<value>Vertical</value>
</data>
<data name="TaskDialogCollectionAlreadyBound" xml:space="preserve">
<value>One of the collections of this {0} is already bound to a {1} instance.</value>
</data>

10
src/System.Windows.Forms/src/Resources/xlf/SR.cs.xlf сгенерированный
Просмотреть файл

@ -5427,6 +5427,11 @@ Chcete jej nahradit?</target>
<target state="translated">Počet řádků v tabulce</target>
<note />
</trans-unit>
<trans-unit id="HScrollBarDefaultAccessibleName">
<source>Horizontal</source>
<target state="new">Horizontal</target>
<note />
</trans-unit>
<trans-unit id="HandleAlreadyExists">
<source>Window handle already exists.</source>
<target state="translated">Popisovač okna již existuje.</target>
@ -10791,6 +10796,11 @@ Trasování zásobníku, kde došlo k neplatné operaci:
<target state="translated">Vyvolá se při každém načtení uživatelského ovládacího prvku.</target>
<note />
</trans-unit>
<trans-unit id="VScrollBarDefaultAccessibleName">
<source>Vertical</source>
<target state="new">Vertical</target>
<note />
</trans-unit>
<trans-unit id="VisualStyleHandleCreationFailed">
<source>Visual Style handle creation operation did not succeed.</source>
<target state="translated">Operace vytvoření popisovače vizuálního stylu se nezdařila.</target>

10
src/System.Windows.Forms/src/Resources/xlf/SR.de.xlf сгенерированный
Просмотреть файл

@ -5427,6 +5427,11 @@ Möchten Sie sie ersetzen?</target>
<target state="translated">Die Anzahl der Zeilen für die Tabelle.</target>
<note />
</trans-unit>
<trans-unit id="HScrollBarDefaultAccessibleName">
<source>Horizontal</source>
<target state="new">Horizontal</target>
<note />
</trans-unit>
<trans-unit id="HandleAlreadyExists">
<source>Window handle already exists.</source>
<target state="translated">Der Fensterhandle ist bereits vorhanden.</target>
@ -10791,6 +10796,11 @@ Stapelüberwachung, in der der unzulässige Vorgang auftrat:
<target state="translated">Tritt ein, wenn das Benutzersteuerelement geladen wird.</target>
<note />
</trans-unit>
<trans-unit id="VScrollBarDefaultAccessibleName">
<source>Vertical</source>
<target state="new">Vertical</target>
<note />
</trans-unit>
<trans-unit id="VisualStyleHandleCreationFailed">
<source>Visual Style handle creation operation did not succeed.</source>
<target state="translated">Fehler beim Erstellen eines Visual Style-Handles.</target>

10
src/System.Windows.Forms/src/Resources/xlf/SR.es.xlf сгенерированный
Просмотреть файл

@ -5427,6 +5427,11 @@ Do you want to replace it?</source>
<target state="translated">Número de filas de la tabla.</target>
<note />
</trans-unit>
<trans-unit id="HScrollBarDefaultAccessibleName">
<source>Horizontal</source>
<target state="new">Horizontal</target>
<note />
</trans-unit>
<trans-unit id="HandleAlreadyExists">
<source>Window handle already exists.</source>
<target state="translated">Ya existe el identificador de ventana.</target>
@ -10791,6 +10796,11 @@ El seguimiento de la pila donde tuvo lugar la operación no válida fue:
<target state="translated">Tiene lugar siempre que se carga el control de usuario.</target>
<note />
</trans-unit>
<trans-unit id="VScrollBarDefaultAccessibleName">
<source>Vertical</source>
<target state="new">Vertical</target>
<note />
</trans-unit>
<trans-unit id="VisualStyleHandleCreationFailed">
<source>Visual Style handle creation operation did not succeed.</source>
<target state="translated">Error en la operación de creación de un identificador de Visual Style.</target>

10
src/System.Windows.Forms/src/Resources/xlf/SR.fr.xlf сгенерированный
Просмотреть файл

@ -5427,6 +5427,11 @@ Voulez-vous le remplacer ?</target>
<target state="translated">Nombre de ligne de la table.</target>
<note />
</trans-unit>
<trans-unit id="HScrollBarDefaultAccessibleName">
<source>Horizontal</source>
<target state="new">Horizontal</target>
<note />
</trans-unit>
<trans-unit id="HandleAlreadyExists">
<source>Window handle already exists.</source>
<target state="translated">Le handle de fenêtre existe déjà.</target>
@ -10791,6 +10796,11 @@ Cette opération non conforme s'est produite sur la trace de la pile :
<target state="translated">Se produit lors du chargement du contrôle utilisateur.</target>
<note />
</trans-unit>
<trans-unit id="VScrollBarDefaultAccessibleName">
<source>Vertical</source>
<target state="new">Vertical</target>
<note />
</trans-unit>
<trans-unit id="VisualStyleHandleCreationFailed">
<source>Visual Style handle creation operation did not succeed.</source>
<target state="translated">Échec de l'opération de création de handle de style visuel.</target>

10
src/System.Windows.Forms/src/Resources/xlf/SR.it.xlf сгенерированный
Просмотреть файл

@ -5427,6 +5427,11 @@ Sostituirlo?</target>
<target state="translated">Il numero di righe nella tabella.</target>
<note />
</trans-unit>
<trans-unit id="HScrollBarDefaultAccessibleName">
<source>Horizontal</source>
<target state="new">Horizontal</target>
<note />
</trans-unit>
<trans-unit id="HandleAlreadyExists">
<source>Window handle already exists.</source>
<target state="translated">Handle di finestra già esistente.</target>
@ -10791,6 +10796,11 @@ Traccia dello stack da cui si è verificata l'operazione non valida:
<target state="translated">Generato quando viene caricato il controllo utente.</target>
<note />
</trans-unit>
<trans-unit id="VScrollBarDefaultAccessibleName">
<source>Vertical</source>
<target state="new">Vertical</target>
<note />
</trans-unit>
<trans-unit id="VisualStyleHandleCreationFailed">
<source>Visual Style handle creation operation did not succeed.</source>
<target state="translated">Operazione di creazione handle per uno stile di visualizzazione non riuscita.</target>

10
src/System.Windows.Forms/src/Resources/xlf/SR.ja.xlf сгенерированный
Просмотреть файл

@ -5427,6 +5427,11 @@ Do you want to replace it?</source>
<target state="translated">テーブルの行数です。</target>
<note />
</trans-unit>
<trans-unit id="HScrollBarDefaultAccessibleName">
<source>Horizontal</source>
<target state="new">Horizontal</target>
<note />
</trans-unit>
<trans-unit id="HandleAlreadyExists">
<source>Window handle already exists.</source>
<target state="translated">ウィンドウ ハンドルは既に存在します。</target>
@ -10791,6 +10796,11 @@ Stack trace where the illegal operation occurred was:
<target state="translated">ユーザー コントロールを読み込むときに発生します。</target>
<note />
</trans-unit>
<trans-unit id="VScrollBarDefaultAccessibleName">
<source>Vertical</source>
<target state="new">Vertical</target>
<note />
</trans-unit>
<trans-unit id="VisualStyleHandleCreationFailed">
<source>Visual Style handle creation operation did not succeed.</source>
<target state="translated">Visual スタイル ハンドルを作成することができませんでした。</target>

10
src/System.Windows.Forms/src/Resources/xlf/SR.ko.xlf сгенерированный
Просмотреть файл

@ -5427,6 +5427,11 @@ Do you want to replace it?</source>
<target state="translated">테이블의 행 개수입니다.</target>
<note />
</trans-unit>
<trans-unit id="HScrollBarDefaultAccessibleName">
<source>Horizontal</source>
<target state="new">Horizontal</target>
<note />
</trans-unit>
<trans-unit id="HandleAlreadyExists">
<source>Window handle already exists.</source>
<target state="translated">창 핸들이 이미 있습니다.</target>
@ -10791,6 +10796,11 @@ Stack trace where the illegal operation occurred was:
<target state="translated">사용자 정의 컨트롤이 로드될 때마다 발생합니다.</target>
<note />
</trans-unit>
<trans-unit id="VScrollBarDefaultAccessibleName">
<source>Vertical</source>
<target state="new">Vertical</target>
<note />
</trans-unit>
<trans-unit id="VisualStyleHandleCreationFailed">
<source>Visual Style handle creation operation did not succeed.</source>
<target state="translated">비주얼 스타일 핸들을 만들지 못했습니다.</target>

10
src/System.Windows.Forms/src/Resources/xlf/SR.pl.xlf сгенерированный
Просмотреть файл

@ -5427,6 +5427,11 @@ Czy chcesz go zamienić?</target>
<target state="translated">Liczba wierszy w tabeli.</target>
<note />
</trans-unit>
<trans-unit id="HScrollBarDefaultAccessibleName">
<source>Horizontal</source>
<target state="new">Horizontal</target>
<note />
</trans-unit>
<trans-unit id="HandleAlreadyExists">
<source>Window handle already exists.</source>
<target state="translated">Uchwyt okna już istnieje.</target>
@ -10791,6 +10796,11 @@ Stos śledzenia, w którym wystąpiła zabroniona operacja:
<target state="translated">Występuje za każdym razem, gdy jest ładowany formant użytkownika.</target>
<note />
</trans-unit>
<trans-unit id="VScrollBarDefaultAccessibleName">
<source>Vertical</source>
<target state="new">Vertical</target>
<note />
</trans-unit>
<trans-unit id="VisualStyleHandleCreationFailed">
<source>Visual Style handle creation operation did not succeed.</source>
<target state="translated">Operacja utworzenia uchwytu elementu Visual Style nie powiodła się.</target>

Просмотреть файл

@ -5427,6 +5427,11 @@ Deseja substituí-lo?</target>
<target state="translated">O número de linhas na tabela.</target>
<note />
</trans-unit>
<trans-unit id="HScrollBarDefaultAccessibleName">
<source>Horizontal</source>
<target state="new">Horizontal</target>
<note />
</trans-unit>
<trans-unit id="HandleAlreadyExists">
<source>Window handle already exists.</source>
<target state="translated">O identificador de janela já existe.</target>
@ -10791,6 +10796,11 @@ Rastreamento de pilha em que a operação ilegal ocorreu:
<target state="translated">Ocorre sempre que o controle de usuário é carregado.</target>
<note />
</trans-unit>
<trans-unit id="VScrollBarDefaultAccessibleName">
<source>Vertical</source>
<target state="new">Vertical</target>
<note />
</trans-unit>
<trans-unit id="VisualStyleHandleCreationFailed">
<source>Visual Style handle creation operation did not succeed.</source>
<target state="translated">Falha na operação de criação de alça de Estilo Visual.</target>

10
src/System.Windows.Forms/src/Resources/xlf/SR.ru.xlf сгенерированный
Просмотреть файл

@ -5428,6 +5428,11 @@ Do you want to replace it?</source>
<target state="translated">Число строк в таблице.</target>
<note />
</trans-unit>
<trans-unit id="HScrollBarDefaultAccessibleName">
<source>Horizontal</source>
<target state="new">Horizontal</target>
<note />
</trans-unit>
<trans-unit id="HandleAlreadyExists">
<source>Window handle already exists.</source>
<target state="translated">Дескриптор окна уже существует.</target>
@ -10792,6 +10797,11 @@ Stack trace where the illegal operation occurred was:
<target state="translated">Происходит при каждой загрузке пользовательского элемента управления.</target>
<note />
</trans-unit>
<trans-unit id="VScrollBarDefaultAccessibleName">
<source>Vertical</source>
<target state="new">Vertical</target>
<note />
</trans-unit>
<trans-unit id="VisualStyleHandleCreationFailed">
<source>Visual Style handle creation operation did not succeed.</source>
<target state="translated">Операция создания дескриптора Visual Style не удалась.</target>

10
src/System.Windows.Forms/src/Resources/xlf/SR.tr.xlf сгенерированный
Просмотреть файл

@ -5427,6 +5427,11 @@ Bunu değiştirmek istiyor musunuz?</target>
<target state="translated">Tablodaki satır sayısı.</target>
<note />
</trans-unit>
<trans-unit id="HScrollBarDefaultAccessibleName">
<source>Horizontal</source>
<target state="new">Horizontal</target>
<note />
</trans-unit>
<trans-unit id="HandleAlreadyExists">
<source>Window handle already exists.</source>
<target state="translated">Pencere işleyicisi zaten var.</target>
@ -10791,6 +10796,11 @@ Geçersiz işlemin gerçekleştiği yığın izi:
<target state="translated">Kullanıcı denetimi her yüklendiğinde gerçekleşir.</target>
<note />
</trans-unit>
<trans-unit id="VScrollBarDefaultAccessibleName">
<source>Vertical</source>
<target state="new">Vertical</target>
<note />
</trans-unit>
<trans-unit id="VisualStyleHandleCreationFailed">
<source>Visual Style handle creation operation did not succeed.</source>
<target state="translated">Görsel Stil işleyicisi oluşturma işlemi başarısız oldu.</target>

Просмотреть файл

@ -5427,6 +5427,11 @@ Do you want to replace it?</source>
<target state="translated">表中的行数。</target>
<note />
</trans-unit>
<trans-unit id="HScrollBarDefaultAccessibleName">
<source>Horizontal</source>
<target state="new">Horizontal</target>
<note />
</trans-unit>
<trans-unit id="HandleAlreadyExists">
<source>Window handle already exists.</source>
<target state="translated">窗口句柄已存在。</target>
@ -10791,6 +10796,11 @@ Stack trace where the illegal operation occurred was:
<target state="translated">每当用户控件加载时发生。</target>
<note />
</trans-unit>
<trans-unit id="VScrollBarDefaultAccessibleName">
<source>Vertical</source>
<target state="new">Vertical</target>
<note />
</trans-unit>
<trans-unit id="VisualStyleHandleCreationFailed">
<source>Visual Style handle creation operation did not succeed.</source>
<target state="translated">视觉样式句柄创建操作失败。</target>

Просмотреть файл

@ -5427,6 +5427,11 @@ Do you want to replace it?</source>
<target state="translated">資料表中的資料列數目。</target>
<note />
</trans-unit>
<trans-unit id="HScrollBarDefaultAccessibleName">
<source>Horizontal</source>
<target state="new">Horizontal</target>
<note />
</trans-unit>
<trans-unit id="HandleAlreadyExists">
<source>Window handle already exists.</source>
<target state="translated">視窗控制代碼已經存在。</target>
@ -10791,6 +10796,11 @@ Stack trace where the illegal operation occurred was:
<target state="translated">載入使用者控制項時發生。</target>
<note />
</trans-unit>
<trans-unit id="VScrollBarDefaultAccessibleName">
<source>Vertical</source>
<target state="new">Vertical</target>
<note />
</trans-unit>
<trans-unit id="VisualStyleHandleCreationFailed">
<source>Visual Style handle creation operation did not succeed.</source>
<target state="translated">視覺化樣式控制代碼建立作業失敗。</target>

Просмотреть файл

@ -0,0 +1,27 @@
// 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System.Windows.Forms
{
public partial class HScrollBar
{
internal class HScrollBarAccessibleObject : ScrollBarAccessibleObject
{
internal HScrollBarAccessibleObject(HScrollBar owner) : base(owner)
{
}
public override string Name
{
get => base.Name ?? SR.HScrollBarDefaultAccessibleName;
}
}
}
}

Просмотреть файл

@ -12,7 +12,7 @@ namespace System.Windows.Forms
/// Represents a standard Windows horizontal scroll bar.
/// </summary>
[SRDescription(nameof(SR.DescriptionHScrollBar))]
public class HScrollBar : ScrollBar
public partial class HScrollBar : ScrollBar
{
protected override CreateParams CreateParams
{
@ -24,6 +24,10 @@ namespace System.Windows.Forms
}
}
protected override Size DefaultSize => new Size(80, SystemInformation.HorizontalScrollBarHeight);
protected override Size DefaultSize
=> new Size(80, SystemInformation.HorizontalScrollBarHeight);
protected override AccessibleObject CreateAccessibilityInstance()
=> new HScrollBarAccessibleObject(this);
}
}

Просмотреть файл

@ -0,0 +1,49 @@
// 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Interop;
namespace System.Windows.Forms
{
public partial class ScrollBar
{
internal class ScrollBarAccessibleObject : ControlAccessibleObject
{
private ScrollBar _owningScrollBar;
internal ScrollBarAccessibleObject(ScrollBar owner) : base(owner)
{
_owningScrollBar = owner;
}
internal override bool IsIAccessibleExSupported() => true;
internal override bool IsPatternSupported(UiaCore.UIA patternId)
{
if (patternId == UiaCore.UIA.ValuePatternId)
{
return true;
}
return base.IsPatternSupported(patternId);
}
internal override object? GetPropertyValue(UiaCore.UIA propertyID)
=> propertyID switch
{
UiaCore.UIA.NamePropertyId => Name,
UiaCore.UIA.AutomationIdPropertyId => _owningScrollBar.Name,
UiaCore.UIA.ControlTypePropertyId => UiaCore.UIA.ScrollBarControlTypeId,
UiaCore.UIA.IsKeyboardFocusablePropertyId => true,
UiaCore.UIA.IsValuePatternAvailablePropertyId => IsPatternSupported(UiaCore.UIA.ValuePatternId),
_ => base.GetPropertyValue(propertyID)
};
}
}
}

Просмотреть файл

@ -14,7 +14,7 @@ namespace System.Windows.Forms
/// </summary>
[DefaultProperty(nameof(Value))]
[DefaultEvent(nameof(Scroll))]
public abstract class ScrollBar : Control
public abstract partial class ScrollBar : Control
{
private static readonly object s_scrollEvent = new object();
private static readonly object s_valueChangedEvent = new object();
@ -738,5 +738,15 @@ namespace System.Windows.Forms
break;
}
}
/// <summary>
/// Creates a new AccessibleObject for this <see cref='ScrollBar'/> instance.
/// The AccessibleObject instance returned by this method supports ControlType UIA property.
/// </summary>
/// <returns>
/// AccessibleObject for this <see cref='ScrollBar'/> instance.
/// </returns>
protected override AccessibleObject CreateAccessibilityInstance()
=> new ScrollBarAccessibleObject(this);
}
}

Просмотреть файл

@ -0,0 +1,27 @@
// 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System.Windows.Forms
{
public partial class VScrollBar
{
internal class VScrollBarAccessibleObject : ScrollBarAccessibleObject
{
internal VScrollBarAccessibleObject(VScrollBar owner) : base(owner)
{
}
public override string Name
{
get => base.Name ?? SR.VScrollBarDefaultAccessibleName;
}
}
}
}

Просмотреть файл

@ -13,7 +13,7 @@ namespace System.Windows.Forms
/// Represents a standard Windows vertical scroll bar.
/// </summary>
[SRDescription(nameof(SR.DescriptionVScrollBar))]
public class VScrollBar : ScrollBar
public partial class VScrollBar : ScrollBar
{
private const int DefaultHeight = 80;
@ -55,5 +55,8 @@ namespace System.Windows.Forms
add => base.RightToLeftChanged += value;
remove => base.RightToLeftChanged -= value;
}
protected override AccessibleObject CreateAccessibilityInstance()
=> new VScrollBarAccessibleObject(this);
}
}

Просмотреть файл

@ -0,0 +1,46 @@
// 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace System.Windows.Forms.Tests
{
public class HScrollBar_HScrollBarAccessibleObjectTests :
IClassFixture<ThreadExceptionFixture>
{
[WinFormsFact]
public void HScrollBarAccessibleObject_ctor_ThrowsException_IfHScrollBarAccessibleObjectIsNull()
{
Assert.Throws<ArgumentNullException>(() => new HScrollBar.HScrollBarAccessibleObject(null));
}
[WinFormsFact]
public void HScrollBarAccessibleObject_Ctor_Default()
{
using var horScrollBar = new HScrollBar();
AccessibleObject accessibleObject = horScrollBar.AccessibilityObject;
Assert.NotNull(accessibleObject);
Assert.Equal(AccessibleRole.ScrollBar, accessibleObject.Role);
// TODO: ControlAccessibleObject shouldn't force handle creation, tracked in https://github.com/dotnet/winforms/issues/3062
Assert.True(horScrollBar.IsHandleCreated);
}
[WinFormsFact]
public void HScrollBarAccessibleObject_Name_Get_ReturnsExpected()
{
using var horScrollBar = new HScrollBar();
HScrollBar.HScrollBarAccessibleObject accessibleObject =
Assert.IsType<HScrollBar.HScrollBarAccessibleObject>(horScrollBar.AccessibilityObject);
Assert.Equal("Horizontal", accessibleObject.Name);
// TODO: ControlAccessibleObject shouldn't force handle creation, tracked in https://github.com/dotnet/winforms/issues/3062
Assert.True(horScrollBar.IsHandleCreated);
}
}
}

Просмотреть файл

@ -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 System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using static Interop.UiaCore;
namespace System.Windows.Forms.Tests
{
public class ScrollBar_ScrollBarAccessibleObjectTests :
IClassFixture<ThreadExceptionFixture>
{
[WinFormsFact]
public void ScrollBarAccessibleObject_ctor_ThrowsException_IfScrollBarAccessibleObjectIsNull()
{
Assert.Throws<ArgumentNullException>(() => new ScrollBar.ScrollBarAccessibleObject(null));
}
[WinFormsFact]
public void ScrollBarAccessibleObject_Ctor_Default()
{
using var scrollBar = new SubScrollBar();
AccessibleObject accessibleObject = scrollBar.AccessibilityObject;
Assert.NotNull(accessibleObject);
Assert.Equal(AccessibleRole.ScrollBar, accessibleObject.Role);
// TODO: ControlAccessibleObject shouldn't force handle creation, tracked in https://github.com/dotnet/winforms/issues/3062
Assert.True(scrollBar.IsHandleCreated);
}
[WinFormsFact]
public void ScrollBarAccessibleObject_IsPatternSupported_Invoke_ReturnsExpected()
{
using var scrollBar = new SubScrollBar();
AccessibleObject accessibleObject = scrollBar.AccessibilityObject;
Assert.True(accessibleObject.IsPatternSupported(UIA.ValuePatternId));
// TODO: ControlAccessibleObject shouldn't force handle creation, tracked in https://github.com/dotnet/winforms/issues/3062
Assert.True(scrollBar.IsHandleCreated);
}
[WinFormsTheory]
[InlineData((int)UIA.NamePropertyId, "TestName")]
[InlineData((int)UIA.ControlTypePropertyId, UIA.ScrollBarControlTypeId)]
[InlineData((int)UIA.IsKeyboardFocusablePropertyId, true)]
[InlineData((int)UIA.IsValuePatternAvailablePropertyId, true)]
[InlineData((int)UIA.AutomationIdPropertyId, "AutomId")]
public void ScrollBarAccessibleObject_GetPropertyValue_Invoke_ReturnsExpected(int propertyID, object expected)
{
using var scrollBar = new SubScrollBar
{
AccessibleName = "TestName",
Name = "AutomId"
};
Assert.False(scrollBar.IsHandleCreated);
var scrollBarAccessibleObject = new ScrollBar.ScrollBarAccessibleObject(scrollBar);
object value = scrollBarAccessibleObject.GetPropertyValue((UIA)propertyID);
Assert.Equal(expected, value);
// TODO: ControlAccessibleObject shouldn't force handle creation, tracked in https://github.com/dotnet/winforms/issues/3062
Assert.True(scrollBar.IsHandleCreated);
}
private class SubScrollBar : ScrollBar
{
public SubScrollBar() : base()
{
}
}
}
}

Просмотреть файл

@ -0,0 +1,46 @@
// 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace System.Windows.Forms.Tests
{
public class VScrollBar_VScrollBarAccessibleObjectTests :
IClassFixture<ThreadExceptionFixture>
{
[WinFormsFact]
public void VScrollBarAccessibleObject_ctor_ThrowsException_IfVScrollBarAccessibleObjectIsNull()
{
Assert.Throws<ArgumentNullException>(() => new VScrollBar.VScrollBarAccessibleObject(null));
}
[WinFormsFact]
public void VScrollBarAccessibleObject_Ctor_Default()
{
using var vertScrollBar = new VScrollBar();
AccessibleObject accessibleObject = vertScrollBar.AccessibilityObject;
Assert.NotNull(accessibleObject);
Assert.Equal(AccessibleRole.ScrollBar, accessibleObject.Role);
// TODO: ControlAccessibleObject shouldn't force handle creation, tracked in https://github.com/dotnet/winforms/issues/3062
Assert.True(vertScrollBar.IsHandleCreated);
}
[WinFormsFact]
public void VScrollBarAccessibleObject_Name_Get_ReturnsExpected()
{
using var vertScrollBar = new VScrollBar();
VScrollBar.VScrollBarAccessibleObject accessibleObject
= Assert.IsType<VScrollBar.VScrollBarAccessibleObject>(vertScrollBar.AccessibilityObject);
Assert.Equal("Vertical", accessibleObject.Name);
// TODO: ControlAccessibleObject shouldn't force handle creation, tracked in https://github.com/dotnet/winforms/issues/3062
Assert.True(vertScrollBar.IsHandleCreated);
}
}
}