4
4
#nullable disable
5
5
6
6
using System . Drawing ;
7
+ using Windows . Win32 . System . Variant ;
7
8
using Windows . Win32 . UI . Accessibility ;
8
9
9
10
namespace System . Windows . Forms . Tests . AccessibleObjects ;
10
11
11
- public class ToolStripControlHost_ToolStripHostedControlAccessibleObjectTests
12
+ public class ToolStripControlHost_ToolStripHostedControlAccessibleObjectTests : IDisposable
12
13
{
14
+ private readonly ToolStrip _toolStrip ;
15
+ private readonly TextBox _textBox ;
16
+ private readonly ToolStripControlHost _host ;
17
+
18
+ public ToolStripControlHost_ToolStripHostedControlAccessibleObjectTests ( )
19
+ {
20
+ _toolStrip = new ToolStrip ( ) ;
21
+ _textBox = new TextBox ( ) ;
22
+ _host = new ToolStripControlHost ( _textBox ) ;
23
+ _toolStrip . Items . Add ( _host ) ;
24
+ }
25
+
26
+ public void Dispose ( )
27
+ {
28
+ _host . Dispose ( ) ;
29
+ _textBox . Dispose ( ) ;
30
+ _toolStrip . Dispose ( ) ;
31
+ }
32
+
13
33
public static IEnumerable < object [ ] > ToolStripItemAccessibleObject_TestData ( )
14
34
{
15
35
return ReflectionHelper . GetPublicNotAbstractClasses < ToolStripControlHost > ( ) . Select ( type => new object [ ] { type } ) ;
@@ -19,14 +39,119 @@ public static IEnumerable<object[]> ToolStripItemAccessibleObject_TestData()
19
39
[ MemberData ( nameof ( ToolStripItemAccessibleObject_TestData ) ) ]
20
40
public void ToolStripHostedControlAccessibleObject_GetPropertyValue_IsOffscreenPropertyId_ReturnExpected ( Type type )
21
41
{
22
- using ToolStrip toolStrip = new ( ) ;
23
- toolStrip . CreateControl ( ) ;
42
+ _toolStrip . CreateControl ( ) ;
24
43
using ToolStripControlHost item = ReflectionHelper . InvokePublicConstructor < ToolStripControlHost > ( type ) ;
25
44
item . Size = new Size ( 0 , 0 ) ;
26
- toolStrip . Items . Add ( item ) ;
45
+ _toolStrip . Items . Add ( item ) ;
46
+
47
+ GetIsOffscreenPropertyValue ( item . AccessibilityObject ) . Should ( ) . BeTrue ( ) ;
48
+ GetIsOffscreenPropertyValue ( item . Control . AccessibilityObject ) . Should ( ) . BeTrue ( ) ;
49
+ }
50
+
51
+ [ WinFormsFact ]
52
+ public void ToolStripHostedControlAccessibleObject_FragmentRoot_Returns_Owner_AccessibilityObject_When_Valid ( )
53
+ {
54
+ ToolStripControlHost . ToolStripHostedControlAccessibleObject accessibleObject =
55
+ new ( _textBox , _host ) ;
56
+ IRawElementProviderFragmentRoot . Interface fragmentRoot = accessibleObject . FragmentRoot ;
57
+
58
+ fragmentRoot . Should ( ) . BeSameAs ( _toolStrip . AccessibilityObject ) ;
59
+ }
60
+
61
+ [ WinFormsFact ]
62
+ public void ToolStripHostedControlAccessibleObject_FragmentRoot_FallsBack_ToBase_When_Null ( )
63
+ {
64
+ ToolStripControlHost . ToolStripHostedControlAccessibleObject accessibleObject =
65
+ new ( _textBox , null ) ;
66
+ IRawElementProviderFragmentRoot . Interface fragmentRoot = accessibleObject . FragmentRoot ;
67
+
68
+ fragmentRoot . Should ( ) . Be ( _textBox . AccessibilityObject . FragmentRoot ) ;
69
+ }
70
+
71
+ [ WinFormsFact ]
72
+ public void ToolStripHostedControlAccessibleObject_FragmentNavigate_FallsBack_ToBase_When_Null ( )
73
+ {
74
+ ToolStripControlHost . ToolStripHostedControlAccessibleObject accessibleObject =
75
+ new ( _textBox , null ) ;
76
+
77
+ // Use a valid direction that is not handled by the switch, e.g. NavigateDirection.NavigateDirection_FirstChild
78
+ NavigateDirection direction = NavigateDirection . NavigateDirection_FirstChild ;
79
+ IRawElementProviderFragment . Interface expected = _textBox . AccessibilityObject . FragmentNavigate ( direction ) ;
80
+ IRawElementProviderFragment . Interface actual = accessibleObject . FragmentNavigate ( direction ) ;
81
+
82
+ actual . Should ( ) . Be ( expected ) ;
83
+ }
84
+
85
+ [ WinFormsFact ]
86
+ public void ToolStripHostedControlAccessibleObject_ReturnsVariant_ForIsOffscreenPropertyId ( )
87
+ {
88
+ ToolStripControlHost . ToolStripHostedControlAccessibleObject accessibleObject =
89
+ new ( _textBox , null ) ;
90
+ VARIANT value = accessibleObject . GetPropertyValue ( UIA_PROPERTY_ID . UIA_IsOffscreenPropertyId ) ;
91
+
92
+ value . Type . Should ( ) . Be ( VARENUM . VT_BOOL ) ;
93
+ ( ( bool ) value ) . Should ( ) . BeTrue ( ) ;
94
+ }
95
+
96
+ [ WinFormsFact ]
97
+ public void ToolStripHostedControlAccessibleObject_GetPropertyValue_UnknownPropertyId_FallsBack_ToBase ( )
98
+ {
99
+ ToolStripControlHost . ToolStripHostedControlAccessibleObject accessibleObject =
100
+ new ( _textBox , null ) ;
101
+ VARIANT value = accessibleObject . GetPropertyValue ( ( UIA_PROPERTY_ID ) 99999 ) ;
102
+
103
+ value . Should ( ) . Be ( _textBox . AccessibilityObject . GetPropertyValue ( ( UIA_PROPERTY_ID ) 99999 ) ) ;
104
+ }
105
+
106
+ [ WinFormsFact ]
107
+ public void ToolStripHostedControlAccessibleObject_FragmentNavigate_Delegates_To_Host_For_Parent ( )
108
+ {
109
+ // Ensure the host is fully initialized and accessible
110
+ _toolStrip . CreateControl ( ) ;
111
+ ToolStripControlHost . ToolStripHostedControlAccessibleObject accessibleObject =
112
+ new ( _textBox , _host ) ;
113
+ IRawElementProviderFragment . Interface expected =
114
+ _host . AccessibilityObject . FragmentNavigate ( NavigateDirection . NavigateDirection_Parent ) ;
115
+ IRawElementProviderFragment . Interface actual =
116
+ accessibleObject . FragmentNavigate ( NavigateDirection . NavigateDirection_Parent ) ;
117
+
118
+ actual . Should ( ) . Be ( expected ) ;
119
+ }
120
+
121
+ [ WinFormsFact ]
122
+ public void ToolStripHostedControlAccessibleObject_FragmentNavigate_FallsBack_ToBase_For_OtherDirections ( )
123
+ {
124
+ ToolStripControlHost . ToolStripHostedControlAccessibleObject accessibleObject =
125
+ new ( _textBox , null ) ;
126
+
127
+ // Use a direction not handled by the switch, e.g. FirstChild
128
+ IRawElementProviderFragment . Interface expected =
129
+ _textBox . AccessibilityObject . FragmentNavigate ( NavigateDirection . NavigateDirection_FirstChild ) ;
130
+ IRawElementProviderFragment . Interface actual =
131
+ accessibleObject . FragmentNavigate ( NavigateDirection . NavigateDirection_FirstChild ) ;
132
+
133
+ actual . Should ( ) . Be ( expected ) ;
134
+ }
135
+
136
+ [ WinFormsFact ]
137
+ public void ToolStripHostedControlAccessibleObject_IsPatternSupported_ValuePatternId_Returns_True ( )
138
+ {
139
+ ToolStripControlHost . ToolStripHostedControlAccessibleObject accessibleObject =
140
+ new ( _textBox , null ) ;
141
+ bool result = accessibleObject . IsPatternSupported ( UIA_PATTERN_ID . UIA_ValuePatternId ) ;
142
+
143
+ result . Should ( ) . BeTrue ( ) ;
144
+ }
145
+
146
+ [ WinFormsFact ]
147
+ public void ToolStripHostedControlAccessibleObject_IsPatternSupported_UnknownPatternId_FallsBack_ToBase ( )
148
+ {
149
+ ToolStripControlHost . ToolStripHostedControlAccessibleObject accessibleObject =
150
+ new ( _textBox , null ) ;
151
+ bool expected = _textBox . AccessibilityObject . IsPatternSupported ( ( UIA_PATTERN_ID ) 99999 ) ;
152
+ bool actual = accessibleObject . IsPatternSupported ( ( UIA_PATTERN_ID ) 99999 ) ;
27
153
28
- Assert . True ( GetIsOffscreenPropertyValue ( item . AccessibilityObject ) ) ;
29
- Assert . True ( GetIsOffscreenPropertyValue ( item . Control . AccessibilityObject ) ) ;
154
+ actual . Should ( ) . Be ( expected ) ;
30
155
}
31
156
32
157
private bool GetIsOffscreenPropertyValue ( AccessibleObject accessibleObject ) =>
0 commit comments