Give test_newtab's content scope a set of shared wait helpers
Categories
(Firefox :: New Tab Page, task)
Tracking
()
People
(Reporter: florian, Unassigned)
References
(Blocks 1 open bug)
Details
(Whiteboard: [hnt])
[note: description written by Claude]
test_newtab bodies are serialized and run in the content process, so they cannot see anything in the test file's chrome scope. The only way to share a helper between them is to inject it onto the content global from addContentHelpers() in browser/extensions/newtab/test/browser/head.js, which today provides three: openContextMenuAndGetOptions, waitForTopSite and waitForPanelItem (the last two added in bug 2025752). Everything else gets written out again in each body, which is why the same ContentTaskUtils.waitForCondition blocks keep reappearing -- and why each copy is free to wait on the wrong thing, as bug 2072918 and bug 2064559 both found.
The folder has 101 ContentTaskUtils.waitForCondition calls across 20 test files. They fall into a small number of shapes:
- Wait for a selector to appear --
waitForCondition(() => document.querySelector(SEL), "msg"): 47 calls in 16 files. Worst:browser_topsites_section.js(9),browser_newtab_side_by_side_layout.js(9),browser_newtab_spaces.js(6),browser_customize_menu_content.js(5). Eight of them are immediately followed by a secondquerySelectorof the same selector, becausewaitForCondition's return value is not used (browser_topsites_section.jsx6,browser_newtab_header.js,browser_newtab_spaces.js). - Wait for a selector to disappear -- the same block negated: 11 calls in 4 files, 5 of them in
browser_activation_window.js. That file alone waits on.top-sites-listbeing present or absent 8 times, in five different phrasings (=== null,!...,return !...). - Wait for a class to be added or removed on a node: 10 calls --
customize-animate-enter-donex5 inbrowser_customize_menu_content.js,activex3 inbrowser_newtab_last_LinkMenu.js,stuck-searchx2 inbrowser_newtab_sticky_search.js. - Wait for the customize panel to open or close (bug 2072918): the
enter-donewait appears 5 times inbrowser_customize_menu_content.jsand once each inbrowser_customize_menu_key_open.jsandbrowser_customize_menu_render.js; the matching close wait on the dialog'sopenproperty appears 3 times. Seven copies of one concept across three files. - Wait for the content feed's layout (bug 2064559): the
.layout-content-column.has-feedwait is repeated 9 times, once per test, inbrowser_newtab_side_by_side_layout.js. - Wait for focus --
waitForCondition(() => document.activeElement === X): 6 calls (browser_topsites_section.jsx4,browser_customize_menu_content.jsx2). - Wait on a computed style value: 4 calls (
browser_topsites_section.js,browser_customize_menu_content.js).
Two non-wait helpers are copy-pasted the same way:
panelEvent = (target, name) => ContentTaskUtils.waitForEvent(target, name, false, null, true), with its comment aboutpanel-list's untrusted events, is defined 4 times (browser_topsites_section.jsx3,browser_discovery_card.js).- The
span(cols, gaps)probe that measures a--col-widthexpression is defined 7 times inbrowser_newtab_side_by_side_layout.js, whose file comment already says why: "Test bodies run in the content process and cannot see helpers from this scope, hence the repeated local probe helpers."
Proposed: extend addContentHelpers() with the generic waits (appear/disappear by selector, class added/removed, focus) and the two feature-specific ones the folder keeps rewriting (the customize panel's open state, the feed layout), then convert the call sites. Returning the found element from the appear helper also removes the double-query.
Updated•28 days ago
|
Updated•28 days ago
|
Description
•