Contributing to WebView Tests

Instrumentation tests

These are on-device integration tests for android_webview with rest of the chromium code (covering both Java and native code). A large percentage of Android applications use WebView, and could trigger WebView specific code paths in the codebase, therefore it is important to have solid integration tests.

Where to add tests?

The tests are located in the javatests directory. They are roughly organized by the Aw classes (some tests are organized by overall functionality instead). Put new tests into an existing test class or create a new one if a suitable one isn't available.

How to write intrumentation tests?

See the instrumentation test doc.

How do tests interact with WebView?

Tests are written as JUnit4 tests. AwActivityTestRule is used to create and obtain references to WebView objects such as AwContents(internally it launches the WebView instrumentation shell application to hold AwTestContainerViews which in turn contains AwContents). AwContents will allow the test to trigger code paths such as loading urls, going forwards/backwards, etc... . AwActivityTestRule has some helper methods to call the AwContents methods, for example to ensure that they are called on the UI thread. Some AW components, such as AwCookieManager, can be directly created in tests.

How do tests inject html/css/js content?

Tests can use the load* methods in AwActivityTestRule to inject snippets of content. This will however bypass the network layer. To have end-to-end testing, use EmbeddedTestServer, which will allow simple loading of files from the data directory. For loading data from arbitrary URIs and more advanced control, the TestWebServer can be used.

Java unittest (JUnit)

These are off-device tests using robolectric that only exercise android_webview Java code.

Where do add tests?

The tests are located in the junit directory.

How to write junit tests?

See the JUnit doc.

Native unittests

These are on-device gtests that only exercise android_webview native code.

Where to add tests?

The tests are located alongside respective source code files under android_webview directory.

How to write gtests?

See the GTest doc.

How to run tests?

Running tests is covered in WebView Test Instructions.