Skip to content

test: migrate pages handler validation tests to mocks - #2758

Closed
dhananjaypai08 wants to merge 1 commit into
ChromeDevTools:mainfrom
dhananjaypai08:test-migrate-pages-handler-validation
Closed

dhananjaypai08 wants to merge 1 commit into
ChromeDevTools:mainfrom
dhananjaypai08:test-migrate-pages-handler-validation

Conversation

@dhananjaypai08

Copy link
Copy Markdown

Refs #2639

Summary

  • Move the list_pages handler test and the new_page / navigate_page URL validation tests in tests/tools/pages.test.ts onto createHandlerMocks().
  • Assert the list_pages response flags (setIncludePages, setListThirdPartyDeveloperTools, setListWebMcpTools) and that rejected URLs never call context.newPage or page.pptrPage.goto.
  • Keep the remaining real-browser tests in this file (page close recovery, extensions, dialogs, chrome://newtab/, focus, isolated contexts).

Test plan

  • npm run test tests/tools/pages.test.ts -- --test-name-pattern='list pages$|javascript URL|javascript, data, or vbscript|does not parse|chrome: and chrome-untrusted|chrome-extension: URLs unless'
    • 9/9 passed in ~69ms with PUPPETEER_EXECUTABLE_PATH pointed at a nonexistent binary
  • npm run test tests/tools/pages.test.ts
  • npm run format

@dhananjaypai08
dhananjaypai08 force-pushed the test-migrate-pages-handler-validation branch from d137a5e to 1e9a508 Compare September 23, 2026 23:31
@dhananjaypai08
dhananjaypai08 force-pushed the test-migrate-pages-handler-validation branch from 1e9a508 to aac76f8 Compare September 23, 2026 23:42
@OrKoN
OrKoN self-requested a review September 30, 2026 11:14

@OrKoN OrKoN left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, let's make the following changes:

  1. In tests/tools/pages.test.ts (the --no-javascript-evaluation tests for newPage and navigatePage), rebase on main and pass {javascriptEvaluation: false} directly to createHandlerMocks({javascriptEvaluation: false}) instead of parsing CLI flags. Commit #2861 replaced parseArguments with ConfigParser on main, causing a rebase conflict, and passing the option directly to createHandlerMocks avoids manual argument parsing altogether.

  2. In tests/tools/pages.test.ts, destructure args directly from createHandlerMocks() across the migrated list_pages, newPage, and navigatePage tests instead of repeatedly calling createMockParsedArguments(). createHandlerMocks() already initializes and returns args with default mock options, making the extra createMockParsedArguments() invocations redundant.

@Lightning00Blade

Copy link
Copy Markdown
Collaborator

Closing as stale.

dinfuehr pushed a commit to dinfuehr/chrome-devtools-mcp that referenced this pull request Oct 16, 2026
Part of ChromeDevTools#2639. Picks up ChromeDevTools#2758 (closed as stale) and applies the review
feedback from it.

The `list_pages` handler test and the URL validation tests for
`new_page` and `navigate_page` only check that the handler validates its
input and stops early, so they don't need a real browser. This migrates
them in place to `createHandlerMocks`, following `AGENTS.md`:

- `list_pages` › list pages: asserts `setIncludePages(true)`,
`setListThirdPartyDeveloperTools()` and `setListWebMcpTools()`.
- `new_page` › javascript/data/vbscript URLs, `file:` URLs, unparsable
URL, `chrome:`/`chrome-untrusted:` URLs, `chrome-extension:` URLs:
assert the exact error and that `context.newPage` is never called, so no
tab is opened for a rejected URL.
- `navigate_page` › the same five cases: assert the exact error and that
`page.pptrPage.goto` is never called.

As requested in ChromeDevTools#2758, the flag-dependent cases pass the option directly
(`createHandlerMocks({javascriptEvaluation: false})`,
`createHandlerMocks({fileNavigations: false})`) instead of parsing CLI
flags, and every migrated test destructures `args` from
`createHandlerMocks()` instead of calling `createMockParsedArguments()`.

The rest of the file still uses the real browser and is unchanged:
closed-page recovery, extension pages and service workers, side panels,
dialogs, `chrome://newtab/`, background/focus, isolated contexts,
history navigation, `beforeunload`, `initScript`, resize and
`get_tab_id`. `validateUrl` itself stays covered by
`tests/utils/url.test.ts`.

**Testing**

- `npm run build && NODE_TEST_REPORTER=spec node scripts/test.js
tests/tools/pages.test.ts`: 63/63 pass (63 before as well). `list pages`
goes from about 650 ms to about 35 ms; the URL validation tests from
35–100 ms to 20–40 ms.
- The 11 migrated tests also pass with `PUPPETEER_EXECUTABLE_PATH`
pointing at a nonexistent binary, so none of them starts Chrome.
- Sanity check that they still catch regressions (each change made all
the targeted tests fail, then reverted):
- removing `setListWebMcpTools()` from `list_pages` fails `list pages`;
- moving `validateUrl` after `context.newPage` in `new_page` fails all
five `new_page` cases on `notCalled(context.newPage)`;
- passing `javascriptEvaluation`/`fileNavigations` as `undefined` and
`categoryExtensions: true` to `validateUrl` fails the javascript, file
and chrome-extension cases in both tools;
- removing the `validateUrl` call from `navigate_page` fails all five
`navigate_page` cases.
- `eslint` and `prettier` are clean; only `tests/tools/pages.test.ts`
changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants