@@ -805,6 +805,7 @@ public async Task LocationChangingHandlers_CannotCancelTheNavigationAsynchronous
805
805
// Arrange
806
806
var baseUri = "scheme://host/" ;
807
807
var navigationManager = new TestNavigationManager ( baseUri ) ;
808
+ var blockPreventNavigationTcs = new TaskCompletionSource ( ) ;
808
809
var navigationPreventedTcs = new TaskCompletionSource ( ) ;
809
810
var completeHandlerTcs = new TaskCompletionSource ( ) ;
810
811
LocationChangingContext currentContext = null ;
@@ -814,10 +815,14 @@ public async Task LocationChangingHandlers_CannotCancelTheNavigationAsynchronous
814
815
// Act/Assert
815
816
var navigation1 = navigationManager . RunNotifyLocationChangingAsync ( $ "{ baseUri } /subdir1", null , false ) ;
816
817
818
+ // Unblock the location changing handler to let it cancel the navigation, now that we know the
819
+ // navigation wasn't canceled synchronously
820
+ blockPreventNavigationTcs . SetResult ( ) ;
821
+
817
822
// Wait for the navigation to be prevented asynchronously
818
823
await navigationPreventedTcs . Task . WaitAsync ( Timeout ) ;
819
824
820
- // Assert that we have prevented the navigation but the cancellation token has requested cancellation
825
+ // Assert that we have prevented the navigation but the cancellation token has not requested cancellation
821
826
Assert . True ( currentContext . DidPreventNavigation ) ;
822
827
Assert . False ( currentContext . CancellationToken . IsCancellationRequested ) ;
823
828
@@ -835,7 +840,7 @@ async ValueTask HandleLocationChanging(LocationChangingContext context)
835
840
currentContext = context ;
836
841
837
842
// Force the navigation to be prevented asynchronously
838
- await Task . Yield ( ) ;
843
+ await blockPreventNavigationTcs . Task ;
839
844
840
845
context . PreventNavigation ( ) ;
841
846
navigationPreventedTcs . SetResult ( ) ;
0 commit comments