Skip to content

Fix LocationChangingHandlers_CannotCancelTheNavigationAsynchronously_UntilReturning #54388

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

Merged
merged 1 commit into from
Mar 6, 2024
Merged
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
9 changes: 7 additions & 2 deletions src/Components/Components/test/NavigationManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ public async Task LocationChangingHandlers_CannotCancelTheNavigationAsynchronous
// Arrange
var baseUri = "scheme://host/";
var navigationManager = new TestNavigationManager(baseUri);
var blockPreventNavigationTcs = new TaskCompletionSource();
var navigationPreventedTcs = new TaskCompletionSource();
var completeHandlerTcs = new TaskCompletionSource();
LocationChangingContext currentContext = null;
Expand All @@ -814,10 +815,14 @@ public async Task LocationChangingHandlers_CannotCancelTheNavigationAsynchronous
// Act/Assert
var navigation1 = navigationManager.RunNotifyLocationChangingAsync($"{baseUri}/subdir1", null, false);

// Unblock the location changing handler to let it cancel the navigation, now that we know the
// navigation wasn't canceled synchronously
blockPreventNavigationTcs.SetResult();

// Wait for the navigation to be prevented asynchronously
await navigationPreventedTcs.Task.WaitAsync(Timeout);

// Assert that we have prevented the navigation but the cancellation token has requested cancellation
// Assert that we have prevented the navigation but the cancellation token has not requested cancellation
Assert.True(currentContext.DidPreventNavigation);
Assert.False(currentContext.CancellationToken.IsCancellationRequested);

Expand All @@ -835,7 +840,7 @@ async ValueTask HandleLocationChanging(LocationChangingContext context)
currentContext = context;

// Force the navigation to be prevented asynchronously
await Task.Yield();
await blockPreventNavigationTcs.Task;

context.PreventNavigation();
navigationPreventedTcs.SetResult();
Expand Down