Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frame should throw on page exceptions #18983

Merged
merged 5 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,58 @@ public void When_NavigatingBetweenPages()
Assert.IsTrue(_navigateOrderTracker.FrameNavigated);
}

[TestMethod]
public async Task When_Exception_In_Page_Ctor()
{
var SUT = new Frame()
{
Width = 200,
Height = 200
};

#if HAS_UNO
bool navigationFailed = false;
SUT.NavigationFailed += (s, e) => navigationFailed = true;
#endif

TestServices.WindowHelper.WindowContent = SUT;
await TestServices.WindowHelper.WaitForLoaded(SUT);

var exception = Assert.ThrowsException<NotSupportedException>(() => SUT.Navigate(typeof(ExceptionInCtorPage)));
Assert.AreEqual("Crashed", exception.Message);
#if HAS_UNO
if (FeatureConfiguration.Frame.UseWinUIBehavior)
{
// This is only valid with WinUI Frame behavior
Assert.IsFalse(navigationFailed);
}
#endif
}

[TestMethod]
public async Task When_Exception_In_OnNavigatedTo()
{
var SUT = new Frame()
{
Width = 200,
Height = 200
};

bool navigationFailed = false;
SUT.NavigationFailed += (s, e) =>
{
navigationFailed = true;
e.Handled = true;
};

TestServices.WindowHelper.WindowContent = SUT;
await TestServices.WindowHelper.WaitForLoaded(SUT);

var exception = Assert.ThrowsException<NotSupportedException>(() => SUT.Navigate(typeof(ExceptionInOnNavigatedToPage)));
Assert.AreEqual("Crashed", exception.Message);
Assert.IsTrue(navigationFailed);
}

[TestCleanup]
public void Cleanup()
{
Expand Down Expand Up @@ -613,3 +665,28 @@ private async void FrameNavigateFirstPage_Loaded(object sender, Microsoft.UI.Xam
public partial class FrameNavigateSecondPage : Page
{
}

public partial class ExceptionInCtorPage : Page
{
public ExceptionInCtorPage()
{
throw new NotSupportedException("Crashed");
}
}

public partial class ExceptionInOnNavigatedToPage : Page
{
public ExceptionInOnNavigatedToPage()
{
}

protected
#if HAS_UNO
internal
#endif
override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
throw new NotSupportedException("Crashed");
}
}
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/Frame/Frame.legacy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private bool InnerNavigate(PageStackEntry entry, NavigationMode mode)
Application.Current.RaiseRecoverableUnhandledException(new InvalidOperationException("Navigation failed", exception));
}

return false;
throw;
}
finally
{
Expand Down
3 changes: 3 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Frame/Frame.partial.mux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ private bool NavigateWithTransitionInfoImpl(Type sourcePageType, object paramete
catch
{
pCanNavigate = false;
throw;
}
Cleanup:
;
Expand Down Expand Up @@ -585,6 +586,8 @@ private void ChangeContent(object oldObject, object newObject, object parameter,
{
Content = oldObject;
}

throw;
}
}

Expand Down
Loading