summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31366.cs
blob: e6a62ca9358b4801a74d09d4b5a4b446b8501649 (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
using System;
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using NUnit.Framework;
using Xamarin.UITest;

#endif

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 31366, "Pushing and then popping a page modally causes ArgumentOutOfRangeException",
		PlatformAffected.All)]
	public class Bugzilla31366 : TestNavigationPage
	{
		protected override void Init ()
		{
			var page1 = new ContentPage () { Title = "Page1" };

			var successLabel = new Label ();
			var startPopOnAppearing = new Button () { Text = "Start PopOnAppearing Test" };
			var startModalStack = new Button () { Text = "Start ModalStack Test" };

			page1.Content = new StackLayout () {
				Children = { startPopOnAppearing, startModalStack, successLabel }
			};

			var popOnAppearing = new ContentPage () {
				Title = "PopOnAppearing",
				Content = new StackLayout ()
			};

			popOnAppearing.Appearing += async (sender, args) => {
				await Task.Yield ();
			    await popOnAppearing.Navigation.PopModalAsync ();
			};

			startPopOnAppearing.Clicked += async (sender, args) => {
				successLabel.Text = string.Empty;

				await page1.Navigation.PushModalAsync (popOnAppearing);

				successLabel.Text = "If this is visible, the PopOnAppearing test has passed.";
			};

			startModalStack.Clicked += async (sender, args) => {
				successLabel.Text = string.Empty;

				var intermediatePage = new ContentPage () {
					Content = new StackLayout () {
						Children = {
							new Label () { Text = "If this is visible, the modal stack test has passed." }
						}
					}
				};

				await intermediatePage.Navigation.PushModalAsync (popOnAppearing);

				await page1.Navigation.PushModalAsync (intermediatePage);
			};

			PushAsync (page1);
		}


#if UITEST
		[Test]
		[UiTest (typeof (NavigationPage))]
		public void Issue31366PushingAndPoppingModallyCausesArgumentOutOfRangeException ()
		{
			RunningApp.Tap (q => q.Marked ("Start PopOnAppearing Test"));
			RunningApp.WaitForElement (q => q.Marked ("If this is visible, the PopOnAppearing test has passed."));
		}

		[Test]
		[UiTest (typeof (NavigationPage))]
		public void Issue31366PushingWithModalStackCausesIncorrectStackOrder ()
		{
			RunningApp.Tap (q => q.Marked ("Start ModalStack Test"));
			RunningApp.WaitForElement (q => q.Marked ("If this is visible, the modal stack test has passed."));
		}
#endif
	}
}