summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla35472.cs
blob: 8dee013ee8b8c947effc2d384ddc3d90802759aa (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
using System;
using System.Diagnostics;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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

#endif

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 35472, "PopAsync during ScrollToAsync throws NullReferenceException")]
	public class Bugzilla35472 : TestNavigationPage
	{
		protected override void Init ()
		{
			// Set up the scroll viewer page
			var scrollToButton = new Button () { Text = "Now push this button" };

			var stackLayout = new StackLayout ();

			stackLayout.Children.Add (scrollToButton);

			for (int n = 0; n < 100; n++) {
				stackLayout.Children.Add (new Label () { Text = n.ToString () });
			}

			var scrollView = new ScrollView () {
				Content = stackLayout
			};

			var pageWithScrollView = new ContentPage () {
				Content = scrollView
			};

			// Set up the start page
			var goButton = new Button () {
				Text = "Push this button"
			};

			var successLabel = new Label () { Text = "The test has passed", IsVisible = false };

			var startPage = new ContentPage () {
				Content = new StackLayout {
					VerticalOptions = LayoutOptions.Center,
					Children = {
						goButton,
						successLabel
					}
				}
			};

			PushAsync (startPage);

			goButton.Clicked += (sender, args) => Navigation.PushAsync (pageWithScrollView);

			scrollToButton.Clicked += async (sender, args) => {
				try {
					// Deliberately not awaited so we can simulate a user navigating back
					scrollView.ScrollToAsync (0, 1500, true);
					await Navigation.PopAsync ();
					successLabel.IsVisible = true;
				} catch (Exception ex) {
					Debug.WriteLine (ex);
				}
			};
		}

#if UITEST
		[Test]
		[UiTest (typeof(NavigationPage))]
		public void Issue35472PopAsyncDuringAnimatedScrollToAsync ()
		{
			RunningApp.WaitForElement (q => q.Marked ("Push this button"));
			RunningApp.Tap (q => q.Marked ("Push this button"));

			RunningApp.WaitForElement (q => q.Marked ("Now push this button"));
			RunningApp.Screenshot ("On Page With ScrollView");
			RunningApp.Tap (q => q.Marked ("Now push this button"));

			RunningApp.WaitForElement ("The test has passed");
			RunningApp.Screenshot ("Success");
		}
#endif
	}
}