RunicTestHostedWindow class

Namespace Runic.Application.Testing in Runic.Application.Testing 0.23.0

public sealed class RunicTestHostedWindow

A window a guest asked a RunicTestHost for.

Properties

AcceptsFileDrops

public bool AcceptsFileDrops { get; }

Whether the guest's Window takes dropped files (window-open's fileDrops).

Closed

public Task Closed { get; }

Completes when the guest closed the window.

DialogRequests

public IReadOnlyList<RunicTestDialogRequest> DialogRequests { get; }

The file dialogs, message boxes and context menus the guest asked for in this window, in order.

Features

public RunicWindowPresentationFeatures Features { get; }

What the window can do, as its window-open reply listed it (RunicTestHostOptions.WindowFeatures). A presentation request whose feature is missing is answered unavailable.

FrameIsSameSite

public bool FrameIsSameSite { get; }

Whether the guest served the latest RunicTestHostedWindow.AttachRegionAsync's frame from the embedder's own site (frame.sameSite).

GuardsClose

public bool GuardsClose { get; }

Whether the Window decides about its close, so a user close asks it first.

Height

public int? Height { get; }

The requested height of the window's content, if any.

Id

public string Id { get; }

The guest's id for the window.

IsAttached

public bool IsAttached { get; }

Whether a region shows the window now: from RunicTestHostedWindow.AttachRegionAsync until RunicTestHostedWindow.DetachRegionAsync.

IsClosed

public bool IsClosed { get; }

Whether the guest closed the window (window-closed), or it was refused.

IsModal

public bool IsModal { get; }

Whether the window is modal to its owner.

IsRegion

public bool IsRegion { get; }

Whether the window shows in a region of a host page (region/1) instead of a window of its own, as RunicTestHostOptions.EmbedWindow chose. Its page loads only from the frame launch address of RunicTestHostedWindow.AttachRegionAsync; its RunicTestHostedWindow.LaunchUrl admits nobody.

LaunchRequests

public IReadOnlyList<RunicTestLaunchRequest> LaunchRequests { get; }

The files and links the guest asked the host to open for this window, in order.

LaunchUrl

public Uri LaunchUrl { get; }

The page's one-time launch address. The first request with it binds the guest's surface to that browser, as the host's window would be: open it in the browser under test, once.

Locale

public string? Locale { get; }

The guest Window's locale, as its window-open named it, or null.

public JsonElement? MenuBar { get; }

The window's menu bar as the guest sent it (menus/1): an array of submenu entries with their items' current titles, ids, shortcuts and states, or null for none.

Remarks

An item entry has kind item, id, title, shortcut, enabled and checked; a submenu has kind submenu, title, role, enabled and items. RunicTestHostedWindow.FindMenuItem finds an item by its titles.

Opened

public Task Opened { get; }

Completes when the test host sent the successful window-open reply, after which the guest treats the window as open; cancelled when the window was refused. A window that RunicTestHost.Windows lists has been answered.

OwnerId

public string? OwnerId { get; }

The id of the guest's window that owns this one, or null.

PresentationRequests

public IReadOnlyList<RunicTestPresentationRequest> PresentationRequests { get; }

The presentation requests the guest sent for the window, in order.

Refused

public bool Refused { get; }

Whether RunicTestHostOptions.OpenWindow refused the window.

RegionPages

public IReadOnlyList<string> RegionPages { get; }

The guest's reports about the page that its frame admitted, in order (region-page): connected, disconnected or revoked.

Titles

public IReadOnlyList<string> Titles { get; }

The titles the guest sent for its page in the region (set-title), in order.

Type

public string Type { get; }

The Window type, as the serve-only window line names it.

Width

public int? Width { get; }

The requested width of the window's content, if any.

Methods

AttachComponentAsync

public Task<RunicTestComponent> AttachComponentAsync(string embedder, bool allowSameSite = true, CancellationToken cancellationToken = default)

Attaches the region window as a component (region-component/1, trusted component mode): the guest answers its component module, its WebSocket address and a new component token, for a host page whose origin is embedder. Needs region-component/1 in RunicTestHostOptions.Features, a guest that allows component embedding (RunicGuestOptions.AllowComponentEmbedding) and its component build.

Parameters

embedder

The origin of the host page that loads the component, such as http://127.0.0.1:5173.

allowSameSite

Whether the guest may serve the component from the embedder's own site, as Runic's embedded hosts allow; without it, a component for a 127.0.0.1 page comes from [::1].

cancellationToken

Cancels the wait for the reply.

Returns

The module, WebSocket address and token: import Module in the page, create the element named by its tag export and call its connect({ url, token }), as <runic-hosted-region> does.

Exceptions

InvalidOperationException

The window is not a region window, or the guest refused the attach.

AttachRegionAsync

public Task<Uri> AttachRegionAsync(string embedder, int width = 800, int height = 600, double scale = 1, string sizing = "fill", bool allowSameSite = false, CancellationToken cancellationToken = default)

Attaches a region window to a region of a host page, as a host does when the page shows the region (region-attach), and returns the guest's one-time frame launch address. Load it once, in an <iframe> of a page of embedder: the guest lets no other origin frame its page, and a second load revokes the page's token. An attached window is detached first, by the guest.

Parameters

embedder

The origin of the host page that frames the guest's page: http://127.0.0.1:, http://[::1]: or http://localhost: and a port, nothing after it.

width

The region's width in CSS pixels.

height

The region's height in CSS pixels.

