summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla52419.cs
blob: 4776b73a28c91ee7eb747c78c03402e84e9be2df (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
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.Bugzilla, 52419, "[A] OnAppearing called for previous pages in a tab's navigation when switching active tabs", PlatformAffected.Android)]
	public class Bugzilla52419 : TestTabbedPage
	{
		protected override void Init()
		{
			var nav1 = new NavigationPage { Title = "Tab Page 1" };
			nav1.PushAsync(new Bugzilla52419Page1());
			var nav2 = new NavigationPage { Title = "Tab Page 2" };
			nav2.PushAsync(new Bugzilla52419Page2());
			Children.Add(nav1);
			Children.Add(nav2);
		}

#if UITEST

#if __ANDROID__
		[Test]
		public void Bugzilla52419Test()
		{
			RunningApp.WaitForElement(q => q.Marked("Push new page"));
			RunningApp.Tap(q => q.Marked("Push new page"));
			RunningApp.WaitForElement(q => q.Marked("Push new page"));
			RunningApp.Tap(q => q.Marked("Push new page"));
			RunningApp.WaitForElement(q => q.Marked("Push new page"));
			RunningApp.Tap(q => q.Marked("Push new page"));
			RunningApp.Tap(q => q.Marked("Tab Page 2"));
			RunningApp.Tap(q => q.Marked("Tab Page 1"));
			RunningApp.Tap(q => q.Marked("Tab Page 2"));
			RunningApp.Tap(q => q.Marked("Tab Page 1"));
			RunningApp.Back();
			RunningApp.WaitForElement(q => q.Marked("AppearanceLabel"));
			var label = RunningApp.Query(q => q.Marked("AppearanceLabel"))[0];
			Assert.AreEqual("Times Appeared: 2", label.Text);
		}
#endif

#endif
	}

	class Bugzilla52419Page1 : ContentPage
	{
		public Label _timesAppeared { get; set; }
		int _count;

		string _guid = Guid.NewGuid().ToString();
		public Bugzilla52419Page1()
		{
			_timesAppeared = new Label
			{
				Text = "Times Appeared: " + _count.ToString(),
				AutomationId = "AppearanceLabel"
			};
			Content = new StackLayout
			{
				Children =
					{
						new Label
						{
							Text = "Page Guid: " + _guid
						},
						_timesAppeared,
						new Label
						{
							Text = "Click the button a couple times, switch to the second tab, and then back to the first. The Appearing event (which increase the counter) should only occur for the visible first tab."
						},
						new Button
						{
							Text = "Push new page",
							Command = new Command(() => Navigation.PushAsync(new Bugzilla52419Page1()))
						}
					}
			};
			Appearing += OnAppearing;
		}

		void OnAppearing(object sender, EventArgs e)
		{
			_count++;
			_timesAppeared.Text = "Times Appeared: " + _count.ToString();
		}
	}

	class Bugzilla52419Page2 : ContentPage
	{
		public Bugzilla52419Page2()
		{
			Title = "Tab Page 2";
			Content = new StackLayout
			{
				Children =
				{
					new Label
					{
						Text = "Other content"
					}
				}
			};
		}
	}
}