wiki:WebInspectorTests

Version 1 (modified by BJ Burg, 10 years ago) (diff)

explain how inspector protocol tests work

This page describes how various parts of the Web Inspector are tested.


Test areas

There are two flavors of inspector tests: tests that exercise the raw inspector protocol (independently of any particular frontend), and tests that exercise the models and controllers underlying the current user interface. In some cases, model/controller tests are written instead of protocol tests if the protocol test would be unusually large or hard to debug.

There are no tests that exercise the user interface of the Web Inspector (UI tests). In practice, the Inspector UI changes frequently so such tests are very brittle, and are rarely worth the trouble of maintaining.

Test mechanisms

Each test is an HTML file in the LayoutTests/inspector-protocol/ directory. The special test() method is evaluated in the inspector page (see below), and other scripts are executed in the test page (i.e., the page being inspected by the inspector).

Dummy inspector frontend

Many protocol and model tests do not need to persist across main frame navigations, nor do they need access all of the Web Inspector functionality. For such tests, the test harness creates a dummy inspector frontend by using window.open() from the test page, and establishes bidirectional communication with the child inspector page using window.postMessage and a message event handler. It then evaluates a subset of inspector resources into existence on the dummy page. Finally, it runs the provided test function by calling toString() on the fuction, sending to the child inspector page, and then using eval(). This functionality is implemented by LayoutTests/http/tests/inspector-protocol/resources/protocol-test.js on the test page, and LayoutTests/http/tests/inspector-protocol/resources/InspectorTest.js on the inspector page.