File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed
tests/UnitTests/System/Windows/Forms Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -1970,7 +1970,14 @@ private bool WmSelChange()
1970
1970
if ( IsAccessibilityObjectCreated && SelectedTab ? . ParentInternal is TabControl )
1971
1971
{
1972
1972
SelectedTab . TabAccessibilityObject . RaiseAutomationEvent ( UiaCore . UIA . SelectionItem_ElementSelectedEventId ) ;
1973
- BeginInvoke ( ( MethodInvoker ) ( ( ) => SelectedTab . TabAccessibilityObject . RaiseAutomationEvent ( UiaCore . UIA . AutomationFocusChangedEventId ) ) ) ;
1973
+ BeginInvoke ( ( MethodInvoker ) ( ( ) =>
1974
+ {
1975
+ if ( IsAccessibilityObjectCreated && SelectedTab ? . ParentInternal is TabControl &&
1976
+ ! SelectedTab . IsDisposed && SelectedTab . TabAccessibilityObject is not null )
1977
+ {
1978
+ SelectedTab . TabAccessibilityObject . RaiseAutomationEvent ( UiaCore . UIA . AutomationFocusChangedEventId ) ;
1979
+ }
1980
+ } ) ) ;
1974
1981
}
1975
1982
}
1976
1983
else
Original file line number Diff line number Diff line change @@ -5704,6 +5704,40 @@ public void TabControl_Invokes_SetToolTip_IfExternalToolTipIsSet()
5704
5704
Assert . Equal ( text , actual ) ;
5705
5705
}
5706
5706
5707
+ [ WinFormsFact ]
5708
+ public void TabControl_WmSelChange_SelectedTabIsNull_DoesNotThrowException ( )
5709
+ {
5710
+ using Form form = new ( ) ;
5711
+ using TabControl control = new ( ) ;
5712
+ using TabPage page1 = new ( "text1" ) ;
5713
+ control . TabPages . Add ( page1 ) ;
5714
+ _ = control . AccessibilityObject ;
5715
+
5716
+ form . Controls . Add ( control ) ;
5717
+ form . Show ( ) ;
5718
+ control . SelectedIndex = 0 ;
5719
+
5720
+ Action act = ( ) => control . TestAccessor ( ) . Dynamic . WmSelChange ( ) ;
5721
+ try
5722
+ {
5723
+ act ( ) ;
5724
+ }
5725
+ catch ( Exception ex )
5726
+ {
5727
+ Assert . Fail ( $ "Expected no exception, but got: { ex } ") ;
5728
+ }
5729
+
5730
+ control . TabPages . Clear ( ) ;
5731
+
5732
+ var exception = Record . Exception ( ( ) =>
5733
+ {
5734
+ Application . DoEvents ( ) ;
5735
+ Thread . Sleep ( 100 ) ;
5736
+ } ) ;
5737
+
5738
+ Assert . Null ( exception ) ;
5739
+ }
5740
+
5707
5741
private class SubTabPage : TabPage
5708
5742
{
5709
5743
}
You can’t perform that action at this time.
0 commit comments