Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on RemoteExecutor on some files #12379

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
@@ -1,17 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.DotNet.RemoteExecutor;
using static System.Windows.Forms.Application;

namespace System.Windows.Forms.Tests;

public class ParkingWindowTests
{
[WinFormsFact(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")]
[WinFormsFact]
public void ParkingWindow_DoesNotThrowOnGarbageCollecting()
{
using RemoteInvokeHandle invokerHandle = RemoteExecutor.Invoke(() =>
Task.Run(() =>
{
Control.CheckForIllegalCrossThreadCalls = true;

Expand All @@ -28,10 +27,7 @@ public void ParkingWindow_DoesNotThrowOnGarbageCollecting()
{
Assert.True(ex is null, $"Expected no exception, but got: {ex.Message}"); // Actually need to check whether GC.Collect() does not throw exception.
}
});

// verify the remote process succeeded
Assert.Equal(RemoteExecutor.SuccessExitCode, invokerHandle.ExitCode);
}).Wait();
}

private Form InitFormWithControlToGarbageCollect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,36 @@ public void Application_CurrentCulture_SetNull_ThrowsArgumentNullException()
Assert.Throws<ArgumentNullException>("value", () => Application.CurrentCulture = null);
}

[WinFormsFact(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")]
[WinFormsFact]
public void Application_EnableVisualStyles_InvokeBeforeGettingRenderWithVisualStyles_Success()
{
RemoteExecutor.Invoke(() =>
Task.Run(() =>
{
Application.EnableVisualStyles();
Assert.True(Application.UseVisualStyles);
Assert.True(Application.RenderWithVisualStyles);
}).Dispose();
try
{
Application.EnableVisualStyles();
Assert.True(Application.UseVisualStyles);
Assert.True(Application.RenderWithVisualStyles);
}
finally
{
Application.VisualStyleState = VisualStyleState.NoneEnabled;
}
}).Wait();
}

[WinFormsFact(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")]
[WinFormsFact]
public void Application_EnableVisualStyles_InvokeAfterGettingRenderWithVisualStyles_Success()
{
// This is not a recommended scenario per
// https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.application.enablevisualstyles
// EnableVisualStyles should be executed before any control-related code is.
RemoteExecutor.Invoke(() =>
{
Assert.False(Application.UseVisualStyles);
Assert.False(Application.RenderWithVisualStyles);
Assert.False(Application.UseVisualStyles);
Assert.False(Application.RenderWithVisualStyles);

Application.EnableVisualStyles();
Assert.True(Application.UseVisualStyles, "New Visual Styles will not be applied on WinForms app. This is a high priority bug and must be looked into");
Assert.True(Application.RenderWithVisualStyles);
}).Dispose();
Application.EnableVisualStyles();
Assert.True(Application.UseVisualStyles, "New Visual Styles will not be applied on WinForms app. This is a high priority bug and must be looked into");
Assert.True(Application.RenderWithVisualStyles);
}

[WinFormsFact]
Expand All @@ -115,27 +119,26 @@ public void Application_VisualStyleState_Get_ReturnsExpected()
Assert.Equal(state, Application.VisualStyleState);
}

[WinFormsTheory(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")]
[WinFormsTheory]
[EnumData<VisualStyleState>]
[InvalidEnumData<VisualStyleState>]
public void Application_VisualStyleState_Set_ReturnsExpected(VisualStyleState valueParam)
{
// This needs to be in RemoteExecutor.Invoke because changing Application.VisualStyleState
// sends WM_THEMECHANGED to all controls, which can cause a deadlock if another test fails.
RemoteExecutor.Invoke((valueString) =>
Task.Run(() =>
{
VisualStyleState value = Enum.Parse<VisualStyleState>(valueString);
VisualStyleState state = Application.VisualStyleState;
try
{
Application.VisualStyleState = value;
Assert.Equal(value, Application.VisualStyleState);
Application.VisualStyleState = valueParam;
Assert.Equal(valueParam, Application.VisualStyleState);
}
finally
{
Application.VisualStyleState = state;
}
}, valueParam.ToString());
}).Wait();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.ComponentModel;
using System.Reflection;
using Microsoft.DotNet.RemoteExecutor;
using Moq;

namespace System.Windows.Forms.Tests;
Expand Down Expand Up @@ -116,29 +115,32 @@ public void ShowDialog_NonControlOwner_ReturnsExpected(bool runDialogResult, Dia
Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner.Object));
}

[WinFormsTheory(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")]
[WinFormsTheory]
[InlineData(true, DialogResult.OK)]
[InlineData(false, DialogResult.Cancel)]
public void ShowDialog_NonControlOwnerWithVisualStyles_ReturnsExpected(bool runDialogResultParam, DialogResult expectedDialogResultParam)
{
// Run this from another thread as we call Application.EnableVisualStyles.
RemoteExecutor.Invoke((runDialogResultString, expectedDialogResultString) =>
Task.Run(() =>
{
bool runDialogResult = bool.Parse(runDialogResultString);
DialogResult expectedDialogResult = (DialogResult)Enum.Parse(typeof(DialogResult), expectedDialogResultString);

Application.EnableVisualStyles();

using SubCommonDialog dialog = new()
try
{
RunDialogResult = runDialogResult
};
var owner = new Mock<IWin32Window>(MockBehavior.Strict);
owner
.Setup(o => o.Handle)
.Returns(IntPtr.Zero);
Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner.Object));
}, runDialogResultParam.ToString(), expectedDialogResultParam.ToString()).Dispose();
Application.EnableVisualStyles();

using SubCommonDialog dialog = new()
{
RunDialogResult = runDialogResultParam
};
var owner = new Mock<IWin32Window>(MockBehavior.Strict);
owner
.Setup(o => o.Handle)
.Returns(IntPtr.Zero);
Assert.Equal(expectedDialogResultParam, dialog.ShowDialog(owner.Object));
}
finally
{
Application.VisualStyleState = VisualStyles.VisualStyleState.NoneEnabled;
}
}).Wait();
}

[WinFormsTheory]
Expand All @@ -154,26 +156,29 @@ public void ShowDialog_ControlOwner_ReturnsExpected(bool runDialogResult, Dialog
Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner));
}

