Fix smoke 1차 follow-up gaps: player resolver, type target, filter, utf8 (#12)
This commit is contained in:
@@ -299,6 +299,138 @@ public class RecorderTests
|
||||
Assert.Equal(0x43u, steps[0].RawVk);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DragCollapser_TypeAfterFocusChange_InheritsTarget()
|
||||
{
|
||||
// focus_change → key_down B,O,X (no resolver result for keys).
|
||||
UiaResolution? Resolver(RawEvent ev) => null;
|
||||
const string focusPath = "MetroWindow[@AutomationId='root']/CommandPanel/TextBox[@AutomationId='CommandBox']/TextBox[@AutomationId='CB']";
|
||||
var events = new[]
|
||||
{
|
||||
new RawEvent(100, "focus_change", 0, 0, 0, 0, focusPath),
|
||||
new RawEvent(110, "key_down", 0, 0, 0x42, 0), // B
|
||||
new RawEvent(120, "key_down", 0, 0, 0x4F, 0), // O
|
||||
new RawEvent(130, "key_down", 0, 0, 0x58, 0), // X
|
||||
};
|
||||
|
||||
var steps = new DragCollapser().Collapse(events, Resolver);
|
||||
|
||||
// focus + type
|
||||
Assert.Equal(2, steps.Count);
|
||||
Assert.Equal("type", steps[1].Kind);
|
||||
Assert.Equal("BOX", steps[1].Value);
|
||||
Assert.NotNull(steps[1].Target);
|
||||
Assert.Equal(focusPath, steps[1].Target!.UiaPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DragCollapser_TypeAfterMouseDown_FallbackToMouseTarget()
|
||||
{
|
||||
var el = MakeRectElement("Canvas", 0, 0, 800, 600);
|
||||
const string mousePath = "Window[@Name='Canvas']";
|
||||
UiaResolution? Resolver(RawEvent ev) =>
|
||||
ev.Kind == "key_down" || ev.Kind == "key_up"
|
||||
? null
|
||||
: new UiaResolution(el, mousePath);
|
||||
|
||||
var events = new[]
|
||||
{
|
||||
new RawEvent(100, "mouse_down_l", 100, 100, 0, 0),
|
||||
new RawEvent(105, "mouse_up_l", 101, 101, 0, 0),
|
||||
new RawEvent(110, "key_down", 0, 0, 0x31, 0), // 1
|
||||
new RawEvent(120, "key_down", 0, 0, 0x30, 0), // 0
|
||||
};
|
||||
|
||||
var steps = new DragCollapser().Collapse(events, Resolver);
|
||||
|
||||
Assert.Equal(2, steps.Count);
|
||||
Assert.Equal("click", steps[0].Kind);
|
||||
Assert.Equal("type", steps[1].Kind);
|
||||
Assert.Equal("10", steps[1].Value);
|
||||
Assert.NotNull(steps[1].Target);
|
||||
Assert.Equal(mousePath, steps[1].Target!.UiaPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WindowFilter_ExternalCoord_DropsEvent()
|
||||
{
|
||||
// SUT pid is 42. Mouse event at (10,10) belongs to pid 99 → drop.
|
||||
var filter = new SutProcessWindowFilter(
|
||||
sutPid: 42,
|
||||
processFromPoint: (_, _) => 99,
|
||||
processFromForeground: () => 99);
|
||||
|
||||
var ev = new RawEvent(0, "mouse_down_l", 10, 10, 0, 0);
|
||||
Assert.False(filter.ShouldKeep(ev));
|
||||
|
||||
var key = new RawEvent(0, "key_down", 0, 0, 0x42, 0);
|
||||
Assert.False(filter.ShouldKeep(key));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WindowFilter_SutCoord_KeepsEvent()
|
||||
{
|
||||
var filter = new SutProcessWindowFilter(
|
||||
sutPid: 42,
|
||||
processFromPoint: (_, _) => 42,
|
||||
processFromForeground: () => 42);
|
||||
|
||||
Assert.True(filter.ShouldKeep(new RawEvent(0, "mouse_down_l", 10, 10, 0, 0)));
|
||||
Assert.True(filter.ShouldKeep(new RawEvent(0, "key_down", 0, 0, 0x42, 0)));
|
||||
// Unknown pid (0) is permissively kept to avoid false drops.
|
||||
var permissive = new SutProcessWindowFilter(
|
||||
sutPid: 42,
|
||||
processFromPoint: (_, _) => 0,
|
||||
processFromForeground: () => 0);
|
||||
Assert.True(permissive.ShouldKeep(new RawEvent(0, "mouse_down_l", 1, 1, 0, 0)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScenarioWriter_RoundTrip_PreservesKorean()
|
||||
{
|
||||
var s = new Scenario
|
||||
{
|
||||
Name = "한글-시나리오",
|
||||
Description = "회귀 테스트 — 새 파일",
|
||||
Steps =
|
||||
{
|
||||
new ScenarioStep
|
||||
{
|
||||
Kind = "click",
|
||||
Target = new ScenarioTarget
|
||||
{
|
||||
UiaPath = "MetroWindow[@AutomationId='root']/Button[@Name='새 파일']",
|
||||
Offset = new[] { 0.5, 0.5 },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
var tmp = Path.Combine(Path.GetTempPath(), $"recordingtest-utf8-{System.Guid.NewGuid():N}.yaml");
|
||||
try
|
||||
{
|
||||
ScenarioWriter.WriteToFile(s, tmp);
|
||||
|
||||
// No BOM at byte 0.
|
||||
var bytes = File.ReadAllBytes(tmp);
|
||||
Assert.True(bytes.Length >= 3);
|
||||
Assert.False(bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF,
|
||||
"ScenarioWriter must emit UTF-8 without BOM");
|
||||
|
||||
var text = File.ReadAllText(tmp, System.Text.Encoding.UTF8);
|
||||
var parsed = ScenarioWriter.Deserialize(text);
|
||||
|
||||
Assert.Equal(s.Name, parsed.Name);
|
||||
Assert.Equal(s.Description, parsed.Description);
|
||||
Assert.Equal("MetroWindow[@AutomationId='root']/Button[@Name='새 파일']",
|
||||
parsed.Steps[0].Target!.UiaPath);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(tmp)) File.Delete(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Cli_MissingAttach_ExitTwo()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user