Layout Test Style Guidelines

This is a draft. Not yet effective. To be posted at blink-dev@ for review
See this thread https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/_sTPXDJs53g


See also
https://sites.google.com/a/chromium.org/dev/blink/blink-testing-and-the-w3c

Testing framework

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

js-test.js

From WebKit.

Pros:

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

testharness.js

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.

Pros:
  • Passing expectations are not needed.
Cons:

DOCTYPE declaration

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

<html>, <head>, <body>

These tags are normally omitted.

Indentation

Either of 2 space and 4 space indentation.

The usage should be consistent within a test file.

Braces

Either of Blink style or Google C++ style.

The usage should be consistent within a test file.

Quotation

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.

Comments

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?>
Comments