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
This commit is contained in:
Steve Sanderson 2020-09-09 17:54:45 +01:00 committed by GitHub
parent 646925127b
commit c5bcd68853
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 15 deletions

File diff suppressed because one or more lines are too long

View File

@ -165,9 +165,9 @@ async function getCacheToUseIfEnabled(bootConfig: BootJsonData): Promise<Cache |
return null; return null;
} }
// cache integrity is compromised if the first request has been served over http // cache integrity is compromised if the first request has been served over http (except localhost)
// in this case, we want to disable caching and integrity validation // in this case, we want to disable caching and integrity validation
if (document.location.protocol !== 'https:') { if (window.isSecureContext === false) {
return null; return null;
} }

View File

@ -83,4 +83,12 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
{ {
} }
} }
public class ServerVirtualizationTest : VirtualizationTest
{
public ServerVirtualizationTest(BrowserFixture browserFixture, ToggleExecutionModeServerFixture<Program> serverFixture, ITestOutputHelper output)
: base(browserFixture, serverFixture.WithServerExecution(), output)
{
}
}
} }

View File

@ -71,16 +71,16 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
Navigate("/"); Navigate("/");
WaitUntilLoaded(); WaitUntilLoaded();
var cacheEntryUrls1 = GetCacheEntryUrls(); var cacheEntryUrls1 = GetCacheEntryUrls();
var cacheEntryForMsCorLib = cacheEntryUrls1.Single(url => url.Contains("/mscorlib.dll")); var cacheEntryForComponentsDll = cacheEntryUrls1.Single(url => url.Contains("/Microsoft.AspNetCore.Components.dll"));
var cacheEntryForDotNetWasm = cacheEntryUrls1.Single(url => url.Contains("/dotnet.wasm")); var cacheEntryForDotNetWasm = cacheEntryUrls1.Single(url => url.Contains("/dotnet.wasm"));
var cacheEntryForDotNetWasmWithChangedHash = cacheEntryForDotNetWasm.Replace(".sha256-", ".sha256-different"); var cacheEntryForDotNetWasmWithChangedHash = cacheEntryForDotNetWasm.Replace(".sha256-", ".sha256-different");
// Remove some items we do need, and add an item we don't need // Remove some items we do need, and add an item we don't need
RemoveCacheEntry(cacheEntryForMsCorLib); RemoveCacheEntry(cacheEntryForComponentsDll);
RemoveCacheEntry(cacheEntryForDotNetWasm); RemoveCacheEntry(cacheEntryForDotNetWasm);
AddCacheEntry(cacheEntryForDotNetWasmWithChangedHash, "ignored content"); AddCacheEntry(cacheEntryForDotNetWasmWithChangedHash, "ignored content");
var cacheEntryUrls2 = GetCacheEntryUrls(); var cacheEntryUrls2 = GetCacheEntryUrls();
Assert.DoesNotContain(cacheEntryForMsCorLib, cacheEntryUrls2); Assert.DoesNotContain(cacheEntryForComponentsDll, cacheEntryUrls2);
Assert.DoesNotContain(cacheEntryForDotNetWasm, cacheEntryUrls2); Assert.DoesNotContain(cacheEntryForDotNetWasm, cacheEntryUrls2);
Assert.Contains(cacheEntryForDotNetWasmWithChangedHash, cacheEntryUrls2); Assert.Contains(cacheEntryForDotNetWasmWithChangedHash, cacheEntryUrls2);
@ -91,13 +91,13 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
WaitUntilLoaded(); WaitUntilLoaded();
var subsequentResourcesRequested = GetAndClearRequestedPaths(); var subsequentResourcesRequested = GetAndClearRequestedPaths();
Assert.Collection(subsequentResourcesRequested.Where(url => url.Contains(".dll")), Assert.Collection(subsequentResourcesRequested.Where(url => url.Contains(".dll")),
requestedDll => Assert.Contains("/mscorlib.dll", requestedDll)); requestedDll => Assert.Contains("/Microsoft.AspNetCore.Components.dll", requestedDll));
Assert.Collection(subsequentResourcesRequested.Where(url => url.Contains(".wasm")), Assert.Collection(subsequentResourcesRequested.Where(url => url.Contains(".wasm")),
requestedDll => Assert.Contains("/dotnet.wasm", requestedDll)); requestedDll => Assert.Contains("/dotnet.wasm", requestedDll));
// We also update the cache (add new items, remove unnecessary items) // We also update the cache (add new items, remove unnecessary items)
var cacheEntryUrls3 = GetCacheEntryUrls(); var cacheEntryUrls3 = GetCacheEntryUrls();
Assert.Contains(cacheEntryForMsCorLib, cacheEntryUrls3); Assert.Contains(cacheEntryForComponentsDll, cacheEntryUrls3);
Assert.Contains(cacheEntryForDotNetWasm, cacheEntryUrls3); Assert.Contains(cacheEntryForDotNetWasm, cacheEntryUrls3);
Assert.DoesNotContain(cacheEntryForDotNetWasmWithChangedHash, cacheEntryUrls3); Assert.DoesNotContain(cacheEntryForDotNetWasmWithChangedHash, cacheEntryUrls3);
} }

