@ -511,11 +511,39 @@ namespace Avalonia.Controls.UnitTests
( target as IClickableControl ) . RaiseClick ( ) ;
( target as IClickableControl ) . RaiseClick ( ) ;
}
}
[Fact]
void Should_Not_Fire_Click_Event_On_Space_Key_When_It_Is_Not_Focus ( )
{
using ( UnitTestApplication . Start ( TestServices . StyledWindow ) )
{
var raised = 0 ;
var target = new TextBox ( ) ;
var button = new Button ( )
{
Content = target ,
} ;
var window = new Window { Content = button } ;
window . Show ( ) ;
button . Click + = ( s , e ) = > + + raised ;
target . Focus ( ) ;
target . RaiseEvent ( CreateKeyDownEvent ( Key . Space ) ) ;
target . RaiseEvent ( CreateKeyUpEvent ( Key . Space ) ) ;
Assert . Equal ( 0 , raised ) ;
}
}
private KeyEventArgs CreateKeyDownEvent ( Key key , Interactive source = null )
private KeyEventArgs CreateKeyDownEvent ( Key key , Interactive source = null )
{
{
return new KeyEventArgs { RoutedEvent = InputElement . KeyDownEvent , Key = key , Source = source } ;
return new KeyEventArgs { RoutedEvent = InputElement . KeyDownEvent , Key = key , Source = source } ;
}
}
private KeyEventArgs CreateKeyUpEvent ( Key key , Interactive source = null )
{
return new KeyEventArgs { RoutedEvent = InputElement . KeyUpEvent , Key = key , Source = source } ;
}
private void RaisePointerPressed ( Button button , int clickCount , MouseButton mouseButton , Point position )
private void RaisePointerPressed ( Button button , int clickCount , MouseButton mouseButton , Point position )
{
{
_ helper . Down ( button , mouseButton , position , clickCount : clickCount ) ;
_ helper . Down ( button , mouseButton , position , clickCount : clickCount ) ;