maui-linux/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issu.../Bugzilla44096.cs

203 строки
4.4 KiB
C#
Исходник Обычный вид История

using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.IsEnabled)]
#endif
[Preserve(AllMembers = true)]
2017-09-06 02:17:32 +03:00
[Issue(IssueTracker.Bugzilla, 44096, "Grid, StackLayout, and ContentView still participate in hit testing on "
+ "Android after IsEnabled is set to false", PlatformAffected.Android)]
public class Bugzilla44096 : TestContentPage
{
bool _flag;
2017-09-06 01:18:05 +03:00
const string Child = "Child";
const string Original = "Original";
const string ToggleColor = "color";
const string ToggleIsEnabled = "disabled";
const string StackLayout = "stackLayout";
const string ContentView = "contentView";
const string Grid = "grid";
2017-09-06 01:23:28 +03:00
const string RelativeLayout = "relativeLayout";
protected override void Init()
{
var result = new Label
{
2017-09-06 01:18:05 +03:00
Text = Original
};
var grid = new Grid
{
IsEnabled = true,
WidthRequest = 250,
HeightRequest = 50,
2017-09-06 01:18:05 +03:00
AutomationId = Grid
};
AddTapGesture(result, grid);
var contentView = new ContentView
{
IsEnabled = true,
WidthRequest = 250,
HeightRequest = 50,
2017-09-06 01:18:05 +03:00
AutomationId = ContentView
};
AddTapGesture(result, contentView);
var stackLayout = new StackLayout
{
IsEnabled = true,
WidthRequest = 250,
HeightRequest = 50,
2017-09-06 01:18:05 +03:00
AutomationId = StackLayout
};
AddTapGesture(result, stackLayout);
2017-09-06 01:23:28 +03:00
var relativeLayout = new RelativeLayout
{
IsEnabled = true,
WidthRequest = 250,
HeightRequest = 50,
AutomationId = RelativeLayout
};
AddTapGesture(result, relativeLayout);
var color = new Button
{
Text = "Toggle colors",
Command = new Command(() =>
{
if (!_flag)
{
grid.BackgroundColor = Color.Red;
contentView.BackgroundColor = Color.Blue;
stackLayout.BackgroundColor = Color.Yellow;
2017-09-06 01:23:28 +03:00
relativeLayout.BackgroundColor = Color.Green;
}
else
{
grid.BackgroundColor = Color.Default;
contentView.BackgroundColor = Color.Default;
stackLayout.BackgroundColor = Color.Default;
2017-09-06 01:23:28 +03:00
relativeLayout.BackgroundColor = Color.Default;
}
_flag = !_flag;
}),
2017-09-06 01:18:05 +03:00
AutomationId = ToggleColor
};
var disabled = new Button
{
2017-09-06 01:18:05 +03:00
Text = "Toggle IsEnabled",
Command = new Command(() =>
{
grid.IsEnabled = false;
contentView.IsEnabled = false;
stackLayout.IsEnabled = false;
2017-09-06 01:23:28 +03:00
relativeLayout.IsEnabled = false;
2017-09-06 01:18:05 +03:00
result.Text = Original;
}),
2017-09-06 01:18:05 +03:00
AutomationId = ToggleIsEnabled
};
var parent = new StackLayout
{
Spacing = 10,
Orientation = StackOrientation.Vertical,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Children =
{
color,
disabled,
result,
grid,
contentView,
2017-09-06 01:23:28 +03:00
stackLayout,
relativeLayout
}
};
Content = parent;
}
void AddTapGesture(Label result, View view)
{
var tapGestureRecognizer = new TapGestureRecognizer
{
Command = new Command(() =>
{
2017-09-06 01:18:05 +03:00
result.Text = Child;
})
};
view.GestureRecognizers.Add(tapGestureRecognizer);
}
#if UITEST
2017-09-06 01:18:05 +03:00
[Test]
2017-09-06 01:18:05 +03:00
public void TestGrid()
{
2017-09-06 01:18:05 +03:00
TestControl(Grid);
}
2017-09-06 01:18:05 +03:00
[Test]
public void TestContentView()
{
TestControl(ContentView);
}
2017-09-06 01:18:05 +03:00
[Test]
public void TestStackLayout()
{
TestControl(StackLayout);
}
2017-09-06 01:23:28 +03:00
[Test]
public void TestRelativeLayout()
{
TestControl(RelativeLayout);
}
2017-09-06 01:18:05 +03:00
void TestControl(string control)
{
RunningApp.WaitForElement(q => q.Marked(control));
RunningApp.Tap(q => q.Marked(control));
RunningApp.WaitForElement(q => q.Marked(Child));
2017-09-06 01:18:05 +03:00
RunningApp.WaitForElement(q => q.Marked(ToggleColor));
RunningApp.Tap(q => q.Marked(ToggleColor));
2017-09-06 01:18:05 +03:00
RunningApp.WaitForElement(q => q.Marked(control));
RunningApp.Tap(q => q.Marked(control));
RunningApp.WaitForElement(q => q.Marked(Child));
2017-09-06 01:18:05 +03:00
RunningApp.WaitForElement(q => q.Marked(ToggleIsEnabled));
RunningApp.Tap(q => q.Marked(ToggleIsEnabled));
2017-09-06 01:18:05 +03:00
RunningApp.WaitForElement(q => q.Marked(control));
RunningApp.Tap(q => q.Marked(control));
RunningApp.WaitForElement(q => q.Marked(Original));
2017-09-06 01:18:05 +03:00
RunningApp.WaitForElement(q => q.Marked(ToggleColor));
RunningApp.Tap(q => q.Marked(ToggleColor));
2017-09-06 01:18:05 +03:00
RunningApp.WaitForElement(q => q.Marked(control));
RunningApp.Tap(q => q.Marked(control));
RunningApp.WaitForElement(q => q.Marked(Original));
}
#endif
}
}