blob: 169a2cca2d9514bd7dabab0965f660bf63e5976a [file] [log] [blame] [view]
Nate Fischer867117c32019-01-16 02:24:331# WebView Test Instructions
2
3## Android Instructions
4
5Please follow the instructions at
Nate Fischer19d894a42019-01-24 18:55:226[android_test_instructions.md](/docs/android_test_instructions.md).
Nate Fischer867117c32019-01-16 02:24:337This guide is an extension with WebView-specific content.
8
9*** note
10**Note:** except where otherwise noted, all tests require a device or emulator.
11***
12
13## Chromium-side tests
14
15### Instrumentation tests
16
17These tests live under `//android_webview/javatests/`, and are mostly
18end-to-end (*with the exception of the `//android_webview/glue/` layer*).
19
20```sh
21# Build
22$ autoninja -C out/Default webview_instrumentation_test_apk
23
24# Run tests (any of these commands):
25$ out/Default/bin/run_webview_instrumentation_test_apk # All tests
26$ out/Default/bin/run_webview_instrumentation_test_apk -f AwContentsTest#* # A particular test suite
27$ out/Default/bin/run_webview_instrumentation_test_apk -f AwContentsTest#testClearCacheInQuickSuccession # A single test
28$ out/Default/bin/run_webview_instrumentation_test_apk -f AwContentsTest#*Succession # Any glob pattern matching 1 or more tests
29```
30
Nate Fischer19d894a42019-01-24 18:55:2231*** aside
32You can optionally use `ClassName.methodName` instead of `ClassName#methodName`;
33the chromium test runner understands either syntax.
34***
35
Nate Fischer867117c32019-01-16 02:24:3336### Native unittests
37
38These are any `*_test.cc` or `*_unittest.cc` test under `//android_webview/`.
39Currently, we only have tests under `//android_webview/browser/` and
40`//android_webview/lib/`.
41
42```sh
43# Build
44$ autoninja -C out/Default android_webview_unittests
45
46# Run tests (any of these commands):
47$ out/Default/bin/run_android_webview_unittests # All tests
48$ out/Default/bin/run_android_webview_unittests -f AndroidStreamReaderURLRequestJobTest.* # Same glob patterns work here
49```
50
Nate Fischer19d894a42019-01-24 18:55:2251### Layout tests and page cycler tests
52
53WebView's layout tests and page cycler tests exercise the WebView installed on
54the system, instrumenting the WebView shell (`system_webview_shell_apk`,
55`org.chromium.webview_shell`). These test cases are defined in
56`//android_webview/tools/system_webview_shell/`.
57
58```sh
59# Build
60$ autoninja -C out/Default system_webview_shell_layout_test_apk
61
62# Install the desired WebView APK
63...
64
65# Run layout tests (installs WebView shell):
66$ out/Default/bin/run_system_webview_shell_layout_test_apk
67```
68
69To run page cycler tests instead, use the `system_webview_shell_page_cycler_apk`
70target and test runner in the steps above.
71
Nate Fischer867117c32019-01-16 02:24:3372### Useful test runner options
73
74#### Debugging flaky tests
75
76```sh
77$ out/Default/bin/run_webview_instrumentation_test_apk \ # Any test runner
78 --num_retries=0 \ # Tests normally retry-on-failure; disable for easier repo
79 --repeat=1000 \ # Repeat up to 1000 times for a failure
80 --break-on-failure \ # Stop repeating once we see the first failure
81 -f=AwContentsTest#testClearCacheInQuickSuccession
82```
83
84#### Enable a Feature for a local run
85
86```sh
87$ out/Default/bin/run_webview_instrumentation_test_apk \ # Any test runner
88 # Desired Features; see commandline-flags.md for more information
89 --enable-features="NetworkService,NetworkServiceInProcess" \
90 -f=AwContentsTest#testClearCacheInQuickSuccession
91```
92
93## External tests
94
95As WebView is an Android system component, we have some tests defined outside of
96the chromium repository, but which the team still maintains. For some of these
97tests, we have scripts to help chromium developers check these tests.
98
99*** promo
100All of these tests are end-to-end, so they exercise whatever WebView
101implementation you've installed and selected on your device. This also means you
102can enable Features and commandline flags the same way [as you would for
Nate Fischer19d894a42019-01-24 18:55:22103production](./commandline-flags.md).
Nate Fischer867117c32019-01-16 02:24:33104***
105
106### CTS
107
108WebView has [CTS](https://source.android.com/compatibility/cts) tests, testing
Nate Fischer19d894a42019-01-24 18:55:22109end-to-end behavior (using the WebView installed on the system). These tests
110live in the Android source tree (under `//platform/cts/tests/tests/webkit/`).
Nate Fischer867117c32019-01-16 02:24:33111
Nate Fischer19d894a42019-01-24 18:55:22112Chromium developers can download and run pre-built APKs for these test cases
113with:
Nate Fischer867117c32019-01-16 02:24:33114
115```sh
Nate Fischer19d894a42019-01-24 18:55:22116# Install the desired WebView APK
117...
118
119# Run pre-built WebView CTS tests:
Nate Fischer867117c32019-01-16 02:24:33120$ android_webview/tools/run_cts.py \
Nate Fischer19d894a42019-01-24 18:55:22121 --apk-dir="$HOME/run-cts-apk-dir" \ # Any folder, to use as an optional cache
Nate Fischer867117c32019-01-16 02:24:33122 --verbose \ # Optional
123 -f=android.webkit.cts.WebViewTest#* # Supports similar test filters
124```
125
126If you'd like to edit these tests, see internal documentation at
127http://go/clank-webview for working with Android checkouts.
128
129### AndroidX (Support Library)
130
131WebView also has an AndroidX module, which has its own tests (similar to CTS
132tests). These tests live under the AOSP source tree, under
133`//platform/frameworks/support/`.
134
135TODO(ntfschr): document the solution for http://crbug.com/891102, when that's
136fixed.