Open Bug 2074031 Opened 1 month ago Updated 28 days ago

Give test_newtab's content scope a set of shared wait helpers

Categories

(Firefox :: New Tab Page, task)

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 second querySelector of the same selector, because waitForCondition's return value is not used (browser_topsites_section.js x6, 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-list being 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-done x5 in browser_customize_menu_content.js, active x3 in browser_newtab_last_LinkMenu.js, stuck-search x2 in browser_newtab_sticky_search.js.
  • Wait for the customize panel to open or close (bug 2072918): the enter-done wait appears 5 times in browser_customize_menu_content.js and once each in browser_customize_menu_key_open.js and browser_customize_menu_render.js; the matching close wait on the dialog's open property 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-feed wait is repeated 9 times, once per test, in browser_newtab_side_by_side_layout.js.
  • Wait for focus -- waitForCondition(() => document.activeElement === X): 6 calls (browser_topsites_section.js x4, browser_customize_menu_content.js x2).
  • 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 about panel-list's untrusted events, is defined 4 times (browser_topsites_section.js x3, browser_discovery_card.js).
  • The span(cols, gaps) probe that measures a --col-width expression is defined 7 times in browser_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.

Whiteboard: [hnt]
You need to log in before you can comment on or make changes to this bug.