Skip to content
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
2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.server.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/Components/Web.JS/src/Boot.Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ async function boot(userOptions?: Partial<CircuitStartOptions>): Promise<void> {
}
};

window.addEventListener('beforeunload', cleanup, { capture: false, once: true });
window['Blazor'].disconnect = cleanup;

window.addEventListener('unload', cleanup, { capture: false, once: true });

window['Blazor'].reconnect = reconnect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public override async Task InitializeAsync()
protected override void InitializeAsyncCore()
{
Navigate(ServerPathBase, noReload: false);
Browser.MountTestComponent<CounterComponent>();
Browser.Equal("Current count: 0", () => Browser.FindElement(By.TagName("p")).Text);
Browser.MountTestComponent<GracefulTermination>();
Browser.Equal("Graceful Termination", () => Browser.FindElement(By.TagName("h1")).Text);

GracefulDisconnectCompletionSource = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
Sink = _serverFixture.Host.Services.GetRequiredService<TestSink>();
Expand Down Expand Up @@ -91,6 +91,45 @@ public async Task ClosingTheBrowserWindow_GracefullyDisconnects_WhenNavigatingAw
Assert.Contains((Extensions.Logging.LogLevel.Debug, "CircuitDisconnectedPermanently"), Messages);
}

[Fact]
public async Task NavigatingToProtocolLink_DoesNotGracefullyDisconnect_TheCurrentCircuit()
{
// Arrange & Act
var element = Browser.FindElement(By.Id("mailto-link"));
element.Click();
await Task.WhenAny(Task.Delay(10000), GracefulDisconnectCompletionSource.Task);

// Assert
Assert.DoesNotContain((Extensions.Logging.LogLevel.Debug, "CircuitTerminatedGracefully"), Messages);
Assert.DoesNotContain((Extensions.Logging.LogLevel.Debug, "CircuitDisconnectedPermanently"), Messages);
}

[Fact]
public async Task DownloadAction_DoesNotGracefullyDisconnect_TheCurrentCircuit()
{
// Arrange & Act
var element = Browser.FindElement(By.Id("download-link"));
element.Click();
await Task.WhenAny(Task.Delay(10000), GracefulDisconnectCompletionSource.Task);

// Assert
Assert.DoesNotContain((Extensions.Logging.LogLevel.Debug, "CircuitTerminatedGracefully"), Messages);
Assert.DoesNotContain((Extensions.Logging.LogLevel.Debug, "CircuitDisconnectedPermanently"), Messages);
}

[Fact]
public async Task DownloadHref_DoesNotGracefullyDisconnect_TheCurrentCircuit()
{
// Arrange & Act
var element = Browser.FindElement(By.Id("download-href"));
element.Click();
await Task.WhenAny(Task.Delay(10000), GracefulDisconnectCompletionSource.Task);

// Assert
Assert.DoesNotContain((Extensions.Logging.LogLevel.Debug, "CircuitTerminatedGracefully"), Messages);
Assert.DoesNotContain((Extensions.Logging.LogLevel.Debug, "CircuitDisconnectedPermanently"), Messages);
}

private void Log(WriteContext wc)
{
if ((Extensions.Logging.LogLevel.Debug, "CircuitTerminatedGracefully") == (wc.LogLevel, wc.EventId.Name))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@inject NavigationManager navigationManager

<h1>Graceful Termination</h1>

<a href="mailto:[email protected]" id="mailto-link">Send Email</a>
<a href="download" download id="download-href">Download Link</a>
<button @onclick="DownloadFile" id="download-link">Download File</button>

@code {
private void DownloadFile()
{
navigationManager.NavigateTo("/subdir/download", true);
}
}
1 change: 1 addition & 0 deletions src/Components/test/testassets/BasicTestApp/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<option value="BasicTestApp.FormsTest.InputFileComponent">Input file</option>
<option value="BasicTestApp.NavigateOnSubmit">Navigate to submit</option>
<option value="BasicTestApp.GlobalizationBindCases">Globalization Bind Cases</option>
<option value="BasicTestApp.GracefulTermination">Graceful Termination</option>
<option value="BasicTestApp.HierarchicalImportsTest.Subdir.ComponentUsingImports">Imports statement</option>
<option value="BasicTestApp.HtmlBlockChildContent">ChildContent HTML Block</option>
<option value="BasicTestApp.HtmlEncodedChildContent">ChildContent HTML Encoded Block</option>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.IO;
using System.Text;
using Microsoft.AspNetCore.Mvc;

namespace Components.TestServer.Controllers
{
public class DownloadController : Controller
{

[HttpGet("~/download")]
public FileStreamResult Download()
{
var buffer = Encoding.UTF8.GetBytes("The quick brown fox jumped over the lazy dog.");
var stream = new MemoryStream(buffer);

var result = new FileStreamResult(stream, "text/plain");
result.FileDownloadName = "test.txt";
return result;
}
}
}
1 change: 1 addition & 0 deletions src/Components/test/testassets/TestServer/ServerStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapControllerRoute("mvc", "{controller}/{action}");
endpoints.MapFallbackToPage("/_ServerHost");
});
});
Expand Down