Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public static partial class PlatformDetection
public static bool IsSpeedOptimized => !IsSizeOptimized;
public static bool IsSizeOptimized => IsBrowser || IsAndroid || IsAppleMobile;

public static bool IsBrowserDomSupported => GetIsBrowserDomSupported();
public static bool IsBrowserDomSupportedOrNotBrowser => IsNotBrowser || GetIsBrowserDomSupported();
public static bool IsBrowserDomSupported => IsEnvironmentVariableTrue("IsBrowserDomSupported");
public static bool IsBrowserDomSupportedOrNotBrowser => IsNotBrowser || IsBrowserDomSupported;
public static bool IsNotBrowserDomSupported => !IsBrowserDomSupported;
public static bool IsWebSocketSupported => IsEnvironmentVariableTrue("IsWebSocketSupported");
public static bool LocalEchoServerIsNotAvailable => !LocalEchoServerIsAvailable;
public static bool LocalEchoServerIsAvailable => IsBrowser;

Expand Down Expand Up @@ -494,12 +495,12 @@ private static bool GetIsRunningOnMonoInterpreter()
#endif
}

private static bool GetIsBrowserDomSupported()
private static bool IsEnvironmentVariableTrue(string variableName)
{
if (!IsBrowser)
return false;

var val = Environment.GetEnvironmentVariable("IsBrowserDomSupported");
var val = Environment.GetEnvironmentVariable(variableName);
return (val != null && val == "true");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public AbortTest(ITestOutputHelper output) : base(output) { }

[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/63673", TestPlatforms.Browser)]
public async Task Abort_ConnectAndAbort_ThrowsWebSocketExceptionWithmessage(Uri server)
{
using (var cws = new ClientWebSocket())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public async Task ConnectAsync_CookieHeaders_Success(Uri server)

[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/63681", TestPlatforms.Browser)]
public async Task ConnectAsync_PassNoSubProtocol_ServerRequires_ThrowsWebSocketException(Uri server)
{
const string AcceptedProtocol = "CustomProtocol";
Expand Down Expand Up @@ -256,6 +257,7 @@ public async Task ConnectAndCloseAsync_UseProxyServer_ExpectedClosedState(Uri se
}

[ConditionalFact(nameof(WebSocketsSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/63672", TestPlatforms.Browser)]
public async Task ConnectAsync_CancellationRequestedBeforeConnect_ThrowsOperationCanceledException()
{
using (var clientSocket = new ClientWebSocket())
Expand All @@ -268,6 +270,7 @@ public async Task ConnectAsync_CancellationRequestedBeforeConnect_ThrowsOperatio
}

[ConditionalFact(nameof(WebSocketsSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/63672", TestPlatforms.Browser)]
public async Task ConnectAsync_CancellationRequestedInflightConnect_ThrowsOperationCanceledException()
{
using (var clientSocket = new ClientWebSocket())
Expand All @@ -281,6 +284,7 @@ public async Task ConnectAsync_CancellationRequestedInflightConnect_ThrowsOperat

[ConditionalFact(nameof(WebSocketsSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34690", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/63671", TestPlatforms.Browser)]
public async Task ConnectAsync_CancellationRequestedAfterConnect_ThrowsOperationCanceledException()
{
var releaseServer = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,40 @@
</PropertyGroup>

<PropertyGroup Condition="'$(TargetOS)' == 'Browser'">
<!-- This doesn't run on V8 because it lacks websocket support -->
<Scenario>WasmTestOnBrowser</Scenario>
<TestArchiveTestsRoot>$(TestArchiveRoot)browseronly/</TestArchiveTestsRoot>
<TestArchiveTestsRoot>$(TestArchiveRoot)browserornodejs/</TestArchiveTestsRoot>
<TestArchiveTestsDir>$(TestArchiveTestsRoot)$(OSPlatformConfig)/</TestArchiveTestsDir>
<DefineConstants>$(DefineConstants);TARGET_BROWSER</DefineConstants>
</PropertyGroup>

<Import Condition="'$(TargetOS)' == 'Browser'" Project="$(CommonTestPath)System/Net/Prerequisites/LocalEchoServer.props" />

<PropertyGroup Condition="'$(Scenario)' == 'WasmTestOnNodeJS'">
<WasmXHarnessMonoArgs>--setenv=NPM_MODULES=ws:WebSocket</WasmXHarnessMonoArgs>
</PropertyGroup>
<ItemGroup Condition="'$(Scenario)' == 'WasmTestOnNodeJS'">
<WasmExtraFilesToDeploy Include="package.json" />
<WasmExtraFilesToDeploy Include="package-lock.json" />
</ItemGroup>

<ItemGroup Condition="'$(Scenario)' == 'WasmTestOnNodeJS' and '$(OS)' != 'Windows_NT'">
<!-- WebSocket tests use self-signed certificates for wss protocol that are refused by NodeJS -->
<SetScriptCommands Include="export NODE_TLS_REJECT_UNAUTHORIZED=0" />
<HelixPreCommand Include="export NODE_TLS_REJECT_UNAUTHORIZED=0" />
<!-- Restore NPM packages -->
<RunScriptCommands Include="pushd $EXECUTION_DIR &amp;&amp; npm ci &amp;&amp; popd" />
<HelixPreCommand Include="npm ci" />
</ItemGroup>
<ItemGroup Condition="'$(Scenario)' == 'WasmTestOnNodeJS' and '$(OS)' == 'Windows_NT'">
<!-- WebSocket tests use self-signed certificates for wss protocol that are refused by NodeJS -->
<SetScriptCommands Include="set &quot;NODE_TLS_REJECT_UNAUTHORIZED=0&quot;" />
<HelixPreCommand Include="set &quot;NODE_TLS_REJECT_UNAUTHORIZED=0&quot;" />
<!-- Restore NPM packages -->
<RunScriptCommands Include="cmd /c &quot;cd %EXECUTION_DIR% &amp;&amp; npm ci&quot;" />
<HelixPreCommand Include="cmd /c &quot;npm ci&quot;" />
</ItemGroup>

<!-- Browser specific files -->
<ItemGroup Condition="'$(TargetOS)' == 'Browser'">
<ProjectReference Include="$(CommonTestPath)System/Net/Prerequisites/NetCoreServer/NetCoreServer.csproj" ReferenceOutputAssembly="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static async Task<T> Retry<T>(ITestOutputHelper output, Func<Task<T>> fun
private static bool InitWebSocketSupported()
{
ClientWebSocket cws = null;
if (PlatformDetection.IsBrowser && !PlatformDetection.IsBrowserDomSupported)
if (PlatformDetection.IsBrowser && !PlatformDetection.IsWebSocketSupported)
{
return false;
}
Expand Down
44 changes: 44 additions & 0 deletions src/libraries/System.Net.WebSockets.Client/tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/libraries/System.Net.WebSockets.Client/tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "system.net.websockets.client.tests",
"private": true,
"dependencies": {
"ws": "8.4.0"
}
}
21 changes: 21 additions & 0 deletions src/mono/wasm/test-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,27 @@ try {
console.error(e);
}

if (is_node) {
const modulesToLoad = processedArguments.setenv["NPM_MODULES"];
if (modulesToLoad) {
modulesToLoad.split(',').forEach(module => {
const parts = module.split(':');

let message = `Loading npm '${parts[0]}'`;
const moduleExport = require(parts[0]);
if (parts.length == 2) {
message += ` and attaching to global as '${parts[1]}'.`;
globalThis[parts[1]] = moduleExport;
}

console.log(message);
});
}
}

// Must be after loading npm modules.
processedArguments.setenv["IsWebSocketSupported"] = ("WebSocket" in globalThis).toString().toLowerCase();

async function loadDotnet(file) {
let loadScript = undefined;
if (typeof WScript !== "undefined") { // Chakra
Expand Down