();
+ var deleteButton = app.FindElement(By.Id("delete"));
+ var incrementButton = app.FindElement(By.Id("increment"));
+ app.FindElement(By.TagName("input")).SendKeys(_apiServerFixture.RootUri.ToString());
+
+ // Ensure we're starting from a clean state
+ deleteButton.Click();
+ Assert.Equal("Reset completed", WaitAndGetResponseText());
+
+ // Observe that subsequent requests manage to preserve state via cookie
+ incrementButton.Click();
+ Assert.Equal("Counter value is 1", WaitAndGetResponseText());
+ incrementButton.Click();
+ Assert.Equal("Counter value is 2", WaitAndGetResponseText());
+
+ // Verify that attempting to delete a cookie actually works
+ deleteButton.Click();
+ Assert.Equal("Reset completed", WaitAndGetResponseText());
+ incrementButton.Click();
+ Assert.Equal("Counter value is 1", WaitAndGetResponseText());
+
+ string WaitAndGetResponseText()
+ {
+ new WebDriverWait(Browser, TimeSpan.FromSeconds(30)).Until(
+ driver => driver.FindElement(By.Id("response-text")) != null);
+ return app.FindElement(By.Id("response-text")).Text;
+ }
+ }
+
private void IssueRequest(string requestMethod, string relativeUri, string requestBody = null)
{
var targetUri = new Uri(_apiServerFixture.RootUri, relativeUri);
diff --git a/test/testapps/BasicTestApp/HttpClientTest/CookieCounterComponent.cshtml b/test/testapps/BasicTestApp/HttpClientTest/CookieCounterComponent.cshtml
new file mode 100644
index 0000000000..9efde52e6b
--- /dev/null
+++ b/test/testapps/BasicTestApp/HttpClientTest/CookieCounterComponent.cshtml
@@ -0,0 +1,38 @@
+@inject System.Net.Http.HttpClient Http
+
+Cookie counter
+The server increments the count by one on each request.
+TestServer base URL:
+
+
+
+@if (!requestInProgress)
+{
+ @responseText
+}
+
+@functions
+{
+ bool requestInProgress = false;
+ string testServerBaseUrl;
+ string responseText;
+
+ async void DeleteCookie()
+ {
+ await DoRequest("api/cookie/reset");
+ StateHasChanged();
+ }
+
+ async void GetAndIncrementCounter()
+ {
+ await DoRequest("api/cookie/increment");
+ StateHasChanged();
+ }
+
+ async Task DoRequest(string url)
+ {
+ requestInProgress = true;
+ responseText = await Http.GetStringAsync(testServerBaseUrl + url);
+ requestInProgress = false;
+ }
+}
diff --git a/test/testapps/BasicTestApp/Program.cs b/test/testapps/BasicTestApp/Program.cs
index c8b87d4968..39e5bc6d0d 100644
--- a/test/testapps/BasicTestApp/Program.cs
+++ b/test/testapps/BasicTestApp/Program.cs
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using Microsoft.AspNetCore.Blazor.Browser.Http;
using Microsoft.AspNetCore.Blazor.Browser.Interop;
using Microsoft.AspNetCore.Blazor.Browser.Rendering;
using Microsoft.AspNetCore.Blazor.Components;
@@ -12,6 +13,10 @@ namespace BasicTestApp
{
static void Main(string[] args)
{
+ // Needed because the test server runs on a different port than the client app,
+ // and we want to test sending/receiving cookies undering this config
+ BrowserHttpMessageHandler.DefaultCredentials = FetchCredentialsOption.Include;
+
// Signal to tests that we're ready
RegisteredFunction.Invoke