|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
4 |
| -using System.Net.Http; |
5 | 4 | using System.Text.Encodings.Web;
|
6 | 5 | using System.Text.Json;
|
7 | 6 | using System.Text.RegularExpressions;
|
@@ -71,6 +70,78 @@ public async Task CanRender_ParameterlessComponent_ClientMode()
|
71 | 70 | Assert.Empty(httpContext.Items);
|
72 | 71 | }
|
73 | 72 |
|
| 73 | + [Fact] |
| 74 | + public async Task CanPreload_WebAssembly_ResourceAssets() |
| 75 | + { |
| 76 | + // Arrange |
| 77 | + var httpContext = GetHttpContext(); |
| 78 | + var writer = new StringWriter(); |
| 79 | + |
| 80 | + httpContext.SetEndpoint( |
| 81 | + new Endpoint( |
| 82 | + ctx => Task.CompletedTask, |
| 83 | + new EndpointMetadataCollection([ |
| 84 | + new ResourcePreloadCollection( |
| 85 | + new ResourceAssetCollection([ |
| 86 | + new ResourceAsset("second.js", [ |
| 87 | + new ResourceAssetProperty("preloadrel", "preload"), |
| 88 | + new ResourceAssetProperty("preloadas", "script"), |
| 89 | + new ResourceAssetProperty("preloadpriority", "high"), |
| 90 | + new ResourceAssetProperty("preloadcrossorigin", "anonymous"), |
| 91 | + new ResourceAssetProperty("integrity", "abcd"), |
| 92 | + new ResourceAssetProperty("preloadorder", "2"), |
| 93 | + new ResourceAssetProperty("preloadgroup", "webassembly") |
| 94 | + ]), |
| 95 | + new ResourceAsset("first.js", [ |
| 96 | + new ResourceAssetProperty("preloadrel", "preload"), |
| 97 | + new ResourceAssetProperty("preloadas", "script"), |
| 98 | + new ResourceAssetProperty("preloadpriority", "high"), |
| 99 | + new ResourceAssetProperty("preloadcrossorigin", "anonymous"), |
| 100 | + new ResourceAssetProperty("integrity", "abcd"), |
| 101 | + new ResourceAssetProperty("preloadorder", "1"), |
| 102 | + new ResourceAssetProperty("preloadgroup", "webassembly") |
| 103 | + ]), |
| 104 | + new ResourceAsset("preload-nowebassembly.js", [ |
| 105 | + new ResourceAssetProperty("preloadrel", "preload"), |
| 106 | + new ResourceAssetProperty("preloadas", "script"), |
| 107 | + new ResourceAssetProperty("preloadpriority", "high"), |
| 108 | + new ResourceAssetProperty("preloadcrossorigin", "anonymous"), |
| 109 | + new ResourceAssetProperty("integrity", "abcd"), |
| 110 | + new ResourceAssetProperty("preloadorder", "1"), |
| 111 | + new ResourceAssetProperty("preloadgroup", "abcd") |
| 112 | + ]), |
| 113 | + new ResourceAsset("nopreload.js", [ |
| 114 | + new ResourceAssetProperty("integrity", "abcd") |
| 115 | + ]) |
| 116 | + ]) |
| 117 | + ) |
| 118 | + ]), |
| 119 | + "TestEndpoint" |
| 120 | + ) |
| 121 | + ); |
| 122 | + |
| 123 | + // Act |
| 124 | + var result = await renderer.PrerenderComponentAsync(httpContext, typeof(SimpleComponent), new InteractiveWebAssemblyRenderMode(prerender: false), ParameterView.Empty); |
| 125 | + await renderer.Dispatcher.InvokeAsync(() => result.WriteTo(writer, HtmlEncoder.Default)); |
| 126 | + |
| 127 | + // Assert |
| 128 | + Assert.Equal(2, httpContext.Response.Headers.Link.Count); |
| 129 | + |
| 130 | + var firstPreloadLink = httpContext.Response.Headers.Link[0]; |
| 131 | + Assert.Contains("<first.js>", firstPreloadLink); |
| 132 | + Assert.Contains("rel=preload", firstPreloadLink); |
| 133 | + Assert.Contains("as=script", firstPreloadLink); |
| 134 | + Assert.Contains("fetchpriority=high", firstPreloadLink); |
| 135 | + Assert.Contains("integrity=\"abcd\"", firstPreloadLink); |
| 136 | + |
| 137 | + var secondPreloadLink = httpContext.Response.Headers.Link[1]; |
| 138 | + Assert.Contains("<second.js>", secondPreloadLink); |
| 139 | + Assert.Contains("rel=preload", secondPreloadLink); |
| 140 | + Assert.Contains("as=script", secondPreloadLink); |
| 141 | + Assert.Contains("fetchpriority=high", secondPreloadLink); |
| 142 | + Assert.Contains("integrity=\"abcd\"", secondPreloadLink); |
| 143 | + } |
| 144 | + |
74 | 145 | [Fact]
|
75 | 146 | public async Task CanPrerender_ParameterlessComponent_ClientMode()
|
76 | 147 | {
|
|
0 commit comments