ui::testing::HeadlessWindowHost¶
Header: winui/testing/HeadlessUI.hpp.
The in-memory window host HeadlessUI installs. It follows the same window-state rules as the real host without a native window, so window-state and title-bar tests can drive it.
- Requests apply synchronously by default. Set
defer_requeststo queue them instead, so a test can observe the gap between a request and the system's answer, then call apply_pending_requests() to let them land. - simulate_state() is the other direction: the user clicking the caption's maximize button, or Win+Down. It reports the new state without anyone having asked.
- Everything the window sends the host is recorded, and click_system_menu_item() and click_thumbnail_button() stand in for the user picking an entry.
Like the real host, it remembers the normal bounds across minimize and maximize, and whether full screen was entered from maximized, so restore() goes back to the right place.
Example:
ui::testing::HeadlessUI ui;
ui::Window& window = ui.window();
ui.host().defer_requests = true;
window.request_state(ui::WindowState::Maximized);
REQUIRE(window.state().get() == ui::WindowState::Normal); // asked, not yet answered
ui.host().apply_pending_requests();
REQUIRE(window.state().get() == ui::WindowState::Maximized);
window.set_system_menu({{.text = "Always on top", .on_click = [&] { /* ... */ }}});
REQUIRE(ui.host().click_system_menu_item(0));
window.close();
REQUIRE(ui.host().close_requests == 1);
defer_requests¶
When true, requests are queued instead of applied (see the class comment).
normal_bounds¶
The bounds a restore to Normal lands on, and what bounds() reports.
frame¶
What the frame takes around the client area, for resize() and the size limits.
screen_work_area¶
What work_area() reports.
close_requests¶
How many times close() was called.
style_applications¶
How many times set_style() was called.
activations¶
How many times activate() ran.
wake_requests¶
How many times wake() was called; atomic since wake() may come from any thread.
HeadlessWindowHost¶
A host for window, which must outlive it. Does not install itself; HeadlessUI does.
~HeadlessWindowHost¶
HeadlessWindowHost¶
operator=¶
request_state¶
Applies state at once and reports it back, or queues it while defer_requests is set.
restore¶
Leaves Minimized/Maximized/Fullscreen for the state it came from; queued like request_state() while defer_requests is set.
close¶
Only counts the request in close_requests; the window is not destroyed.
wake¶
Only counts the request in wake_requests; safe from any thread.
set_title¶
Records the title for title().
set_style¶
Records the style for style() and counts it in style_applications.
set_chrome¶
Records the chrome overrides for chrome().
placement¶
normal_bounds, the current state, and whether a restore would go back to Maximized.
set_icon¶
Records only whether there is an icon (has_icon()).
set_system_menu¶
Records the entries' texts, checks and enabled states for click_system_menu_item().
set_taskbar_progress¶
Records the progress for taskbar_progress().
set_taskbar_overlay¶
Records whether there is an overlay and its description.
request_attention¶
Records the flash request for flashing().
set_thumbnail_buttons¶
Fixes the button count on the first call (at most 7), as the taskbar does. Later calls only update which of those buttons are clickable.
move¶
Moves normal_bounds to position.
resize¶
Resizes normal_bounds so its client part, less frame, is size, clamped to the size limits.
bounds¶
Always normal_bounds.
work_area¶
Always screen_work_area.
set_visible¶
Reports visibility to the window, and activates it when asked to.
activate¶
Counts the activation in activations and reports the window active.
set_size_limits¶
Records the client size limits and re-clamps the current size, as a real host does.
apply_pending_requests¶
Applies every queued request in order, reporting each resulting state.
pending_request_count¶
How many requests are queued while defer_requests is set.
simulate_state¶
A change the user makes from outside the app. Reports state and, while not minimized, remembers it for restore().
simulate_active¶
The user activating another window, or coming back.
simulate_caption_insets¶
Reports the caption-button insets of an extended title bar, as the system would.
click_system_menu_item¶
Picks the app's system-menu entry index, as the user would. False if the host was never given that many entries.
click_thumbnail_button¶
Clicks thumbnail button index. False if it doesn't exist, or is disabled or hidden.
title¶
The last title set_title() was given.
style¶
The last style set_style() was given.
chrome¶
The last chrome overrides set_chrome() was given.
has_icon¶
Whether the last set_icon() passed an icon.
system_menu_texts¶
The system menu entries' texts, in order; empty text is a separator.
system_menu_checks¶
The system menu entries' check marks, parallel to system_menu_texts().
taskbar_progress¶
The last taskbar progress set.
has_overlay¶
Whether a taskbar overlay icon is set.
overlay_description¶
The overlay's accessible description.
flashing¶
Whether the last request_attention() asked to flash.
thumbnail_button_count¶
How many buttons the taskbar holds, fixed by the first set_thumbnail_buttons() call.
min_size¶
The minimum client size last set; zero on an axis is none.
max_size¶
The maximum client size last set; zero on an axis is none.