summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla35132.cs
blob: 732c0a948a933b84e365750e88cb5e2f93a4c2d1 (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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
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, 35132, "Pages are not collected when using a Navigationpage (FormsApplicationActivity)")]
	public class Bugzilla35132 : TestNavigationPage
	{
		protected override void Init()
		{
			PushAsync(new RootPage());
		}

		[Preserve(AllMembers = true)]
		public class BugPage : ContentPage
		{
			public static int Livecount;
			public static int Pushedcount;

			public BugPage()
			{
				Interlocked.Increment(ref Livecount);

				Content = new StackLayout
				{
					Children =
					{
						new Label { Text =  Pushedcount < 2 ? "Testing..." : Livecount < 3 ? "Success" : "Failure" },
					}
				};

				Interlocked.Increment(ref Pushedcount);
			}

			~BugPage()
			{
				Debug.WriteLine(">>>>>>>> BugPage Finalized");
				Interlocked.Decrement(ref Livecount);
			}
		}

		[Preserve(AllMembers = true)]
		public class RootPage : ContentPage
		{
			public RootPage()
			{
				var button = new Button { Text = "Open" };
				button.Clicked += Button_Clicked;
				Content = button;
			}

			async void Button_Clicked(object sender, EventArgs e)
			{
				Debug.WriteLine(">>>>>>>> Invoking Garbage Collector");
				GC.Collect();
				GC.WaitForPendingFinalizers();

				await Navigation.PushAsync(new BugPage());
			}
		}

#if UITEST 
		[Test]
		public void PagesAreCollected()
		{
			RunningApp.WaitForElement (q => q.Marked ("Open"));
			RunningApp.Tap(q => q.Marked ("Open"));
			RunningApp.WaitForElement (q => q.Marked ("Testing..."));
			RunningApp.Back();
			RunningApp.WaitForElement (q => q.Marked ("Open"));
			RunningApp.Tap(q => q.Marked ("Open"));
			RunningApp.WaitForElement (q => q.Marked ("Testing..."));
			RunningApp.Back();
			RunningApp.WaitForElement (q => q.Marked ("Open"));
			RunningApp.Tap(q => q.Marked ("Open"));
			RunningApp.WaitForElement (q => q.Marked ("Success"));
		}
#endif
	}
}