forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix iOS so if you remove more than one page it's able to remove them …
…successfully (xamarin#14383) * Fix iOS Shell when removing multiple views * - ui tests and fix navigate args * - improve logic * Update ShellSection.cs * - update UI Tests
- Loading branch information
Showing
15 changed files
with
473 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue13916.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Text; | ||
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 | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 13916, "[iOS] iOS Application crashes on Back press when navigated to using GoToAsync with \"//\" or \"///\" route if 2 or more things are removed from the navigation stack", | ||
PlatformAffected.iOS)] | ||
#if UITEST | ||
[NUnit.Framework.Category(Core.UITests.UITestCategories.Github5000)] | ||
[NUnit.Framework.Category(UITestCategories.Shell)] | ||
#endif | ||
public class Issue13916 : TestShell | ||
{ | ||
static int pageCount = 1; | ||
protected override void Init() | ||
{ | ||
Routing.RegisterRoute(nameof(Issue13916SuccessPage), typeof(Issue13916SuccessPage)); | ||
|
||
AddFlyoutItem(CreateContentPage(), "Push Me"); | ||
} | ||
|
||
|
||
public class Issue13916SuccessPage : ContentPage | ||
{ | ||
public Issue13916SuccessPage() | ||
{ | ||
StackLayout layout = new StackLayout(); | ||
Label label = new Label() | ||
{ | ||
Text = "Success", | ||
AutomationId = "Success" | ||
}; | ||
layout.Children.Add(label); | ||
Content = layout; | ||
} | ||
} | ||
|
||
ContentPage CreateContentPage() | ||
{ | ||
StackLayout layout = new StackLayout(); | ||
Button button = new Button() | ||
{ | ||
Text = "Click Me", | ||
AutomationId = $"ClickMe{pageCount}", | ||
Command = new Command(async () => | ||
{ | ||
if (Navigation.NavigationStack.Count >= 3) | ||
{ | ||
await GoToAsync($"../../{nameof(Issue13916SuccessPage)}"); | ||
} | ||
else | ||
{ | ||
await Navigation.PushAsync(CreateContentPage()); | ||
} | ||
}) | ||
}; | ||
pageCount++; | ||
|
||
layout.Children.Add(button); | ||
|
||
return new ContentPage() | ||
{ | ||
Content = layout | ||
}; | ||
} | ||
|
||
#if UITEST | ||
[Test] | ||
public void RemovingMoreThanOneInnerPageAndThenPushingAPageCrashes() | ||
{ | ||
RunningApp.Tap("ClickMe1"); | ||
RunningApp.Tap("ClickMe2"); | ||
RunningApp.Tap("ClickMe3"); | ||
RunningApp.WaitForElement("Success"); | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
211 changes: 211 additions & 0 deletions
211
Xamarin.Forms.Core.UnitTests/ShellNavigatedArgsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Xamarin.Forms.Internals; | ||
|
||
namespace Xamarin.Forms.Core.UnitTests | ||
{ | ||
[TestFixture] | ||
public class ShellNavigatedArgsTests : ShellTestBase | ||
{ | ||
[TearDown] | ||
public override void TearDown() | ||
{ | ||
base.TearDown(); | ||
Routing.Clear(); | ||
} | ||
|
||
[Test] | ||
public async Task RemoveInnerPagesNavigatingArgs() | ||
{ | ||
Routing.RegisterRoute("SecondPageView", typeof(ContentPage)); | ||
Routing.RegisterRoute("ThirdPageView", typeof(ContentPage)); | ||
Routing.RegisterRoute("FourthPage", typeof(ContentPage)); | ||
|
||
var shell = new TestShell(CreateShellItem<FlyoutItem>(shellContentRoute: "HomePageView")); | ||
|
||
await shell.GoToAsync("//HomePageView/SecondPageView/ThirdPageView"); | ||
await shell.GoToAsync("//HomePageView/FourthPage"); | ||
|
||
shell.TestNavigatedArgs(ShellNavigationSource.Pop, "//HomePageView/SecondPageView/ThirdPageView", "//HomePageView/FourthPage"); | ||
Assert.AreEqual(3, shell.NavigatedCount); | ||
} | ||
|
||
[Test] | ||
public async Task PopToRootSetsCorrectNavigationSource() | ||
{ | ||
var shell = new TestShell(CreateShellItem()); | ||
await shell.Navigation.PushAsync(new ContentPage()); | ||
await shell.Navigation.PushAsync(new ContentPage()); | ||
await shell.Navigation.PopToRootAsync(); | ||
Assert.AreEqual(ShellNavigationSource.PopToRoot, shell.LastShellNavigatingEventArgs.Source); | ||
|
||
await shell.Navigation.PushAsync(new ContentPage()); | ||
await shell.Navigation.PushAsync(new ContentPage()); | ||
|
||
await shell.Navigation.PopAsync(); | ||
Assert.AreEqual(ShellNavigationSource.Pop, shell.LastShellNavigatingEventArgs.Source); | ||
|
||
await shell.Navigation.PopAsync(); | ||
Assert.AreEqual(ShellNavigationSource.PopToRoot, shell.LastShellNavigatingEventArgs.Source); | ||
} | ||
|
||
[Test] | ||
public async Task PushingSetsCorrectNavigationSource() | ||
{ | ||
var shell = new TestShell(CreateShellItem(shellItemRoute: "item1")); | ||
shell.RegisterPage(nameof(PushingSetsCorrectNavigationSource)); | ||
await shell.GoToAsync(nameof(PushingSetsCorrectNavigationSource)); | ||
|
||
shell.TestNavigatingArgs(ShellNavigationSource.Push, | ||
"//item1", $"{nameof(PushingSetsCorrectNavigationSource)}"); | ||
|
||
shell.TestNavigatedArgs(ShellNavigationSource.Push, | ||
"//item1", $"//item1/{nameof(PushingSetsCorrectNavigationSource)}"); | ||
} | ||
|
||
[Test] | ||
public async Task ChangingShellItemSetsCorrectNavigationSource() | ||
{ | ||
var shell = new TestShell( | ||
CreateShellItem(shellItemRoute: "item1"), | ||
CreateShellItem(shellItemRoute: "item2") | ||
); | ||
|
||
await shell.GoToAsync("//item2"); | ||
|
||
shell.TestNavigationArgs(ShellNavigationSource.ShellItemChanged, | ||
"//item1", "//item2"); | ||
} | ||
|
||
[Test] | ||
public async Task ChangingShellSectionSetsCorrectNavigationSource() | ||
{ | ||
var shell = new TestShell( | ||
CreateShellItem(shellSectionRoute: "item1") | ||
); | ||
|
||
shell.Items[0].Items.Add(CreateShellSection(shellContentRoute: "item2")); | ||
|
||
await shell.GoToAsync("//item2"); | ||
|
||
shell.TestNavigationArgs(ShellNavigationSource.ShellSectionChanged, | ||
"//item1", "//item2"); | ||
} | ||
|
||
[Test] | ||
public async Task PoppingSamePageSetsCorrectNavigationSource() | ||
{ | ||
Routing.RegisterRoute("detailspage", typeof(ContentPage)); | ||
var shell = new TestShell(CreateShellItem(shellItemRoute: "item1")); | ||
await shell.GoToAsync("detailspage/detailspage"); | ||
await shell.Navigation.PopAsync(); | ||
|
||
|
||
shell.TestNavigatingArgs(ShellNavigationSource.Pop, | ||
"//item1/detailspage/detailspage", $".."); | ||
|
||
shell.TestNavigatedArgs(ShellNavigationSource.Pop, | ||
"//item1/detailspage/detailspage", $"//item1/detailspage"); | ||
} | ||
|
||
[Test] | ||
public async Task ChangingShellContentSetsCorrectNavigationSource() | ||
{ | ||
var shell = new TestShell( | ||
CreateShellItem(shellContentRoute: "item1") | ||
); | ||
|
||
shell.Items[0].Items[0].Items.Add(CreateShellContent(shellContentRoute: "item2")); | ||
|
||
await shell.GoToAsync("//item2"); | ||
|
||
shell.TestNavigationArgs(ShellNavigationSource.ShellContentChanged, | ||
"//item1", "//item2"); | ||
} | ||
|
||
[Test] | ||
public async Task InsertPageSetsCorrectNavigationSource() | ||
{ | ||
Routing.RegisterRoute("pagemiddle", typeof(ContentPage)); | ||
Routing.RegisterRoute("page", typeof(ContentPage)); | ||
var shell = new TestShell( | ||
CreateShellItem(shellItemRoute: "item") | ||
); | ||
|
||
await shell.GoToAsync("//item/page"); | ||
await shell.GoToAsync("//item/pagemiddle/page"); | ||
|
||
shell.TestNavigationArgs(ShellNavigationSource.Insert, | ||
"//item/page", "//item/pagemiddle/page"); | ||
} | ||
|
||
|
||
[Test] | ||
public async Task InsertPageFromINavigationSetsCorrectNavigationSource() | ||
{ | ||
Routing.RegisterRoute("pagemiddle", typeof(ContentPage)); | ||
Routing.RegisterRoute("page", typeof(ContentPage)); | ||
var shell = new TestShell( | ||
CreateShellItem(shellItemRoute: "item") | ||
); | ||
|
||
await shell.GoToAsync("//item/page"); | ||
ContentPage contentPage = new ContentPage(); | ||
Routing.SetRoute(contentPage, "pagemiddle"); | ||
shell.Navigation.InsertPageBefore(contentPage, shell.Navigation.NavigationStack.Last()); | ||
|
||
shell.TestNavigationArgs(ShellNavigationSource.Insert, | ||
"//item/page", "//item/pagemiddle/page"); | ||
} | ||
|
||
|
||
[Test] | ||
public async Task RemovePageFromINavigationSetsCorrectNavigationSource() | ||
{ | ||
Routing.RegisterRoute("pagemiddle", typeof(ContentPage)); | ||
Routing.RegisterRoute("page", typeof(ContentPage)); | ||
var shell = new TestShell( | ||
CreateShellItem(shellItemRoute: "item") | ||
); | ||
|
||
await shell.GoToAsync("//item/pagemiddle/page"); | ||
shell.Navigation.RemovePage(shell.Navigation.NavigationStack[1]); | ||
|
||
shell.TestNavigationArgs(ShellNavigationSource.Remove, | ||
"//item/pagemiddle/page", "//item/page"); | ||
} | ||
|
||
[Test] | ||
public async Task RemovePageSetsCorrectNavigationSource() | ||
{ | ||
Routing.RegisterRoute("pagemiddle", typeof(ContentPage)); | ||
Routing.RegisterRoute("page", typeof(ContentPage)); | ||
var shell = new TestShell( | ||
CreateShellItem(shellItemRoute: "item") | ||
); | ||
|
||
await shell.GoToAsync("//item/pagemiddle/page"); | ||
await shell.GoToAsync("//item/page"); | ||
|
||
|
||
shell.TestNavigationArgs(ShellNavigationSource.Remove, | ||
"//item/pagemiddle/page", "//item/page"); | ||
} | ||
|
||
[Test] | ||
public async Task InitialNavigatingArgs() | ||
{ | ||
var shell = new TestShell( | ||
CreateShellItem(shellItemRoute: "item") | ||
); | ||
|
||
shell.TestNavigationArgs(ShellNavigationSource.ShellItemChanged, | ||
null, "//item"); | ||
} | ||
} | ||
} |
Oops, something went wrong.