Task: 2026/11/16/deliver-widget-cursor-selection-right-click-and-finger-claim-as-messages
9.4 KiB
test_chat_menu
Type: Harness API (may include self-tests).
Source contract: test_chat_menu.h.
Use when
Attribute chat-list context menus to the exact message. Read the contract below and the source header before use. A menu the list builds on a later turn - a right click on a widget card - is read with the three-call form: Menus built on a later turn.
Contract and usage
The chat-list context-menu reader, OpenChatListContextMenu(list, target, point) (input helpers), in a module of its own because it depends on history
view types, which test_menu.h does not: ChatListMenuReading (the
underlying ContextMenuReading, with its menu pointer cleared on every
refusal; the requested message and the list's own view of it; the four
ChatListResolutions; enterSent, leaveSent, menuRead, observed,
listMenu, menuHidden, deferred, sentAt, waited and attributed;
built(), never true on default state; pending(), a delivered request not
decided yet), the fourteen refusals ChatListMenuRefusalName names, and
ChatListMenuDetails, which prints recorded values only. The private state it
reads - _mouseActive, _dragStateItem, _overElement, _overItemExact,
the visible message area, _menu and HistoryInner::hasPendingResizedItems()
- goes through the test-only explicit-instantiation accessor
test_notify_override.cppuses, confined totest_chat_menu.cpp: no production accessor, no pixel scan, no registry. Its own self-test,AppendChatListMenuSelfTest, in twelve stages, needs a logged-in session and a Saved Messages history whose folder is known. It injects two fixed plain-text outgoing messages A and B there, a private fixture added withHistory::addNewMessageand ids fromData::Session::nextNonHistoryEntryId() - regular and so selectable, nothing sent, "Select" the only entry ever
triggered - and keeps the main window minimized with
KeepMainWindowNotMarkingReadfrom before the injection until both are destroyed. On the legacyHistoryInner, and then on theHistoryView::ListWidgetof aHistoryView::ChatWidgetopened through theuse-modern-chat-viewoption: a premise arm (A resolved last, the mouse outside the list, the window inactive throughClearWindowActive, and an unprotectedOpenContextMenuat B's point that the list resolved to A or to none, never to B, read at build through the observer); the protected reading for B under the same conditions, built and attributed to B; "Select" from it leaving exactly B selected (HistoryInner::getSelectedItems(),ListWidget::getSelectedIds()); B requested at A's point refusedwrong-targetwith A in its details, its menu hidden, and "Select" through it refusedmenu-gonewith the selection unchanged;no-list,not-a-chat-listandoutside-viewportcontrols; and an active control throughForceWindowActive, the window still minimized and not marking read, that resolves B. EveryClearWindowActiveandForceWindowActiveis undone in the same turn, back to the activation captured at the start. The teardown destroys A and B first and proves that neither id resolves to a message or to aListWidgetview, then restores the option, the chat, the window state and the Qt activation, and the same idempotent release runs fromRunner::onFinish. TheHistory::messages()index theChatWidgetleg seeds may stay allocated and keep listing both ids: an id aboveServerMaxMsgIdlies above every slice'srange.till, whereSparseIdsList::removeOnecannot reach it, and every reader of the index looks ids up throughData::Session::message()and skips one with no message behind it; itsFIXTURE_INDEXrow reports what it lists. Confirm withAppendChatListMenuSelfTest.
Menus built on a later turn
When to use it
Over a widget card the list accepts a right click's context-menu event
without building anything: WidgetTouch (tgw_touch.cpp) records the event
and, once the widget's answer arrives on a later turn, re-sends it to the
list's own contextMenuEvent when the widget did not take the press, or at
tgw_renderer.cpp's 150 ms answer deadline; a press the widget took builds
no menu at all. OpenChatListContextMenu reads such a click menu-refused
(no-menu) in the event's turn and sends its leave at once, which clears
_mouseActive, the active click handler and Element::Hovered() before the
list resolves the point again for the later menu. Read it in three calls
instead:
BeginChatListContextMenu(list, target, point): the refusals before delivery, the enter, and the context-menu event with the at-build observer, exactly asOpenChatListContextMenu's first two steps. No leave, so the list's resolution gate stays open for the later menu's ownmouseActionUpdate(e->globalPos()). A refused request is final.PollChatListContextMenu(reading), on a later turn: for apending()reading whose underlying reading isno-menu, aTest::RetakeContextMenu, and in the poll that finds a fresh menudeferred, the at-build resolution and the list's own_menuread again, in that turn. It answers whether the wait is over: true once a menu or aseveral-menusrefusal was found, or when no menu can come (nothing pending, no event sent, the list gone); false otherwise. Each poll of ano-menureading setswaited, the ms sincesentAt.EndChatListContextMenu(reading): the leave, the decision and the hide of a refused menu, exactly asOpenChatListContextMenu's third step and decision. A reading that is notpending()is left as it is.
OpenChatListContextMenu is Begin then End in one call, so its readings,
its self-test and every caller that reads a menu built inside the event are
unchanged (deferred false, waited 0).
Preconditions and limits
- The caller owns the timer and the bound. A menu that has not come within
the product's deadline never comes for that press, so a bound of the
deadline plus slack decides it;
Test::ConformancePointerpolls every 5 ms for 250 ms (timed pointer sequences). - Send the list nothing between
BeginandEnd: the list stays entered (_mouseActivetrue) untilEnd, and the attribution of a deferred menu rests on the resolution its replayed event left. The product may resolve again in between - a widget's cursor answer re-runsmouseActionUpdate()throughData::Session::notifyViewLayoutChange- at the same stored point (_mousePosition), which keeps that resolution. - A deferred reading's
atBuildresolution andlistMenuare read in the poll turn that found the menu, not inside the call that built it; the gate is still judged onafterEnter, the state the original event was delivered into. The underlying reading'satBuildlifecycle stays the event's turn's (no menu) and itsafterSettleis the finding poll's. - A poll sees only a menu that is still alive: one the product built and
closed between two polls reads
no-menu, so a deferredno-menureading is product evidence only beside a positive control read the same way, and on a locked Windows console, where Qt closes a shown menu before the next turn, it is undecidable. - Always call
End, also after the bound passed with no menu, which decides the readingmenu-refused(no-menu) as the one-call reader would. A reading dropped withoutEndleaves the list entered.
Minimal use
// The event's turn:
state->menu = Test::BeginChatListContextMenu(list, item, point);
state->until = crl::now() + kMenuBound;
// Each later turn, until it answers true or the bound passed:
const auto over = Test::PollChatListContextMenu(state->menu)
|| (crl::now() >= state->until);
if (over) {
Test::EndChatListContextMenu(state->menu);
Test::Check(
state->menu.built(),
u"right click: the message menu, attributed"_q,
Test::ChatListMenuDetails(state->menu));
// Trigger an entry or hide the menu here, in this same turn.
}
Readings and refusals
The refusals are OpenChatListContextMenu's. ChatListMenuDetails prints
deferred and waited beside the other fields, and the underlying reading's
retakes. A built() reading with deferred true is a menu the list built
on a later turn while it resolved exactly the target; deferred false with
waited above zero is a wait that ended with no menu, and both at zero a
reading that was never polled.
Lifetime and cleanup
Begin leaves the list entered and End's leave is the cleanup, so a
caller whose wait can be cut short (a stage timeout, the watchdog) also
ends a pending reading from Runner::onFinish; End is idempotent. A
built() reading's menu is open: trigger an entry or hide it
(Ui::PopupMenu::hideMenu(true)) in the turn End returned in. A refused
reading's menu was hidden by End.
Verification
AppendChatListMenuSelfTest reads only menus built inside the event, through
OpenChatListContextMenu, so it covers Begin and End as one call. The
later-turn path has no self-test of its own: the conformance runner's right
click on a widget card (auto/16-sdk-taps-b, whose element claims nothing)
reads a deferred, built and hidden menu with waited under the bound. That
run's results belong to its task evidence.