View File

@ -14,7 +14,7 @@ using TestServer;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
namespace Microsoft.AspNetCore.Components.E2ETests.Tests namespace Microsoft.AspNetCore.Components.E2ETest.Tests
{ {
public class ClientRenderingMultpleComponentsTest : ServerTestBase<BasicTestAppServerSiteFixture<MultipleComponents>> public class ClientRenderingMultpleComponentsTest : ServerTestBase<BasicTestAppServerSiteFixture<MultipleComponents>>
{ {

View File

@ -3,7 +3,6 @@
using System.Linq; using System.Linq;
using BasicTestApp; using BasicTestApp;
using Microsoft.AspNetCore.Components.E2ETest;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure; using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures; using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting; using Microsoft.AspNetCore.E2ETesting;
@ -11,7 +10,7 @@ using OpenQA.Selenium;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
namespace Microsoft.AspNetCore.Components.E2ETests.Tests namespace Microsoft.AspNetCore.Components.E2ETest.Tests
{ {
public class HeadComponentsTest : ServerTestBase<ToggleExecutionModeServerFixture<Program>> public class HeadComponentsTest : ServerTestBase<ToggleExecutionModeServerFixture<Program>>
{ {

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using BasicTestApp; using BasicTestApp;
using Microsoft.AspNetCore.Components.E2ETest;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure; using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures; using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting; using Microsoft.AspNetCore.E2ETesting;
@ -12,7 +11,7 @@ using OpenQA.Selenium.Support.Extensions;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
namespace Microsoft.AspNetCore.Components.E2ETests.Tests namespace Microsoft.AspNetCore.Components.E2ETest.Tests
{ {
public class VirtualizationTest : ServerTestBase<ToggleExecutionModeServerFixture<Program>> public class VirtualizationTest : ServerTestBase<ToggleExecutionModeServerFixture<Program>>
{ {
@ -121,7 +120,7 @@ namespace Microsoft.AspNetCore.Components.E2ETests.Tests
var itemSizeInput = Browser.FindElement(By.Id("item-size-input")); var itemSizeInput = Browser.FindElement(By.Id("item-size-input"));
// Change the item size. // Change the item size.
itemSizeInput.SendKeys("\b\b\b50\n"); itemSizeInput.SendKeys("\b\b\b10\n");
// Validate that the list has been re-rendered to show more items. // Validate that the list has been re-rendered to show more items.
Browser.True(() => GetItemCount() > initialItemCount); Browser.True(() => GetItemCount() > initialItemCount);
@ -146,7 +145,7 @@ namespace Microsoft.AspNetCore.Components.E2ETests.Tests
var itemSizeInput = Browser.FindElement(By.Id("item-size-input")); var itemSizeInput = Browser.FindElement(By.Id("item-size-input"));
// Change the item size. // Change the item size.
itemSizeInput.SendKeys("\b\b\b50\n"); itemSizeInput.SendKeys("\b\b\b10\n");
// Validate that the same number of loaded items is rendered. // Validate that the same number of loaded items is rendered.
Browser.Equal(initialItemCount, GetItemCount); Browser.Equal(initialItemCount, GetItemCount);