summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32801.cs
blob: 80028670daad42e7a9e807158201c284bcd2b9ab (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
using System;

using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 32801, "Memory Leak in TabbedPage + NavigationPage")]
	public class Bugzilla32801 : TestTabbedPage // or TestMasterDetailPage, etc ...
	{
		protected override void Init ()
		{
			Children.Add (new NavigationPage (new TestDemoPage (1)) { Title = "Tab", Icon = "bank.png" });
			Children.Add (new NavigationPage (new TestDemoPage (1)) { Title = "Tab 1", Icon = "bank.png" });

		}

		public class TestDemoPage : ContentPage
		{
			int _level = 0;

			public TestDemoPage (int level)
			{	
				_level = level;

				System.Diagnostics.Debug.WriteLine ("Page Level {0} : Created", _level);

				Title = string.Format ("Level {0}", level);

				var lblStack = new Label ();

				var buttonAdd = new Button {
					Text = "Add Level",
					AutomationId = "btnAdd",
					BackgroundColor = Color.Aqua
				};

				buttonAdd.Clicked += (sender, e) => Navigation.PushAsync (new TestDemoPage (_level + 1));

				var buttonStack = new Button {
					Text = "Show Navigation Stack",
					AutomationId = "btnStack",
					BackgroundColor = Color.Aqua
				};

				buttonStack.Clicked += (object sender, EventArgs e) => {
					lblStack.Text = "Stack " + Navigation.NavigationStack.Count.ToString ();
					System.Diagnostics.Debug.WriteLine ("------------------------------------------------------------");
					foreach (TestDemoPage page in Navigation.NavigationStack)
						System.Diagnostics.Debug.WriteLine ("Items On Navigation Stack =====> Level {0}", page._level);
					System.Diagnostics.Debug.WriteLine ("------------------------------------------------------------");
				};

				Content = new StackLayout {
					Padding = new Thickness (20.0),
					Spacing = 20.0,
					Children = {
						buttonAdd, buttonStack, lblStack
					}
				};
			}

			~TestDemoPage ()
			{
				System.Diagnostics.Debug.WriteLine ("Page Level {0} : Destroyed", _level);
			}
		}

		#if UITEST && __IOS__
		[Test]
		public void Bugzilla32801Test ()
		{
			RunningApp.Tap (c => c.Marked ("btnAdd"));
			RunningApp.Tap (c => c.Marked ("btnAdd"));
			RunningApp.Tap (c => c.Marked ("btnStack"));
			RunningApp.WaitForElement (c => c.Marked ("Stack 3"));
			RunningApp.Tap (c => c.Marked ("Tab"));
			RunningApp.Tap (c => c.Marked ("btnStack"));
			RunningApp.WaitForElement (c => c.Marked ("Stack 1"));
		}

		[TearDown]
		public void TearDown() 
		{
			RunningApp.SetOrientationPortrait ();
		}
#endif
	}
}