Layout Test Style Guidelines

This is a draft. Not yet effective. To be posted at blink-dev@ for review
See this thread!topic/blink-dev/_sTPXDJs53g

See also

Testing framework

Two testing frameworks are available in Blink layout test files. Consider using either of them to reduce boilerplate code and HTML elements.


From WebKit.


  • shouldBe family functions use eval(). Values to be checked need to live in global scope (window, self).


From W3C test suites. If you're going to upstream your tests to W3C test suites, you might want to use this instead of js-test.js.

  • Passing expectations are not needed.

DOCTYPE declaration

Unless the test is explicitly testing quirks mode, include a DOCTYPE declaration.

<html>, <head>, <body>

These tags are normally omitted.


Either of 2 space and 4 space indentation.

The usage should be consistent within a test file.


Either of Blink style or Google C++ style.

The usage should be consistent within a test file.


Some tests use double quote for HTML (e.g. <script src="some.js">) and single quote for JavaScript (e.g. var image = 'resources/image.jpg';), but it could be either.

The usage should be consistent within a test file.


First, try to give a descriptive name to variables and functions. Then, write comments wherever it makes sense to improve readability.

File naming

Give a descriptive name. Separate words by hyphens.

File layout

<Explain resources directory>

Asynchronous tests

Use of Promises may improve readability of tests on asynchronous operations. Use of callbacks is still fine.

TestRunner API

<Write introduction of TestRunner API>

Writing HTTP tests

The test server sets up an alias to LayoutTests/resources directory. You can access testing framework at e.g. "/js-test-resources/js-test.js". Use it instead of putting lots of ".."s.

Stable tests

<Explain what's --stable-release-mode flag>

TestExpectation family files

License boilerplate

<Most of layout test files don't contain any license declaration. Is this fine? Should we encourage putting it?>