namespace XFESystem.Browser.Tests; public sealed class ClassicScriptMimeTests { [Theory] [InlineData("application/json", false, true)] [InlineData("text/plain", false, true)] [InlineData("application/json", true, false)] [InlineData("text/plain", true, false)] [InlineData("application/javascript", true, true)] [InlineData("image/png", false, false)] [InlineData("text/html", false, true)] [InlineData("text/html", true, false)] [InlineData("text/csv", false, false)] public void ClassicCompatibilityDoesNotOverrideNosniffOrRunDataScriptTypes(string mime, bool nosniff, bool allowed) { var page = new BrowserService(new Transport(mime, nosniff)); try { var result = page.Navigate("http://example.test/"); Assert.Equal(allowed ? "42" : "undefined", page.ExecuteJavaScript("typeof mimeCanary==='undefined'?'undefined':String(mimeCanary)")); Assert.Equal("undefined", page.ExecuteJavaScript("typeof inertCanary")); Assert.Equal(!allowed, result.Text.Contains("unsupported MIME", StringComparison.Ordinal)); } finally { page.Release(); } } private sealed class Transport(string mime, bool nosniff) : IWebTransport { public WebResponse Get(Uri address, BrowserLimits limits) => address.AbsolutePath == "/" ? new(address, 200, "text/html", "") : new(address, 200, mime, "globalThis.mimeCanary=42", NoSniff: nosniff); } }