scale

The host page's device pixel ratio.

sizing

fill, or content-height for a region that takes the height the guest's page asks for with resize, which the test host then answers with success.

allowSameSite

Whether the guest may serve the frame from the embedder's own site where it cannot listen on the other loopback family.

cancellationToken

Cancels the wait for the reply.

Returns

The frame launch address (frame.url).

Exceptions

InvalidOperationException

The window is not a region window, or the guest refused the attach.

DetachRegionAsync

public Task DetachRegionAsync(string reason = "removed", CancellationToken cancellationToken = default)

Detaches the region, as a host does when its page removed the region (region-detach): the guest revokes the frame's address and token and disconnects its page; the Window stays open.

Parameters

reason

removed, reload, crashed or host.

cancellationToken

Cancels sending.

Returns

A task that completes when the push was sent.

DropFilesAsync

public Task DropFilesAsync(IReadOnlyList<string> paths, string? target = null, CancellationToken cancellationToken = default)

Drops files onto the window, as the user does: the guest's Window receives them (files-dropped), when it takes dropped files (RunicTestHostedWindow.AcceptsFileDrops).

Parameters

paths

The absolute paths of the dropped files and directories.

target

The page's routing label (data-runic-drop-target), or null.

cancellationToken

Cancels sending.

Returns

A task that completes when the push was sent.

Exceptions

ArgumentException

paths is empty or has a path that is not absolute.

InvalidOperationException

The window does not take dropped files, or window-services/1 is not in use.

FindMenuItem

public string? FindMenuItem(params string[] titles)

Finds the id of an item of the window's menu bar by the titles of its menus and its own, such as ("File", "Save").

Parameters

titles

The titles, from the bar's menu to the item.

Returns

The item's id, or null when the bar has no such item.

FindMenuItem

public static string? FindMenuItem(JsonElement menu, params string[] titles)

Finds the id of an item of a menu, such as a context menu's menu member, by its titles.

Parameters

menu

An array of menu entries.

titles

The titles, from the first level to the item.

Returns

The item's id, or null when the menu has no such item.

FocusRegionAsync

public Task FocusRegionAsync(string direction = "forward", CancellationToken cancellationToken = default)

Moves the keyboard focus into the region, as the host does for Tab, Shift+Tab or its own move (region-focus enter): the guest's page focuses its first, last or last focused element.

Parameters

direction

forward, backward or programmatic.

cancellationToken

Cancels sending.

Returns

A task that completes when the push was sent.

InvokeMenuItemAsync

public Task InvokeMenuItemAsync(string itemId, CancellationToken cancellationToken = default)

Chooses an item of the window's menu bar as the host's user would, or presses its shortcut: pushes menu-invoke, and the guest runs the item's command through the Window's command path.

Parameters

itemId

The item's id, such as from RunicTestHostedWindow.FindMenuItem.

cancellationToken

Cancels sending.

Returns

A task that completes when the push was sent.

RequestCloseAsync

public Task<bool> RequestCloseAsync(bool force = false, CancellationToken cancellationToken = default)

Closes the window as its user would: sends close-request and returns the guest's decision.

Parameters

force

Whether the host closes it whatever the guest decides.

cancellationToken

Cancels the wait for the decision.

Returns

Whether the guest allowed the close; it then closes the Window and RunicTestHostedWindow.Closed completes.

SetActivityAsync

public Task SetActivityAsync(RunicWindowActivity activity, CancellationToken cancellationToken = default)

Reports the window's activity to the guest, as the activity push does.

Parameters

activity

Whether the window is active, minimized and visible.

cancellationToken

Cancels sending.

Returns

A task that completes when the push was sent.

SetColorSchemeAsync

public Task SetColorSchemeAsync(DesktopColorScheme colorScheme, CancellationToken cancellationToken = default)

Reports the window's colour scheme to the guest, as the color-scheme push does after the user or the host changed it.

Parameters

colorScheme

The window's colour scheme.

cancellationToken

Cancels sending.

Returns

A task that completes when the push was sent.

SetPlacementAsync

public Task SetPlacementAsync(RunicWindowPlacement placement, CancellationToken cancellationToken = default)

Reports the window's placement to the guest, as the placement push does after the user moved, resized or maximized it: the bounds it restores to, which the guest's IRunicWindowPresentation.Placement reports, also as its current frame.

Parameters

placement

The bounds the window restores to and whether it is maximized or full-screen.

cancellationToken

Cancels sending.

Returns

A task that completes when the push was sent.

SetRegionBoundsAsync

public Task SetRegionBoundsAsync(int width, int height, double scale = 1, CancellationToken cancellationToken = default)

Reports the region's new size and scale to the guest (region-bounds).

Parameters

width

The region's width in CSS pixels.

height

The region's height in CSS pixels.

scale

The host page's device pixel ratio.

cancellationToken

Cancels sending.

Returns

A task that completes when the push was sent.

WaitForMenuBarAsync

public Task<JsonElement> WaitForMenuBarAsync(Func<JsonElement, bool> match, TimeSpan timeout, CancellationToken cancellationToken = default)

Waits until match accepts the window's menu bar, such as one with a German title.

Parameters

match

Decides about the bar, RunicTestHostedWindow.MenuBar.

timeout

How long to wait.

cancellationToken

Cancels the wait.

Returns

The bar that matched.

Exceptions

TimeoutException

No bar matched in time.

InvalidOperationException

An answer of RunicTestHostOptions failed before.