From 44e29c2d4e151e35fa4794dbdaab59412ed064cd Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Wed, 17 Apr 2024 09:39:42 +0200 Subject: [PATCH] [browser] easy prep for Firefox (#101138) --- .../System/Net/Capability.Security.Unix.cs | 4 ++++ .../TestUtilities/System/PlatformDetection.cs | 2 ++ .../DebuggerTestSuite/ChromeProvider.cs | 2 +- .../DebuggerTestSuite/FirefoxProvider.cs | 2 +- .../tests/debugger-test/debugger-driver.html | 2 +- .../tests/debugger-test/non-wasm-page.html | 2 +- .../wasm-page-without-assets.html | 2 +- src/mono/browser/test-main.js | 19 +++++++++++++++++-- .../Wasm.Build.Tests/TestMainJsTestBase.cs | 2 +- src/tests/Common/wasm-test-runner/index.html | 2 +- 10 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/libraries/Common/tests/System/Net/Capability.Security.Unix.cs b/src/libraries/Common/tests/System/Net/Capability.Security.Unix.cs index bad2ddd2dd73fc..3bbba47040b01b 100644 --- a/src/libraries/Common/tests/System/Net/Capability.Security.Unix.cs +++ b/src/libraries/Common/tests/System/Net/Capability.Security.Unix.cs @@ -9,6 +9,10 @@ public static partial class Capability { public static bool IsNtlmInstalled() { + if (OperatingSystem.IsBrowser()) + { + return false; + } return // Linux bionic uses managed NTLM implementation (OperatingSystem.IsLinux() && RuntimeInformation.RuntimeIdentifier.StartsWith("linux-bionic-", StringComparison.Ordinal)) || diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index 3c93c2b4670989..ec6645cec0c319 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -152,6 +152,8 @@ public static int SlowRuntimeTimeoutModifier public static bool IsNotBrowserDomSupported => !IsBrowserDomSupported; public static bool IsWebSocketSupported => IsEnvironmentVariableTrue("IsWebSocketSupported"); public static bool IsNodeJS => IsEnvironmentVariableTrue("IsNodeJS"); + public static bool IsFirefox => IsEnvironmentVariableTrue("IsFirefox"); + public static bool IsChromium => IsEnvironmentVariableTrue("IsChromium"); public static bool IsNotNodeJS => !IsNodeJS; public static bool IsNodeJSOnWindows => GetNodeJSPlatform() == "win32"; public static bool LocalEchoServerIsNotAvailable => !LocalEchoServerIsAvailable; diff --git a/src/mono/browser/debugger/DebuggerTestSuite/ChromeProvider.cs b/src/mono/browser/debugger/DebuggerTestSuite/ChromeProvider.cs index 17eedf748ed729..6240462add49c8 100644 --- a/src/mono/browser/debugger/DebuggerTestSuite/ChromeProvider.cs +++ b/src/mono/browser/debugger/DebuggerTestSuite/ChromeProvider.cs @@ -28,7 +28,7 @@ internal class ChromeProvider : WasmHostProvider private DebuggerProxy? _debuggerProxy; private static readonly Lazy s_browserPath = new(() => { - string artifactsBinDir = Path.Combine(Path.GetDirectoryName(typeof(ChromeProvider).Assembly.Location)!, "..", "..", ".."); + string artifactsBinDir = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(typeof(ChromeProvider).Assembly.Location)!, "..", "..", "..")); return BrowserLocator.FindChrome(artifactsBinDir, "BROWSER_PATH_FOR_TESTS"); }); private static readonly string[] s_messagesToFilterOut = new[] diff --git a/src/mono/browser/debugger/DebuggerTestSuite/FirefoxProvider.cs b/src/mono/browser/debugger/DebuggerTestSuite/FirefoxProvider.cs index b64fe84ca3d92f..d48a282888a626 100644 --- a/src/mono/browser/debugger/DebuggerTestSuite/FirefoxProvider.cs +++ b/src/mono/browser/debugger/DebuggerTestSuite/FirefoxProvider.cs @@ -23,7 +23,7 @@ internal class FirefoxProvider : WasmHostProvider private FirefoxDebuggerProxy? _firefoxDebuggerProxy; private static readonly Lazy s_browserPath = new(() => { - string artifactsBinDir = Path.Combine(Path.GetDirectoryName(typeof(ChromeProvider).Assembly.Location)!, "..", "..", ".."); + string artifactsBinDir = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(typeof(ChromeProvider).Assembly.Location)!, "..", "..", "..")); return BrowserLocator.FindFirefox(artifactsBinDir, "BROWSER_PATH_FOR_TESTS"); }); diff --git a/src/mono/browser/debugger/tests/debugger-test/debugger-driver.html b/src/mono/browser/debugger/tests/debugger-test/debugger-driver.html index 9d04b58b665c55..e140e64e6ad4cd 100644 --- a/src/mono/browser/debugger/tests/debugger-test/debugger-driver.html +++ b/src/mono/browser/debugger/tests/debugger-test/debugger-driver.html @@ -1,4 +1,4 @@ - + diff --git a/src/mono/browser/debugger/tests/debugger-test/non-wasm-page.html b/src/mono/browser/debugger/tests/debugger-test/non-wasm-page.html index 2894375a79c809..1442fc9b6af961 100644 --- a/src/mono/browser/debugger/tests/debugger-test/non-wasm-page.html +++ b/src/mono/browser/debugger/tests/debugger-test/non-wasm-page.html @@ -1,4 +1,4 @@ - + diff --git a/src/mono/browser/debugger/tests/debugger-test/wasm-page-without-assets.html b/src/mono/browser/debugger/tests/debugger-test/wasm-page-without-assets.html index 49a836c8e88598..9fcdbf4570c1ee 100644 --- a/src/mono/browser/debugger/tests/debugger-test/wasm-page-without-assets.html +++ b/src/mono/browser/debugger/tests/debugger-test/wasm-page-without-assets.html @@ -1,4 +1,4 @@ - + diff --git a/src/mono/browser/test-main.js b/src/mono/browser/test-main.js index 90b332aa5218a3..cb09304bc53526 100644 --- a/src/mono/browser/test-main.js +++ b/src/mono/browser/test-main.js @@ -24,6 +24,8 @@ export const ENVIRONMENT_IS_SIDECAR = ENVIRONMENT_IS_WEB_WORKER && typeof dotnet export const ENVIRONMENT_IS_WORKER = ENVIRONMENT_IS_WEB_WORKER && !ENVIRONMENT_IS_SIDECAR; // we redefine what ENVIRONMENT_IS_WORKER, we replace it in emscripten internals, so that sidecar works export const ENVIRONMENT_IS_WEB = typeof window == "object" || (ENVIRONMENT_IS_WEB_WORKER && !ENVIRONMENT_IS_NODE); export const ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE; +export const isFirefox = !!(ENVIRONMENT_IS_WEB && navigator.userAgent.includes("Firefox")); +export const isChromium = !!(ENVIRONMENT_IS_WEB && navigator.userAgentData && navigator.userAgentData.brands.some(b => b.brand === "Google Chrome" || b.brand === "Microsoft Edge" || b.brand === "Chromium")); if (ENVIRONMENT_IS_NODE && process.versions.node.split(".")[0] < 14) { throw new Error(`NodeJS at '${process.execPath}' has too low version '${process.versions.node}'`); @@ -51,8 +53,13 @@ if (!ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WEB && typeof globalThis.crypto === } } -if (ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_WORKER) { - console.log("Running '" + globalThis.navigator.userAgent + "' at: \n" + globalThis.location.href + "\n"); +if (ENVIRONMENT_IS_WEB && isFirefox) { + Error.stackTraceLimit = 1000; +} + +if (ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_WORKER && !isFirefox) { + console.log("Running in: " + globalThis.navigator.userAgent); + console.log("Running at: " + globalThis.location.href); } let v8args; @@ -179,6 +186,8 @@ function processArguments(incomingArguments, runArgs) { // cheap way to let the testing infrastructure know we're running in a browser context (or not) runArgs.environmentVariables["IsBrowserDomSupported"] = ENVIRONMENT_IS_WEB.toString().toLowerCase(); runArgs.environmentVariables["IsNodeJS"] = ENVIRONMENT_IS_NODE.toString().toLowerCase(); + runArgs.environmentVariables["IsFirefox"] = isFirefox.toString().toLowerCase(); + runArgs.environmentVariables["IsChromium"] = isChromium.toString().toLowerCase(); return runArgs; } @@ -312,6 +321,12 @@ async function run() { App.runtime = await dotnet.create(); App.runArgs = runArgs + if (ENVIRONMENT_IS_WEB && isFirefox) { + console.log("Application arguments: " + runArgs.applicationArguments.join(' ')); + console.log("Running in: " + globalThis.navigator.userAgent); + console.log("Running at: " + globalThis.location.href); + } + console.info("Initializing dotnet version " + App.runtime.runtimeBuildInfo.productVersion + " commit hash " + App.runtime.runtimeBuildInfo.gitHash); for (let i = 0; i < runArgs.profilers.length; ++i) { diff --git a/src/mono/wasm/Wasm.Build.Tests/TestMainJsTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/TestMainJsTestBase.cs index 2c56227c6693a3..4d5db19dc53f34 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestMainJsTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestMainJsTestBase.cs @@ -55,7 +55,7 @@ protected TestMainJsTestBase(ITestOutputHelper output, SharedBuildPerTestClassFi Path.Combine(_projectDir, "test-main.js") ); - File.WriteAllText(Path.Combine(_projectDir!, "index.html"), @""); + File.WriteAllText(Path.Combine(_projectDir!, "index.html"), @""); } else if (_projectDir is null) { diff --git a/src/tests/Common/wasm-test-runner/index.html b/src/tests/Common/wasm-test-runner/index.html index ff7d959f164d40..716b7c4c11f39f 100644 --- a/src/tests/Common/wasm-test-runner/index.html +++ b/src/tests/Common/wasm-test-runner/index.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file