summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla25979.cs
blob: 08b6f8a6d911f022184af69d64bcfe23b5ba47b2 (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
´╗┐using System;

using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 25979, "https://bugzilla.xamarin.com/show_bug.cgi?id=25979")]
	public class Bugzilla25979 : TestNavigationPage // or TestMasterDetailPage, etc ...
	{
		[Preserve (AllMembers = true)]
		internal sealed class MyPage : ContentPage
		{
			public MyPage()
			{
				Title = "Page 1";
				AutomationId = "PageOneId";

				var b = new Button {
					AutomationId = "PageOneButtonId",
					Text = "Next"
				};
				b.Clicked += async (sender, e) => {
					await Navigation.PushAsync (new MyPage2());
				};
				
				Content = new StackLayout { 
					BackgroundColor = Color.Red,
					Children = {
						new Label { Text = "Page 1", FontSize=Device.GetNamedSize(NamedSize.Large, typeof(Label)) },
						b
					}
				};
			}
		}

		[Preserve (AllMembers = true)]
		internal sealed class MyPage2 : ContentPage
		{
			public MyPage2()
			{
				Title = "Page 2";
				AutomationId = "PageTwoId";

				var b = new Button {
					AutomationId = "PageTwoButtonId",
					Text = "Next"
				};
				b.Clicked += async (sender, e) => {
					await Navigation.PushAsync (new MyPage3());
					Navigation.NavigationStack[0].BindingContext = null;
					Navigation.RemovePage(Navigation.NavigationStack[0]);
				};
				
				Content = new StackLayout { 
					BackgroundColor = Color.Red,
					Children = {
						new Label { Text = "Page 2", FontSize=Device.GetNamedSize(NamedSize.Large, typeof(Label)) }, 
						b
					}
				};
			}

			protected override void OnAppearing ()
			{
				base.OnAppearing();
				Navigation.NavigationStack[0].BindingContext = null;
				Navigation.RemovePage(Navigation.NavigationStack[0]);
			}
		}

		[Preserve (AllMembers = true)]
		internal sealed class MyPage3 : ContentPage
		{
			public MyPage3 ()
			{
				AutomationId = "PageThreeId";
				Title = "PageThreeId";

				var label = new Label { Text = "Page 3" };

				Content = new StackLayout {
					Children = {
						label,
						new Button { 
							AutomationId = "PopButton",
							Text = "Try to Pop",
							Command = new Command(
								async() => {
									await Navigation.PopAsync();
									label.Text = "PopAttempted";
								}
							)}
						}
				};
			}
		}

		protected override void Init ()
		{
			// Initialize ui here instead of ctor
			Navigation.PushAsync (new MyPage () { Title="Navigation Stack" });
		}

#if UITEST
		[Test]
		public void Bugzilla25979Test ()
		{
			RunningApp.WaitForElement (q => q.Marked ("PageOneId"));
			RunningApp.Screenshot ("At page one");
			RunningApp.WaitForElement (q => q.Marked ("PageOneButtonId"));
			RunningApp.Tap (q => q.Marked ("PageOneButtonId"));
#if __MACOS__
			System.Threading.Thread.Sleep(2000);
#endif

			RunningApp.WaitForElement (q => q.Marked ("PageTwoId"));
			RunningApp.Screenshot ("At page two - I didn't crash");
			RunningApp.WaitForElement (q => q.Marked ("PageTwoButtonId"));
			RunningApp.Tap (q => q.Marked ("PageTwoButtonId"));
#if __MACOS__
			System.Threading.Thread.Sleep(2000);
#endif

			RunningApp.WaitForElement (q => q.Marked ("PageThreeId"));
			RunningApp.Screenshot ("At page three - I didn't crash");

			RunningApp.WaitForElement (q => q.Marked ("PopButton"));
			RunningApp.Tap (q => q.Marked ("PopButton"));
			RunningApp.WaitForElement (q => q.Marked ("PopAttempted"));
		}
#endif
	}
}