Skip to content

[Web Inspector] Add Testing guide for Inspector layout tests#149

Merged
burg merged 1 commit intoWebKit:mainfrom
burg:eng/bburg/wi-test-guide
Apr 3, 2026
Merged

[Web Inspector] Add Testing guide for Inspector layout tests#149
burg merged 1 commit intoWebKit:mainfrom
burg:eng/bburg/wi-test-guide

Conversation

@burg
Copy link
Copy Markdown
Contributor

@burg burg commented Apr 1, 2026

Port and modernize the WebInspectorTests wiki page from trac.webkit.org. Covers writing and running Web Inspector layout tests:

  • Tutorial walkthrough (Your First Test)
  • Two harness types (frontend vs protocol tests)
  • Async test patterns with protocol agents
  • Testing with page content (evaluateInPage, Promise.all pattern)
  • Protocol test API (InspectorProtocol.awaitCommand/awaitEvent)
  • Test suite and test case lifecycle (setup/teardown, timeouts)
  • Full assertion API reference table
  • Helper scripts and TestPage.registerInitializer
  • Site isolation test patterns (cross-origin targets, StableIdMap)
  • Writing deterministic output
  • Debugging failing tests
  • Common patterns (parameterized tests, event verification)

All examples derived from actual passing tests in the WebKit tree.

suite.addTestCase({
name: "EvaluateExpression",
async test() {
let response = await RuntimeAgent.evaluate("2 + 3");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
let response = await RuntimeAgent.evaluate("2 + 3");
let response = await WI.mainTarget.RuntimeAgent.evaluate("2 + 3");

According to this FIXME, using the agent directly without a target is deprecated, especially now with site isolation engineering in mind. Let's keep our suggestions in the recommended format

let event = await InspectorProtocol.awaitEvent({event: "Debugger.scriptParsed"});

// addEventListener / removeEventListener for persistent listeners
InspectorProtocol.addEventListener("Network.requestWillBeSent", handler);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could always mention ProtocolTest.pass("passing");


Tests under `http/tests/site-isolation/inspector/` verify inspector behavior with cross-process iframes. Key patterns:

- **Cross-origin iframes** use `localhost` vs `127.0.0.1` (both served by the test HTTP server)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Worth pointing out that 127.0.0.1 is the default origin (as in tests in http/tests start with that as the origin)

Reviewed by Brandon Stewart.

Port and modernize the WebInspectorTests wiki page from trac.webkit.org.
Covers writing and running Web Inspector layout tests:

- Tutorial walkthrough (Your First Test)
- Two harness types (frontend vs protocol tests)
- Async test patterns with protocol agents
- Testing with page content (evaluateInPage, Promise.all pattern)
- Protocol test API (InspectorProtocol.awaitCommand/awaitEvent)
- Test suite and test case lifecycle (setup/teardown, timeouts)
- Full assertion API reference table
- Helper scripts and TestPage.registerInitializer
- Site isolation test patterns (cross-origin targets, StableIdMap)
- Writing deterministic output
- Debugging failing tests
- Common patterns (parameterized tests, event verification)

All examples derived from actual passing tests in the WebKit tree.
@burg burg force-pushed the eng/bburg/wi-test-guide branch from 1cbf29d to 86d045a Compare April 3, 2026 21:06
@burg burg merged commit 7af8340 into WebKit:main Apr 3, 2026
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