summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla31602.cs
blob: 0603028afde6d75e09b302a742e10f400ae150ed (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
140
using System;
using Xamarin.Forms.CustomAttributes;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using Xamarin.Forms.Internals;

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

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
	[NUnit.Framework.Category(UITestCategories.MasterDetailPage)]
#endif

	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 31602, "not possible to programmatically open master page after iPad landscape -> portrait rotation, also tests 31664")]
	public class Bugzilla31602 : TestMasterDetailPage
	{
		protected override void Init ()
		{
			BindingContext = new MasterViewModel1 ();
			((MasterViewModel1)BindingContext).MasterPage = this;

			Master = new SidemenuPage ();
			Detail = new NavigationPage (new DetailPage1 (Master as SidemenuPage));
		}

		public class SidemenuPage : ContentPage
		{
			public SidemenuPage ()
			{
				Title = "Side";
				Icon = "menuIcon.png";
				var lbl = new Label { Text = "SideMenu" };
				var btn = new Button { Text = "Menu Opener"  };

				btn.SetBinding (Button.CommandProperty, new Binding ("OpenSideMenuCommand"));

				var stackpanel = new StackLayout { VerticalOptions = LayoutOptions.Center };

				stackpanel.Children.Add (btn);
				stackpanel.Children.Add (lbl);
				Content = stackpanel;
			}

			public void ChangeIcon() {
				Icon = "bank.png";
			}
		}

		public class DetailPage1 : ContentPage
		{
			SidemenuPage _sideMenu;

			public DetailPage1 (SidemenuPage menu)
			{
				_sideMenu = menu;
				Title = "Detail";
				var btns = new Button { Text = "Change Icon" };
				btns.Clicked += (object sender, EventArgs e) => {
					_sideMenu.ChangeIcon();
				};
				var btn = new Button { Text = "Sidemenu Opener"  };
				btn.SetBinding (Button.CommandProperty, new Binding ("OpenSideMenuCommand"));
				Content = new StackLayout { Children = { btns, btn} };
			}
		}

		[Preserve (AllMembers = true)]
		public class MasterViewModel1 : INotifyPropertyChanged
		{
			public MasterDetailPage MasterPage;

			public event PropertyChangedEventHandler PropertyChanged = delegate { };

			protected void OnPropertyChanged ([CallerMemberName] string propertyName = null)
			{
				if (PropertyChanged != null) {
					PropertyChanged (this, new PropertyChangedEventArgs (propertyName));
				}
			}

			bool _isMenuOpen;

			public bool IsMenuOpen {
				get { return _isMenuOpen; }
				private set {
					if (_isMenuOpen != value) {
						System.Diagnostics.Debug.WriteLine ("setting new sidemenu visibility flag to: " + value);
						_isMenuOpen = value;
						OnPropertyChanged ();
					}
				}
			}

			public ICommand OpenSideMenuCommand { get; private set; }

			public MasterViewModel1 ()
			{
				IsMenuOpen = true;
				OpenSideMenuCommand = new Command (OpenSideMenu);
			}

			void OpenSideMenu ()
			{
				IsMenuOpen = true;
				MasterPage.IsPresented = IsMenuOpen;
			}
		}

		#if UITEST
		[Test]
		public void Bugzilla31602Test ()
		{
			var appAs = RunningApp as iOSApp;
			if (appAs != null && appAs.Device.IsTablet) {
				RunningApp.Tap (q => q.Marked ("Sidemenu Opener"));
				RunningApp.WaitForElement (q => q.Marked ("SideMenu"));
				RunningApp.SetOrientationLandscape ();
				RunningApp.WaitForElement (q => q.Marked ("SideMenu"));
				RunningApp.SetOrientationPortrait ();
				RunningApp.WaitForNoElement (q => q.Marked ("SideMenu"));
				RunningApp.Tap (q => q.Marked ("Sidemenu Opener"));
				RunningApp.WaitForElement (q => q.Marked ("SideMenu"));
			}
		}

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