[WinFormsTheory(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")]
[WinFormsTheory]
[InlineData(true, DialogResult.OK)]
[InlineData(false, DialogResult.Cancel)]
public void ShowDialog_ControlOwnerWithVisualStyles_ReturnsExpected(bool runDialogResultParam, DialogResult expectedDialogResultParam)
{
// Run this from another thread as we call Application.EnableVisualStyles.
RemoteExecutor.Invoke((runDialogResultString, expectedDialogResultString) =>
Task.Run(() =>
{
bool runDialogResult = bool.Parse(runDialogResultString);
DialogResult expectedDialogResult = (DialogResult)Enum.Parse(typeof(DialogResult), expectedDialogResultString);

Application.EnableVisualStyles();

using SubCommonDialog dialog = new()
try
{
RunDialogResult = runDialogResult
};
using Control owner = new();
Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner));
}, runDialogResultParam.ToString(), expectedDialogResultParam.ToString()).Dispose();
Application.EnableVisualStyles();

using SubCommonDialog dialog = new()
{
RunDialogResult = runDialogResultParam
};
using Control owner = new();
Assert.Equal(expectedDialogResultParam, dialog.ShowDialog(owner));
}
finally
{
Application.VisualStyleState = VisualStyles.VisualStyleState.NoneEnabled;
}
}).Wait();
}

[WinFormsTheory]
Expand All @@ -190,27 +195,30 @@ public void ShowDialog_ControlOwnerWithHandle_ReturnsExpected(bool runDialogResu
Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner));
}

[WinFormsTheory(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")]
[WinFormsTheory]
[InlineData(true, DialogResult.OK)]
[InlineData(false, DialogResult.Cancel)]
public void ShowDialog_ControlOwnerWithHandleWithVisualStyles_ReturnsExpected(bool runDialogResultParam, DialogResult expectedDialogResultParam)
{
// Run this from another thread as we call Application.EnableVisualStyles.
RemoteExecutor.Invoke((runDialogResultString, expectedDialogResultString) =>
Task.Run(() =>
{
bool runDialogResult = bool.Parse(runDialogResultString);
DialogResult expectedDialogResult = (DialogResult)Enum.Parse(typeof(DialogResult), expectedDialogResultString);

Application.EnableVisualStyles();

using SubCommonDialog dialog = new()
try
{
Application.EnableVisualStyles();

using SubCommonDialog dialog = new()
{
RunDialogResult = runDialogResultParam
};
using Control owner = new();
Assert.NotEqual(IntPtr.Zero, owner.Handle);
Assert.Equal(expectedDialogResultParam, dialog.ShowDialog(owner));
}
finally
{
RunDialogResult = runDialogResult
};
using Control owner = new();
Assert.NotEqual(IntPtr.Zero, owner.Handle);
Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner));
}, runDialogResultParam.ToString(), expectedDialogResultParam.ToString()).Dispose();
Application.VisualStyleState = VisualStyles.VisualStyleState.NoneEnabled;
}
}).Wait();
}

[WinFormsFact]
Expand Down
Loading
Loading