Skip to content

Commit f69cb4c

Browse files
shanselmanCopilot
andcommitted
test(a11y): prove composer UIA recovery
Co-authored-by: Copilot App <[email protected]>
1 parent d006167 commit f69cb4c

3 files changed

Lines changed: 56 additions & 20 deletions

File tree

‎src/OpenClaw.Tray.WinUI/Chat/OpenClawReactorChatRoot.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,7 @@ public static void Prepare(FrameworkElement control)
19671967
Detach(control);
19681968
if (HasUsableLayout(control))
19691969
{
1970-
Enable(control);
1970+
ApplyReadyState(control);
19711971
return;
19721972
}
19731973

@@ -1996,10 +1996,10 @@ private static void TryEnableHitTesting(object sender)
19961996
if (sender is not FrameworkElement control || !HasUsableLayout(control))
19971997
return;
19981998

1999-
Enable(control);
1999+
ApplyReadyState(control);
20002000
}
20012001

2002-
private static void Enable(FrameworkElement control)
2002+
private static void ApplyReadyState(FrameworkElement control)
20032003
{
20042004
Microsoft.UI.Xaml.Automation.AutomationProperties.SetAccessibilityView(
20052005
control,

‎tests/OpenClaw.Tray.UITests/AccessibilityScanTests.cs‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Collections.Generic;
2+
using System.Diagnostics;
23
using System.Threading.Tasks;
4+
using System.Windows.Automation;
35
using Axe.Windows.Core.Enums;
46
using Xunit;
57

@@ -71,4 +73,54 @@ public async Task Page_PassesAccessibilityScan(
7173
exclusions,
7274
context: pageName);
7375
}
76+
77+
[Fact]
78+
[Trait("Category", "Accessibility")]
79+
public async Task ChatComposerControls_ExposeOnscreenLayoutThroughUia()
80+
{
81+
await _app.NavigateAsync("chat", "ChatComposerInput");
82+
var hub = AutomationElement.FromHandle(_app.HubWindowHandle);
83+
foreach (var automationId in new[]
84+
{
85+
"ChatComposerInput",
86+
"ChatComposerAttach",
87+
"ChatComposerSpeakerToggle",
88+
})
89+
{
90+
var element = await WaitForOnscreenLayoutAsync(hub, automationId);
91+
Assert.False(element.Current.IsOffscreen);
92+
Assert.True(element.Current.BoundingRectangle.Width > 0);
93+
Assert.True(element.Current.BoundingRectangle.Height > 0);
94+
}
95+
}
96+
97+
private static async Task<AutomationElement> WaitForOnscreenLayoutAsync(
98+
AutomationElement hub,
99+
string automationId)
100+
{
101+
var timeout = Stopwatch.StartNew();
102+
while (timeout.Elapsed < TimeSpan.FromSeconds(5))
103+
{
104+
var element = hub.FindFirst(
105+
TreeScope.Descendants,
106+
new PropertyCondition(
107+
AutomationElement.AutomationIdProperty,
108+
automationId));
109+
if (element is not null)
110+
{
111+
var bounds = element.Current.BoundingRectangle;
112+
if (!element.Current.IsOffscreen
113+
&& bounds.Width > 0
114+
&& bounds.Height > 0)
115+
{
116+
return element;
117+
}
118+
}
119+
120+
await Task.Delay(50);
121+
}
122+
123+
throw new TimeoutException(
124+
$"Composer control '{automationId}' did not expose onscreen nonzero UIA bounds.");
125+
}
74126
}

‎tests/OpenClaw.Tray.UITests/ReactorComposerAccessibilityProofTests.cs‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public sealed class ReactorComposerAccessibilityProofTests
1414
public ReactorComposerAccessibilityProofTests(UIThreadFixture ui) => _ui = ui;
1515

1616
[Fact]
17-
public async Task ComposerAutomationVisibility_GatesHitTestingUntilLayoutIsUsable()
17+
public async Task ComposerAutomationVisibility_PreventsHitTestingBeforeLayoutIsUsable()
1818
{
1919
await _ui.ResetContainerAsync();
2020
Border? control = null;
@@ -37,22 +37,7 @@ await _ui.RunOnUIAsync(() =>
3737
Assert.Equal(
3838
"ComposerReady",
3939
AutomationProperties.GetAutomationId(control));
40-
_ui.Container.Children.Add(control);
41-
});
42-
await _ui.YieldToRenderAsync();
4340

44-
await _ui.RunOnUIAsync(() =>
45-
{
46-
Assert.True(control!.IsLoaded);
47-
Assert.True(control.ActualWidth > 0);
48-
Assert.True(control.ActualHeight > 0);
49-
Assert.True(control.IsHitTestVisible);
50-
Assert.Equal(
51-
AccessibilityView.Control,
52-
AutomationProperties.GetAccessibilityView(control));
53-
Assert.Equal(
54-
"ComposerReady",
55-
AutomationProperties.GetAutomationId(control));
5641
});
5742
}
5843
finally
@@ -62,7 +47,6 @@ await _ui.RunOnUIAsync(() =>
6247
await _ui.RunOnUIAsync(() =>
6348
{
6449
ComposerAutomationVisibility.Detach(control);
65-
_ui.Container.Children.Remove(control);
6650
});
6751
}
6852
}

0 commit comments

Comments
 (0)