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

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

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve(AllMembers = true)]
	[Issue(IssueTracker.Bugzilla, 30353, "MasterDetailPage.IsPresentedChanged is not raised")]
	public class Bugzilla30353 : TestMasterDetailPage
	{
		protected override void Init()
		{
			var lbl = new Label
			{
				HorizontalOptions = LayoutOptions.CenterAndExpand,
				VerticalOptions = LayoutOptions.CenterAndExpand,
				Text = "Detail"
			};

#if !UITEST
			if (App.IOSVersion == 7 || Device.RuntimePlatform == Device.macOS)
			{
				lbl.Text = "Don't run";
			}
#endif

			var lblMaster = new Label
			{
				HorizontalOptions = LayoutOptions.CenterAndExpand,
				VerticalOptions = LayoutOptions.CenterAndExpand,
				Text = "Master"
			};
			var btn = new Button()
			{
				Text = "Toggle"
			};
			var btn1 = new Button()
			{
				Text = "Toggle"
			};

			btn.Clicked += (object sender, EventArgs e) => IsPresented = !IsPresented;
			btn1.Clicked += (object sender, EventArgs e) => IsPresented = !IsPresented;

			var stacklayout = new StackLayout();
			stacklayout.Children.Add(lbl);
			stacklayout.Children.Add(btn);

			var stacklayout1 = new StackLayout();
			stacklayout1.Children.Add(lblMaster);
			stacklayout1.Children.Add(btn1);

			Master = new ContentPage
			{
				Title = "IsPresentedChanged Test",
				BackgroundColor = Color.Green,
				Content = stacklayout1
			};
			Detail = new ContentPage
			{
				BackgroundColor = Color.Gray,
				Content = stacklayout
			};
			MasterBehavior = MasterBehavior.Popover;
			IsPresentedChanged += (s, e) =>
				lblMaster.Text = lbl.Text = string.Format("The Master is now {0}", IsPresented ? "visible" : "invisible");
		}

#if UITEST
		[Test]
		public void Bugzilla30353Test ()
		{
			var dontRun = RunningApp.Query (q => q.Marked ("Don't run"));
			if (dontRun.Length > 0)
			{
				return;	
			}
			RunningApp.SetOrientationPortrait ();
			RunningApp.Screenshot ("Portrait");
			RunningApp.Tap (q => q.Marked ("Toggle"));
			RunningApp.Screenshot ("Portrait Visible");
			RunningApp.WaitForElement (q => q.Marked ("The Master is now visible"));
			Back();
			RunningApp.Screenshot ("Portrait Invisible");
			RunningApp.WaitForElement (q => q.Marked ("The Master is now invisible"));
			RunningApp.SetOrientationLandscape ();
			RunningApp.Screenshot ("Landscape Invisible");
			RunningApp.WaitForElement (q => q.Marked ("The Master is now invisible"));
			RunningApp.Tap (q => q.Marked ("Toggle"));
			RunningApp.Screenshot ("Landscape Visible");
			RunningApp.WaitForElement (q => q.Marked ("The Master is now visible"));
			Back();
			RunningApp.Screenshot ("Landscape InVisible");
			RunningApp.WaitForElement (q => q.Marked ("The Master is now invisible"));
			RunningApp.SetOrientationPortrait ();
			RunningApp.Tap (q => q.Marked ("Toggle"));
			RunningApp.Screenshot ("Portrait Visible");
			RunningApp.WaitForElement (q => q.Marked ("The Master is now visible"));
			Back();
			RunningApp.Screenshot ("Portrait Invisible");
			RunningApp.WaitForElement (q => q.Marked ("The Master is now invisible"));
			RunningApp.SetOrientationLandscape ();
		}

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

		void Back()
		{
#if __IOS__
			RunningApp.Tap (q => q.Marked ("Toggle"));
#else
			RunningApp.Back();
#endif
		}
#endif
	}
}