summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44096.cs
blob: a86a625de89b15cba591cb1ec522144cadf29ac0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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)]
	[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;
		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";
		const string RelativeLayout = "relativeLayout";

		protected override void Init()
		{
			var result = new Label
			{
				Text = Original
			};

			var grid = new Grid
			{
				IsEnabled = true,
				WidthRequest = 250,
				HeightRequest = 50,
				AutomationId = Grid
			};
			AddTapGesture(result, grid);

			var contentView = new ContentView
			{
				IsEnabled = true,
				WidthRequest = 250,
				HeightRequest = 50,
				AutomationId = ContentView
			};
			AddTapGesture(result, contentView);

			var stackLayout = new StackLayout
			{
				IsEnabled = true,
				WidthRequest = 250,
				HeightRequest = 50,
				AutomationId = StackLayout
			};
			AddTapGesture(result, stackLayout);

			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;
						relativeLayout.BackgroundColor = Color.Green;
					}
					else
					{
						grid.BackgroundColor = Color.Default;
						contentView.BackgroundColor = Color.Default;
						stackLayout.BackgroundColor = Color.Default;
						relativeLayout.BackgroundColor = Color.Default;
					}

					_flag = !_flag;
				}),
				AutomationId = ToggleColor
			};

			var disabled = new Button
			{
				Text = "Toggle IsEnabled",
				Command = new Command(() =>
				{
					grid.IsEnabled = false;
					contentView.IsEnabled = false;
					stackLayout.IsEnabled = false;
					relativeLayout.IsEnabled = false;

					result.Text = Original;
				}),
				AutomationId = ToggleIsEnabled
			};

			var parent = new StackLayout
			{
				Spacing = 10,
				Orientation = StackOrientation.Vertical,
				HorizontalOptions = LayoutOptions.Center,
				VerticalOptions = LayoutOptions.Center,
				Children =
				{
					color,
					disabled,
					result,
					grid,
					contentView,
					stackLayout,
					relativeLayout
				}
			};

			Content = parent;
		}

		void AddTapGesture(Label result, View view)
		{
			var tapGestureRecognizer = new TapGestureRecognizer
			{
				Command = new Command(() =>
				{
					result.Text = Child;
				})
			};
			view.GestureRecognizers.Add(tapGestureRecognizer);
		}

#if UITEST

		[Test]
		public void TestGrid()
		{
			TestControl(Grid);
		}

		[Test]
		public void TestContentView()
		{
			TestControl(ContentView);
		}

		[Test]
		public void TestStackLayout()
		{
			TestControl(StackLayout);
		}

		[Test]
		public void TestRelativeLayout()
		{
			TestControl(RelativeLayout);
		}

		void TestControl(string control)
		{
			RunningApp.WaitForElement(q => q.Marked(control));
			RunningApp.Tap(q => q.Marked(control));
			RunningApp.WaitForElement(q => q.Marked(Child));

			RunningApp.WaitForElement(q => q.Marked(ToggleColor));
			RunningApp.Tap(q => q.Marked(ToggleColor));

			RunningApp.WaitForElement(q => q.Marked(control));
			RunningApp.Tap(q => q.Marked(control));
			RunningApp.WaitForElement(q => q.Marked(Child));

			RunningApp.WaitForElement(q => q.Marked(ToggleIsEnabled));
			RunningApp.Tap(q => q.Marked(ToggleIsEnabled));

			RunningApp.WaitForElement(q => q.Marked(control));
			RunningApp.Tap(q => q.Marked(control));
			RunningApp.WaitForElement(q => q.Marked(Original));

			RunningApp.WaitForElement(q => q.Marked(ToggleColor));
			RunningApp.Tap(q => q.Marked(ToggleColor));

			RunningApp.WaitForElement(q => q.Marked(control));
			RunningApp.Tap(q => q.Marked(control));
			RunningApp.WaitForElement(q => q.Marked(Original));
		}
#endif
	}
}