Skip to content

Commit c5bcd68

Browse files
Fix wasm caching on localhost and various E2E test issues (#25689)
* Fix caching of WASM resources on localhost * Fix test server startup * Add missing server variant of VirtualizationTest * Make test namespaces consistent * Fix VirtualizationTest cases * Update BootResourceCachingTest
1 parent 6469251 commit c5bcd68

File tree

7 files changed

+21
-15
lines changed

7 files changed

+21
-15
lines changed

src/Components/Web.JS/dist/Release/blazor.webassembly.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/src/Platform/WebAssemblyResourceLoader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ async function getCacheToUseIfEnabled(bootConfig: BootJsonData): Promise<Cache |
165165
return null;
166166
}
167167

168-
// cache integrity is compromised if the first request has been served over http
168+
// cache integrity is compromised if the first request has been served over http (except localhost)
169169
// in this case, we want to disable caching and integrity validation
170-
if (document.location.protocol !== 'https:') {
170+
if (window.isSecureContext === false) {
171171
return null;
172172
}
173173

src/Components/test/E2ETest/ServerExecutionTests/TestSubclasses.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,12 @@ public ServerInputFileTest(BrowserFixture browserFixture, ToggleExecutionModeSer
8383
{
8484
}
8585
}
86+
87+
public class ServerVirtualizationTest : VirtualizationTest
88+
{
89+
public ServerVirtualizationTest(BrowserFixture browserFixture, ToggleExecutionModeServerFixture<Program> serverFixture, ITestOutputHelper output)
90+
: base(browserFixture, serverFixture.WithServerExecution(), output)
91+
{
92+
}
93+
}
8694
}

src/Components/test/E2ETest/Tests/BootResourceCachingTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ public void IncrementallyUpdatesCache()
7171
Navigate("/");
7272
WaitUntilLoaded();
7373
var cacheEntryUrls1 = GetCacheEntryUrls();
74-
var cacheEntryForMsCorLib = cacheEntryUrls1.Single(url => url.Contains("/mscorlib.dll"));
74+
var cacheEntryForComponentsDll = cacheEntryUrls1.Single(url => url.Contains("/Microsoft.AspNetCore.Components.dll"));
7575
var cacheEntryForDotNetWasm = cacheEntryUrls1.Single(url => url.Contains("/dotnet.wasm"));
7676
var cacheEntryForDotNetWasmWithChangedHash = cacheEntryForDotNetWasm.Replace(".sha256-", ".sha256-different");
7777

7878
// Remove some items we do need, and add an item we don't need
79-
RemoveCacheEntry(cacheEntryForMsCorLib);
79+
RemoveCacheEntry(cacheEntryForComponentsDll);
8080
RemoveCacheEntry(cacheEntryForDotNetWasm);
8181
AddCacheEntry(cacheEntryForDotNetWasmWithChangedHash, "ignored content");
8282
var cacheEntryUrls2 = GetCacheEntryUrls();
83-
Assert.DoesNotContain(cacheEntryForMsCorLib, cacheEntryUrls2);
83+
Assert.DoesNotContain(cacheEntryForComponentsDll, cacheEntryUrls2);
8484
Assert.DoesNotContain(cacheEntryForDotNetWasm, cacheEntryUrls2);
8585
Assert.Contains(cacheEntryForDotNetWasmWithChangedHash, cacheEntryUrls2);
8686

@@ -91,13 +91,13 @@ public void IncrementallyUpdatesCache()
9191
WaitUntilLoaded();
9292
var subsequentResourcesRequested = GetAndClearRequestedPaths();
9393
Assert.Collection(subsequentResourcesRequested.Where(url => url.Contains(".dll")),
94-
requestedDll => Assert.Contains("/mscorlib.dll", requestedDll));
94+
requestedDll => Assert.Contains("/Microsoft.AspNetCore.Components.dll", requestedDll));
9595
Assert.Collection(subsequentResourcesRequested.Where(url => url.Contains(".wasm")),
9696
requestedDll => Assert.Contains("/dotnet.wasm", requestedDll));
9797

9898
// We also update the cache (add new items, remove unnecessary items)
9999
var cacheEntryUrls3 = GetCacheEntryUrls();
100-
Assert.Contains(cacheEntryForMsCorLib, cacheEntryUrls3);
100+
Assert.Contains(cacheEntryForComponentsDll, cacheEntryUrls3);
101101
Assert.Contains(cacheEntryForDotNetWasm, cacheEntryUrls3);
102102
Assert.DoesNotContain(cacheEntryForDotNetWasmWithChangedHash, cacheEntryUrls3);
103103
}

src/Components/test/E2ETest/Tests/ClientRenderingMultpleComponentsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
using Xunit;
1515
using Xunit.Abstractions;
1616

17-
namespace Microsoft.AspNetCore.Components.E2ETests.Tests
17+
namespace Microsoft.AspNetCore.Components.E2ETest.Tests
1818
{
1919
public class ClientRenderingMultpleComponentsTest : ServerTestBase<BasicTestAppServerSiteFixture<MultipleComponents>>
2020
{

src/Components/test/E2ETest/Tests/HeadComponentsTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44
using System.Linq;
55
using BasicTestApp;
6-
using Microsoft.AspNetCore.Components.E2ETest;
76
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
87
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
98
using Microsoft.AspNetCore.E2ETesting;
109
using OpenQA.Selenium;
1110
using Xunit;
1211
using Xunit.Abstractions;
1312

14-
namespace Microsoft.AspNetCore.Components.E2ETests.Tests
13+
namespace Microsoft.AspNetCore.Components.E2ETest.Tests
1514
{
1615
public class HeadComponentsTest : ServerTestBase<ToggleExecutionModeServerFixture<Program>>
1716
{

src/Components/test/E2ETest/Tests/VirtualizationTest.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using BasicTestApp;
5-
using Microsoft.AspNetCore.Components.E2ETest;
65
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
76
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
87
using Microsoft.AspNetCore.E2ETesting;
@@ -12,7 +11,7 @@
1211
using Xunit;
1312
using Xunit.Abstractions;
1413

15-
namespace Microsoft.AspNetCore.Components.E2ETests.Tests
14+
namespace Microsoft.AspNetCore.Components.E2ETest.Tests
1615
{
1716
public class VirtualizationTest : ServerTestBase<ToggleExecutionModeServerFixture<Program>>
1817
{
@@ -121,7 +120,7 @@ public void RerendersWhenItemSizeShrinks_Sync()
121120
var itemSizeInput = Browser.FindElement(By.Id("item-size-input"));
122121

123122
// Change the item size.
124-
itemSizeInput.SendKeys("\b\b\b50\n");
123+
itemSizeInput.SendKeys("\b\b\b10\n");
125124

126125
// Validate that the list has been re-rendered to show more items.
127126
Browser.True(() => GetItemCount() > initialItemCount);
@@ -146,7 +145,7 @@ public void RerendersWhenItemSizeShrinks_Async()
146145
var itemSizeInput = Browser.FindElement(By.Id("item-size-input"));
147146

148147
// Change the item size.
149-
itemSizeInput.SendKeys("\b\b\b50\n");
148+
itemSizeInput.SendKeys("\b\b\b10\n");
150149

151150
// Validate that the same number of loaded items is rendered.
152151
Browser.Equal(initialItemCount, GetItemCount);

0 commit comments

Comments
 (0)