Skip to content

Commit

Permalink
Test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Fisera committed Jan 16, 2025
1 parent 4d5a399 commit 3e37137
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public void InitializersRunsModernCallbacksByDefaultWhenPresent(bool streaming,
var url = $"{ServerPathBase}/initializers?streaming={streaming}&wasm={webassembly}&server={server}";
Navigate(url);

if (webassembly)
{
((IJavaScriptExecutor)Browser).ExecuteScript("sessionStorage.setItem('block-webassembly-settings', 'true')");
}

foreach (var callback in expectedInvokedCallbacks)
{
Browser.Exists(By.Id(callback));
Expand Down Expand Up @@ -82,7 +87,7 @@ public static TheoryData<bool, bool, bool, string[]> InitializerTestData()
{
{ false, false, false, ["classic-and-modern-before-web-start", "classic-and-modern-after-web-started","modern-before-web-start", "modern-after-web-started"] },
{ false, false, true, ["classic-and-modern-before-web-start", "classic-and-modern-after-web-started", "classic-and-modern-before-server-start", "classic-and-modern-after-server-started", "classic-and-modern-circuit-opened", "modern-before-web-start", "modern-after-web-started", "modern-before-server-start", "modern-after-server-started", "modern-circuit-opened" ] },
{ false, true, false, ["classic-and-modern-before-web-start", "classic-and-modern-after-web-started", "classic-and-modern-before-web-assembly-start", "classic-and-modern-after-web-assembly-started", "modern-before-web-start", "modern-after-web-started", "modern-before-web-assembly-start", "modern-after-web-assembly-started"] },
{ false, true, false, ["classic-and-modern-before-web-start", "classic-and-modern-after-web-started", "classic-and-modern-before-web-assembly-start", "classic-and-modern-after-web-assembly-started", "server--classic-and-modern-before-web-assembly-start", "server--classic-and-modern-after-web-assembly-started", "modern-before-web-start", "modern-after-web-started", "modern-before-web-assembly-start", "modern-after-web-assembly-started"] },
{ false, true, true, ["classic-and-modern-before-web-start", "classic-and-modern-after-web-started", "classic-and-modern-before-server-start", "classic-and-modern-circuit-opened", "classic-and-modern-after-server-started", "classic-and-modern-before-web-assembly-start", "classic-and-modern-after-web-assembly-started", "modern-before-web-start", "modern-after-web-started", "modern-before-server-start", "modern-circuit-opened", "modern-after-server-started", "modern-before-web-assembly-start", "modern-after-web-assembly-started"] },
{ true, false, false, ["classic-and-modern-before-web-start", "classic-and-modern-after-web-started","modern-before-web-start", "modern-after-web-started"] },
{ true, false, true, ["classic-and-modern-before-web-start", "classic-and-modern-after-web-started", "classic-and-modern-before-server-start", "classic-and-modern-after-server-started", "classic-and-modern-circuit-opened", "modern-before-web-start", "modern-after-web-started", "modern-before-server-start", "modern-after-server-started", "modern-circuit-opened" ] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@
const enableClassicInitializers = sessionStorage.getItem('enable-classic-initializers') === 'true';
const suppressEnhancedNavigation = sessionStorage.getItem('suppress-enhanced-navigation') === 'true';
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');
let loadBootResourceUnblocked = null;
if (blockLoadBootResource) {
Expand All @@ -66,6 +68,35 @@
let maxParallelResourceDownloadCount = 0;
let currentParallelResourceDownloadCount = 0;
let webAssemblySettings = {
loadBootResource: function (type, name, defaultUri, integrity) {
switch (type) {
case 'manifest':
case 'dotnetjs':
case 'dotnetwasm':
// note this is resolved to absolute URL using document.baseURI
return `WasmMinimal/_framework/${name}`;
default:
// The following allows us to arbitrarily delay the loading of WebAssembly resources.
// This is useful for guaranteeing that auto mode components will fall back on
// using Blazor server.
currentParallelResourceDownloadCount++;
return fetch(`${document.baseURI}WasmMinimal/_framework/${name}?`, {
method: "GET",
}).then(async (response) => {
if (currentParallelResourceDownloadCount > maxParallelResourceDownloadCount) {
maxParallelResourceDownloadCount = currentParallelResourceDownloadCount;
window['__aspnetcore__testing__max__parallel__resource__download__count'] = maxParallelResourceDownloadCount;
}
currentParallelResourceDownloadCount--;
await loadBootResourceUnblocked;
return response;
});
}
},
};
if (blockWebassemblySettings)
webAssemblySettings = null;
Blazor.start({
ssr: {
Expand All @@ -75,33 +106,7 @@
circuitInactivityTimeoutMs: 100,
},
enableClassicInitializers: enableClassicInitializers,
webAssembly: {
loadBootResource: function (type, name, defaultUri, integrity) {
switch (type) {
case 'manifest':
case 'dotnetjs':
case 'dotnetwasm':
// note this is resolved to absolute URL using document.baseURI
return `WasmMinimal/_framework/${name}`;
default:
// The following allows us to arbitrarily delay the loading of WebAssembly resources.
// This is useful for guaranteeing that auto mode components will fall back on
// using Blazor server.
currentParallelResourceDownloadCount++;
return fetch(`${document.baseURI}WasmMinimal/_framework/${name}?`, {
method: "GET",
}).then(async (response) => {
if (currentParallelResourceDownloadCount > maxParallelResourceDownloadCount) {
maxParallelResourceDownloadCount = currentParallelResourceDownloadCount;
window['__aspnetcore__testing__max__parallel__resource__download__count'] = maxParallelResourceDownloadCount;
}
currentParallelResourceDownloadCount--;
await loadBootResourceUnblocked;
return response;
});
}
},
},
webAssembly: webAssemblySettings,
circuit: {
reconnectionOptions: {
// It's easier to test the reconnection logic if we wait a bit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function beforeWebAssemblyStart() {
appendElement('server--classic-and-modern-before-web-assembly-start', 'Server project Classic and modern "beforeWebAssemblyStart"');
}

export function afterWebAssemblyStarted() {
appendElement('server--classic-and-modern-after-web-assembly-started', 'Server project Classic and modern "afterWebAssemblyStarted"');
}

0 comments on commit 3e37137

Please sign in to comment.