-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
WindowDecorationsTests.cs
237 lines (195 loc) · 8.35 KB
/
WindowDecorationsTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
using System;
using System.Threading;
using Xunit;
namespace Avalonia.IntegrationTests.Appium;
[Collection("WindowDecorations")]
public class WindowDecorationsTests : TestBase, IDisposable
{
public WindowDecorationsTests(DefaultAppFixture fixture)
: base(fixture, "Window Decorations")
{
}
[Fact]
public void Window_Size_Should_Be_Consistent_Between_Toggles()
{
var window = Session.FindElementByAccessibilityId("MainWindow");
var original = window.Size;
// Step 1: keep extend client area to false, but adjust some value that should not have any effect.
SetParameters(false, false, false, false, 10);
ApplyToCurrentWindow();
Assert.Equal(original, window.Size);
// Step 2: enable and disable extended system chrome.
SetParameters(true, true, false, false, 20);
ApplyToCurrentWindow();
SetParameters(false, false, false, false, 20);
ApplyToCurrentWindow();
Assert.Equal(original, window.Size);
// Step 3: enable and disable extended client chrome.
SetParameters(true, false, true, false, 30);
ApplyToCurrentWindow();
SetParameters(false, false, true, false, 20);
ApplyToCurrentWindow();
Assert.Equal(original, window.Size);
}
[Fact]
public void Can_Restore_To_Non_Extended_State()
{
SetParameters(true, true, false, false, 20);
ApplyToCurrentWindow();
SetParameters(false, false, false, false, 1000);
ApplyToCurrentWindow();
var currentWindow = Session.GetCurrentSingleWindow();
var systemChrome = currentWindow.GetSystemChromeButtons();
var clientChrome = currentWindow.GetClientChromeButtons();
AssertSystemChrome(systemChrome, clientChrome, false);
var props = Session.FindElementByAccessibilityId("WindowDecorationProperties");
Assert.Equal($"0 0 False", props.Text);
}
[PlatformTheory(TestPlatforms.Windows)] // We don't have client chrome on macOS
[InlineData(-1)]
[InlineData(25)]
[InlineData(50)]
public void Should_Apply_Client_Chrome(int titleBarHeight)
{
SetParameters(true, false, true, false, titleBarHeight);
ApplyToCurrentWindow();
Thread.Sleep(500);
var currentWindow = Session.GetCurrentSingleWindow();
var systemChrome = currentWindow.GetSystemChromeButtons();
var clientChrome = currentWindow.GetClientChromeButtons();
AssertClientChrome(systemChrome, clientChrome, titleBarHeight);
var props = Session.FindElementByAccessibilityId("WindowDecorationProperties");
if (titleBarHeight > 0)
{
Assert.Equal($"0 {titleBarHeight} True", props.Text);
}
}
[Theory]
[InlineData(-1)]
[InlineData(25)]
[InlineData(50)]
public void Should_Apply_System_Chrome(int titleBarHeight)
{
SetParameters(true, true, false, false, titleBarHeight);
ApplyToCurrentWindow();
Thread.Sleep(500);
var currentWindow = Session.GetCurrentSingleWindow();
var systemChrome = currentWindow.GetSystemChromeButtons();
var clientChrome = currentWindow.GetClientChromeButtons();
AssertSystemChrome(systemChrome, clientChrome, true);
var props = Session.FindElementByAccessibilityId("WindowDecorationProperties");
if (titleBarHeight > 0)
{
Assert.Equal($"0 {titleBarHeight} True", props.Text);
}
}
[PlatformTheory(TestPlatforms.Windows)] // We don't have client chrome on macOS
[InlineData(-1)]
[InlineData(25)]
[InlineData(50)]
public void Should_Apply_Client_Chrome_On_New_Window(int titleBarHeight)
{
SetParameters(true, false, true, false, titleBarHeight);
using (ApplyOnNewWindow())
{
Thread.Sleep(500);
var secondaryWindow = Session.GetWindowById("SecondaryWindow");
var systemChrome = secondaryWindow.GetSystemChromeButtons();
var clientChrome = secondaryWindow.GetClientChromeButtons();
AssertClientChrome(systemChrome, clientChrome, titleBarHeight);
}
}
[PlatformTheory(TestPlatforms.MacOS)] // fix me, for some reason Windows doesn't return TitleBar system chrome for a child window.
[InlineData(-1)]
[InlineData(25)]
[InlineData(50)]
public void Should_Apply_System_Chrome_On_New_Window(int titleBarHeight)
{
SetParameters(true, true, false, false, titleBarHeight);
using (ApplyOnNewWindow())
{
Thread.Sleep(500);
var secondaryWindow = Session.GetWindowById("SecondaryWindow");
var systemChrome = secondaryWindow.GetSystemChromeButtons();
var clientChrome = secondaryWindow.GetClientChromeButtons();
AssertSystemChrome(systemChrome, clientChrome, true);
}
}
private void AssertClientChrome(WindowChrome systemChrome, WindowChrome clientChrome, int titleBarHeight)
{
// Ignore windows, it always reports full sized and enabled buttons and title bar. Just drawn behind.
if (!OperatingSystem.IsWindows())
{
// All system chrome buttons are hidden.
Assert.False(systemChrome.IsAnyButtonEnabled);
Assert.Equal(-1, systemChrome.MaxButtonHeight);
Assert.True(systemChrome.TitleBarHeight is -1 or 0);
}
// At least some client chrome buttons are shown.
Assert.True(clientChrome.IsAnyButtonEnabled);
Assert.True(clientChrome.MaxButtonHeight > 0);
if (titleBarHeight != -1)
{
Assert.Equal(titleBarHeight, clientChrome.TitleBarHeight);
}
}
private void AssertSystemChrome(WindowChrome systemChrome, WindowChrome clientChrome, bool isExtended)
{
// At least some server chrome buttons are shown.
Assert.True(systemChrome.IsAnyButtonEnabled);
Assert.True(systemChrome.MaxButtonHeight > 0);
// All client chrome buttons are hidden.
Assert.False(clientChrome.IsAnyButtonEnabled);
Assert.Equal(-1, clientChrome.MaxButtonHeight);
// System chrome is always 0px height, when client area is extended.
if (isExtended)
{
Assert.True(systemChrome.TitleBarHeight is -1 or 0);
}
// Can't get titlebar height on macOS.
else if (!OperatingSystem.IsMacOS())
{
Assert.True(systemChrome.TitleBarHeight > 0);
}
}
private void SetParameters(
bool extendClientArea,
bool forceSystemChrome,
bool preferSystemChrome,
bool macOsThickSystemChrome,
int titleBarHeight)
{
var extendClientAreaCheckBox = Session.FindElementByAccessibilityId("WindowExtendClientAreaToDecorationsHint");
var forceSystemChromeCheckBox = Session.FindElementByAccessibilityId("WindowForceSystemChrome");
var preferSystemChromeCheckBox = Session.FindElementByAccessibilityId("WindowPreferSystemChrome");
var macOsThickSystemChromeCheckBox = Session.FindElementByAccessibilityId("WindowMacThickSystemChrome");
var titleBarHeightBox = Session.FindElementByAccessibilityId("WindowTitleBarHeightHint");
if (extendClientAreaCheckBox.GetIsChecked() != extendClientArea)
extendClientAreaCheckBox.Click();
if (forceSystemChromeCheckBox.GetIsChecked() != forceSystemChrome)
forceSystemChromeCheckBox.Click();
if (preferSystemChromeCheckBox.GetIsChecked() != preferSystemChrome)
preferSystemChromeCheckBox.Click();
if (macOsThickSystemChromeCheckBox.GetIsChecked() != macOsThickSystemChrome)
macOsThickSystemChromeCheckBox.Click();
titleBarHeightBox.Click();
titleBarHeightBox.Clear();
if (titleBarHeight >= 0)
titleBarHeightBox.SendKeys(titleBarHeight.ToString());
}
private void ApplyToCurrentWindow()
{
var applyWindowDecorations = Session.FindElementByAccessibilityId("ApplyWindowDecorations");
applyWindowDecorations.Click();
}
private IDisposable ApplyOnNewWindow()
{
var showNewWindowDecorations = Session.FindElementByAccessibilityId("ShowNewWindowDecorations");
return showNewWindowDecorations.OpenWindowWithClick();
}
public void Dispose()
{
SetParameters(false, false, false, false, -1);
ApplyToCurrentWindow();
}
}