blob: ba27d2c123dd86bec6520e8e4d7cd34f496758d0 (
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
|
using System.Linq;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.Navigation)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.None, 1134, "Removing page during OnAppearing throws exception", PlatformAffected.Android)]
public class RemovePageOnAppearing : TestContentPage
{
const string Success = "Success";
protected override void Init()
{
Appearing += async (sender, args) =>
{
var nav = new NavigationPage(Root());
Application.Current.MainPage = nav;
await nav.PushAsync(Intermediate());
await nav.PushAsync(new PageWhichRemovesAnEarlierPageOnAppearing());
};
}
static ContentPage Root()
{
return new ContentPage { Content = new Label {Text = "Root"} };
}
static ContentPage Intermediate()
{
return new ContentPage { Content = new Label {Text = "Intermediate page"} };
}
[Preserve(AllMembers = true)]
class PageWhichRemovesAnEarlierPageOnAppearing : ContentPage
{
public PageWhichRemovesAnEarlierPageOnAppearing()
{
var instructions = new Label { Text = "If you can see this, the test has passed" };
Content = new StackLayout { Children = { instructions, new Label { Text = Success } } };
}
protected override void OnAppearing()
{
var toRemove = Navigation.NavigationStack.Skip(1).First();
// toRemove should be the IntermediatePage
Navigation.RemovePage(toRemove);
base.OnAppearing();
}
}
#if UITEST
[Test]
public void RemovePageOnAppearingDoesNotCrash()
{
RunningApp.WaitForElement(Success);
}
#endif
}
}
|