diff --git a/src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs b/src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs index 7dfaf3523287..197976cb6334 100644 --- a/src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs +++ b/src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs @@ -31,7 +31,7 @@ public EnhancedNavigationTest( // One of the tests here makes use of the streaming rendering page, which uses global state // so we can't run at the same time as other such tests public override Task InitializeAsync() - => InitializeAsync(BrowserFixture.StreamingContext); + => InitializeAsync(BrowserFixture.StreamingContext, supportEnhancedNavigationSuppression: true); [Fact] public void CanNavigateToAnotherPageWhilePreservingCommonDOMElements() @@ -677,11 +677,10 @@ public void CanUpdateHrefOnLinkTagWithIntegrity() } [Theory] - [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/60875")] - // [InlineData(false, false, false)] // https://github.com/dotnet/aspnetcore/issues/60875 + [InlineData(false, false, false)] [InlineData(false, true, false)] [InlineData(true, true, false)] - // [InlineData(true, false, false)] // https://github.com/dotnet/aspnetcore/issues/60875 + [InlineData(true, false, false)] // [InlineData(false, false, true)] programmatic navigation doesn't work without enhanced navigation [InlineData(false, true, true)] [InlineData(true, true, true)] @@ -692,8 +691,8 @@ public void EnhancedNavigationScrollBehavesSameAsBrowserOnNavigation(bool enable // or to the beginning of a fragment, regardless of the previous scroll position string landingPageSuffix = enableStreaming ? "" : "-no-streaming"; string buttonKeyword = programmaticNavigation ? "-programmatic" : ""; - Navigate($"{ServerPathBase}/nav/scroll-test{landingPageSuffix}"); EnhancedNavigationTestUtil.SuppressEnhancedNavigation(this, shouldSuppress: !useEnhancedNavigation, skipNavigation: true); + Navigate($"{ServerPathBase}/nav/scroll-test{landingPageSuffix}"); // "landing" page: scroll maximally down and go to "next" page - we should land at the top of that page AssertWeAreOnLandingPage(); @@ -732,10 +731,10 @@ public void EnhancedNavigationScrollBehavesSameAsBrowserOnNavigation(bool enable } [Theory] - // [InlineData(false, false, false)] // https://github.com/dotnet/aspnetcore/issues/60875 + [InlineData(false, false, false)] [InlineData(false, true, false)] [InlineData(true, true, false)] - // [InlineData(true, false, false)] // https://github.com/dotnet/aspnetcore/issues/60875 + [InlineData(true, false, false)] // [InlineData(false, false, true)] programmatic navigation doesn't work without enhanced navigation [InlineData(false, true, true)] [InlineData(true, true, true)] @@ -745,8 +744,8 @@ public void EnhancedNavigationScrollBehavesSameAsBrowserOnBackwardsForwardsActio // This test checks if the scroll position is preserved after backwards/forwards action string landingPageSuffix = enableStreaming ? "" : "-no-streaming"; string buttonKeyword = programmaticNavigation ? "-programmatic" : ""; - Navigate($"{ServerPathBase}/nav/scroll-test{landingPageSuffix}"); EnhancedNavigationTestUtil.SuppressEnhancedNavigation(this, shouldSuppress: !useEnhancedNavigation, skipNavigation: true); + Navigate($"{ServerPathBase}/nav/scroll-test{landingPageSuffix}"); // "landing" page: scroll to pos1, navigate away AssertWeAreOnLandingPage(); @@ -831,6 +830,7 @@ private void AssertScrollPositionCorrect(bool useEnhancedNavigation, long previo private void AssertEnhancedNavigation(bool useEnhancedNavigation, IWebElement elementForStalenessCheck, int retryCount = 3, int delayBetweenRetriesMs = 1000) { bool enhancedNavigationDetected = false; + string logging = ""; for (int i = 0; i < retryCount; i++) { try @@ -841,15 +841,31 @@ private void AssertEnhancedNavigation(bool useEnhancedNavigation, IWebElement el } catch (XunitException) { + var logs = Browser.GetBrowserLogs(LogLevel.Warning); + logging += $"{string.Join(", ", logs.Select(l => l.Message))}\n"; + + var testId = ((IJavaScriptExecutor)Browser).ExecuteScript("return sessionStorage.getItem('test-id');"); + logging += $" testId: {testId}\n"; + if (testId is null) + { + continue; + } + var suppressKey = $"suppress-enhanced-navigation-{testId}"; + + var enhancedNavAttached = ((IJavaScriptExecutor)Browser).ExecuteScript("return sessionStorage.getItem('blazor-enhanced-nav-attached');"); + var suppressEnhancedNavigation = ((IJavaScriptExecutor)Browser).ExecuteScript($"return sessionStorage.getItem('{suppressKey}');"); + + logging += $" suppressKey: {suppressKey}\n"; + logging += $" {suppressKey}: {suppressEnhancedNavigation}\n"; // Maybe the check was done too early to change the DOM ref, retry } Thread.Sleep(delayBetweenRetriesMs); } - string expectedNavigation = useEnhancedNavigation ? "enhanced navigation" : "browser navigation"; + string expectedNavigation = useEnhancedNavigation ? "enhanced navigation" : "full page load"; string isStale = enhancedNavigationDetected ? "is not stale" : "is stale"; - var isNavigationSupressed = (string)((IJavaScriptExecutor)Browser).ExecuteScript("return sessionStorage.getItem('suppress-enhanced-navigation');"); - throw new Exception($"Expected to use {expectedNavigation} because 'suppress-enhanced-navigation' is set to {isNavigationSupressed} but the element from previous path {isStale}"); + var isNavigationSuppressed = (string)((IJavaScriptExecutor)Browser).ExecuteScript("return sessionStorage.getItem('suppress-enhanced-navigation');"); + throw new Exception($"Expected to use {expectedNavigation} because 'suppress-enhanced-navigation' is set to {isNavigationSuppressed} but the element from previous path {isStale}. logging={logging}"); } private void AssertWeAreOnLandingPage() diff --git a/src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTestUtil.cs b/src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTestUtil.cs index 799b915f8fdd..4b6b2524207a 100644 --- a/src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTestUtil.cs +++ b/src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTestUtil.cs @@ -18,15 +18,27 @@ public static void SuppressEnhancedNavigation(ServerTestBase browser.Exists(By.TagName("h1")).Text); } - ((IJavaScriptExecutor)browser).ExecuteScript("sessionStorage.setItem('suppress-enhanced-navigation', 'true')"); + ((IJavaScriptExecutor)browser).ExecuteScript($"sessionStorage.setItem('suppress-enhanced-navigation-{testId}', 'true')"); + + var suppressEnhancedNavigation = ((IJavaScriptExecutor)browser).ExecuteScript($"return sessionStorage.getItem('suppress-enhanced-navigation-{testId}');"); + Assert.True(suppressEnhancedNavigation is not null && (string)suppressEnhancedNavigation == "true", + "Expected 'suppress-enhanced-navigation' to be set in sessionStorage."); } } diff --git a/src/Components/test/E2ETest/ServerRenderingTests/FormHandlingTests/FormWithParentBindingContextTest.cs b/src/Components/test/E2ETest/ServerRenderingTests/FormHandlingTests/FormWithParentBindingContextTest.cs index b6948f9b766c..4a16ced80882 100644 --- a/src/Components/test/E2ETest/ServerRenderingTests/FormHandlingTests/FormWithParentBindingContextTest.cs +++ b/src/Components/test/E2ETest/ServerRenderingTests/FormHandlingTests/FormWithParentBindingContextTest.cs @@ -32,7 +32,7 @@ public override Task InitializeAsync() _tempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); Directory.CreateDirectory(_tempDirectory); - return InitializeAsync(BrowserFixture.StreamingContext); + return InitializeAsync(BrowserFixture.StreamingContext, supportEnhancedNavigationSuppression: true); } [Theory] diff --git a/src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs b/src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs index a6421eb94689..722bdce57676 100644 --- a/src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs +++ b/src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs @@ -285,6 +285,7 @@ public void NotFoundSetOnInitialization_ResponseStarted_SSR(bool hasReExecutionM [InlineData(false, true)] public void NotFoundSetOnInitialization_ResponseStarted_EnhancedNavigationDisabled_SSR(bool hasReExecutionMiddleware, bool hasCustomNotFoundPageSet) { + GrantTestId(); EnhancedNavigationTestUtil.SuppressEnhancedNavigation(this, true, skipNavigation: true); string reexecution = hasReExecutionMiddleware ? "/reexecution" : ""; string testUrl = $"{ServerPathBase}{reexecution}/set-not-found-ssr-streaming?useCustomNotFoundPage={hasCustomNotFoundPageSet}"; diff --git a/src/Components/test/E2ETest/ServerRenderingTests/StreamingRenderingTest.cs b/src/Components/test/E2ETest/ServerRenderingTests/StreamingRenderingTest.cs index 5fcf6d2a3813..5918173d145a 100644 --- a/src/Components/test/E2ETest/ServerRenderingTests/StreamingRenderingTest.cs +++ b/src/Components/test/E2ETest/ServerRenderingTests/StreamingRenderingTest.cs @@ -27,7 +27,7 @@ public StreamingRenderingTest( } public override Task InitializeAsync() - => InitializeAsync(BrowserFixture.StreamingContext); + => InitializeAsync(BrowserFixture.StreamingContext, supportEnhancedNavigationSuppression: true); [Fact] public async Task CanRenderNonstreamingPageWithoutInjectingStreamingMarkersOrHeaders() diff --git a/src/Components/test/E2ETest/Tests/StatePersistenceTest.cs b/src/Components/test/E2ETest/Tests/StatePersistenceTest.cs index a05fbfa05979..73ba3d6a4bb0 100644 --- a/src/Components/test/E2ETest/Tests/StatePersistenceTest.cs +++ b/src/Components/test/E2ETest/Tests/StatePersistenceTest.cs @@ -29,7 +29,7 @@ public StatePersistenceTest( // Separate contexts to ensure that caches and other state don't interfere across tests. public override Task InitializeAsync() - => InitializeAsync(BrowserFixture.StreamingContext + _nextStreamingIdContext++); + => InitializeAsync(BrowserFixture.StreamingContext + _nextStreamingIdContext++, supportEnhancedNavigationSuppression: true); // Validates that we can use persisted state across server, webassembly, and auto modes, with and without // streaming rendering. diff --git a/src/Components/test/testassets/Components.TestServer/RazorComponents/App.razor b/src/Components/test/testassets/Components.TestServer/RazorComponents/App.razor index 012dcc5547f8..7b8af1442eea 100644 --- a/src/Components/test/testassets/Components.TestServer/RazorComponents/App.razor +++ b/src/Components/test/testassets/Components.TestServer/RazorComponents/App.razor @@ -137,10 +137,10 @@ } const enableClassicInitializers = sessionStorage.getItem('enable-classic-initializers') === 'true'; - const suppressEnhancedNavigation = sessionStorage.getItem('suppress-enhanced-navigation') === 'true'; + const testId = sessionStorage.getItem('test-id'); + const suppressEnhancedNavigation = testId ? sessionStorage.getItem(`suppress-enhanced-navigation-${testId}`) === 'true' : false; const blockLoadBootResource = sessionStorage.getItem('block-load-boot-resource') === 'true'; const blockWebassemblySettings = sessionStorage.getItem('block-webassembly-settings') === 'true'; - sessionStorage.removeItem('suppress-enhanced-navigation'); sessionStorage.removeItem('block-load-boot-resource'); sessionStorage.removeItem('enable-classic-initializers'); sessionStorage.removeItem('block-webassembly-settings'); diff --git a/src/Components/test/testassets/Components.TestServer/RazorComponents/Root.razor b/src/Components/test/testassets/Components.TestServer/RazorComponents/Root.razor index 07a5daa32bde..098813212786 100644 --- a/src/Components/test/testassets/Components.TestServer/RazorComponents/Root.razor +++ b/src/Components/test/testassets/Components.TestServer/RazorComponents/Root.razor @@ -14,7 +14,8 @@