Skip to content

Commit c37eaf0

Browse files
committed
remove smaller tests
1 parent 3bc472b commit c37eaf0

6 files changed

Lines changed: 177 additions & 383 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) Microsoft Corporation
2+
// The Microsoft Corporation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using FormsClipboard = System.Windows.Forms.Clipboard;
6+
7+
namespace Microsoft.PowerToys.UITest.Next;
8+
9+
/// <summary>
10+
/// Clipboard helpers that always execute on an STA thread (<see cref="FormsClipboard"/>
11+
/// requires it). Tolerant — every method swallows clipboard errors and returns a default,
12+
/// so callers can use them in test <c>finally</c> blocks without worrying about masking
13+
/// the real failure.
14+
/// </summary>
15+
public static class ClipboardHelper
16+
{
17+
/// <summary>Return the current clipboard text, or <see cref="string.Empty"/> if none / on error.</summary>
18+
public static string GetText() => RunSTA(() => FormsClipboard.ContainsText() ? FormsClipboard.GetText() : string.Empty) ?? string.Empty;
19+
20+
/// <summary>Clear the clipboard. Returns true on success, false on error.</summary>
21+
public static bool Clear() => RunSTA(() => { FormsClipboard.Clear(); return true; });
22+
23+
/// <summary>Set the clipboard text. Returns true on success, false on error.</summary>
24+
public static bool SetText(string value) => RunSTA(() => { FormsClipboard.SetText(value); return true; });
25+
26+
/// <summary>
27+
/// Poll the clipboard up to <paramref name="timeoutMS"/> for the first non-empty text
28+
/// different from <paramref name="ignoredValue"/>. Returns <see cref="string.Empty"/> on
29+
/// timeout. Use when you've just cleared the clipboard and are waiting for an external
30+
/// app (e.g. ColorPicker on click) to write into it.
31+
/// </summary>
32+
public static string WaitForText(string ignoredValue = "", int timeoutMS = 3_000, int pollIntervalMS = 100)
33+
{
34+
var deadline = DateTime.UtcNow + TimeSpan.FromMilliseconds(timeoutMS);
35+
while (DateTime.UtcNow < deadline)
36+
{
37+
var text = GetText();
38+
if (!string.IsNullOrEmpty(text) && text != ignoredValue)
39+
{
40+
return text;
41+
}
42+
43+
Thread.Sleep(pollIntervalMS);
44+
}
45+
46+
return string.Empty;
47+
}
48+
49+
private static T? RunSTA<T>(Func<T> body)
50+
{
51+
T? result = default;
52+
try
53+
{
54+
var thread = new Thread(() =>
55+
{
56+
try
57+
{
58+
result = body();
59+
}
60+
catch
61+
{
62+
// Best effort — clipboard can throw under contention (OpenClipboard failures).
63+
}
64+
});
65+
thread.SetApartmentState(ApartmentState.STA);
66+
thread.Start();
67+
thread.Join(TimeSpan.FromSeconds(5));
68+
}
69+
catch
70+
{
71+
}
72+
73+
return result;
74+
}
75+
}

src/modules/colorPicker/ColorPickerUI/Views/MainView.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626
</Border.Effect>-->
2727

2828
<Grid>
29+
<!--
30+
UIA test hook. Mirrors the displayed HEX value (ColorText) into a
31+
transparent TextBlock with a stable AutomationId so automated UI tests
32+
can read the picker's current color without depending on the visible
33+
TextBlock, whose AutomationProperties.Name is bound to ColorName (the
34+
friendly name) for screen-reader UX and therefore masks the HEX from UIA.
35+
-->
36+
<TextBlock
37+
x:Name="ColorHexAutomationPeer"
38+
AutomationProperties.AutomationId="ColorHexAutomationPeer"
39+
IsHitTestVisible="False"
40+
Opacity="0"
41+
Text="{Binding ColorText}" />
42+
2943
<!-- only color format - one line -->
3044
<Grid Margin="2" Visibility="{Binding ShowColorName, Converter={StaticResource bool2InvertedVisibilityConverter}}">
3145
<Grid.ColumnDefinitions>

src/modules/colorPicker/UITest-ColorPicker.Next/ColorPickerEditorTests.cs

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)