Skip to content

Commit

Permalink
fix: Frame should throw on page exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Dec 2, 2024
1 parent 4d9b3b3 commit 8967b8d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,39 @@ public async Task When_Exception_In_Page_Ctor()
Height = 200
};

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

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

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

[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(CrashOnlyPage)));
var exception = Assert.ThrowsException<NotSupportedException>(() => SUT.Navigate(typeof(ExceptionInOnNavigatedToPage)));
Assert.AreEqual("Crashed", exception.Message);
Assert.IsTrue(navigationFailed);
}

[TestCleanup]
Expand Down Expand Up @@ -630,10 +658,23 @@ public partial class FrameNavigateSecondPage : Page
{
}

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

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

protected internal override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
throw new NotSupportedException("Crashed");
}
}
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

0 comments on commit 8967b8d

Please sign in to comment.