Nate Fischer | 867117c3 | 2019-01-16 02:24:33 | [diff] [blame] | 1 | # WebView Test Instructions |
| 2 | |
| 3 | ## Android Instructions |
| 4 | |
| 5 | Please follow the instructions at |
Nate Fischer | 19d894a4 | 2019-01-24 18:55:22 | [diff] [blame] | 6 | [android_test_instructions.md](/docs/android_test_instructions.md). |
Nate Fischer | 867117c3 | 2019-01-16 02:24:33 | [diff] [blame] | 7 | This 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 | |
| 17 | These tests live under `//android_webview/javatests/`, and are mostly |
| 18 | end-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 Fischer | 19d894a4 | 2019-01-24 18:55:22 | [diff] [blame] | 31 | *** aside |
| 32 | You can optionally use `ClassName.methodName` instead of `ClassName#methodName`; |
| 33 | the chromium test runner understands either syntax. |
| 34 | *** |
| 35 | |
Nate Fischer | 867117c3 | 2019-01-16 02:24:33 | [diff] [blame] | 36 | ### Native unittests |
| 37 | |
| 38 | These are any `*_test.cc` or `*_unittest.cc` test under `//android_webview/`. |
| 39 | Currently, 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 Fischer | 19d894a4 | 2019-01-24 18:55:22 | [diff] [blame] | 51 | ### Layout tests and page cycler tests |
| 52 | |
| 53 | WebView's layout tests and page cycler tests exercise the WebView installed on |
| 54 | the 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 | |
| 69 | To run page cycler tests instead, use the `system_webview_shell_page_cycler_apk` |
| 70 | target and test runner in the steps above. |
| 71 | |
Nate Fischer | 867117c3 | 2019-01-16 02:24:33 | [diff] [blame] | 72 | ### 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 | |
| 95 | As WebView is an Android system component, we have some tests defined outside of |
| 96 | the chromium repository, but which the team still maintains. For some of these |
| 97 | tests, we have scripts to help chromium developers check these tests. |
| 98 | |
| 99 | *** promo |
| 100 | All of these tests are end-to-end, so they exercise whatever WebView |
| 101 | implementation you've installed and selected on your device. This also means you |
| 102 | can enable Features and commandline flags the same way [as you would for |
Nate Fischer | 19d894a4 | 2019-01-24 18:55:22 | [diff] [blame] | 103 | production](./commandline-flags.md). |
Nate Fischer | 867117c3 | 2019-01-16 02:24:33 | [diff] [blame] | 104 | *** |
| 105 | |
| 106 | ### CTS |
| 107 | |
| 108 | WebView has [CTS](https://source.android.com/compatibility/cts) tests, testing |
Nate Fischer | 19d894a4 | 2019-01-24 18:55:22 | [diff] [blame] | 109 | end-to-end behavior (using the WebView installed on the system). These tests |
| 110 | live in the Android source tree (under `//platform/cts/tests/tests/webkit/`). |
Nate Fischer | 867117c3 | 2019-01-16 02:24:33 | [diff] [blame] | 111 | |
Nate Fischer | 19d894a4 | 2019-01-24 18:55:22 | [diff] [blame] | 112 | Chromium developers can download and run pre-built APKs for these test cases |
| 113 | with: |
Nate Fischer | 867117c3 | 2019-01-16 02:24:33 | [diff] [blame] | 114 | |
| 115 | ```sh |
Nate Fischer | 19d894a4 | 2019-01-24 18:55:22 | [diff] [blame] | 116 | # Install the desired WebView APK |
| 117 | ... |
| 118 | |
| 119 | # Run pre-built WebView CTS tests: |
Nate Fischer | 867117c3 | 2019-01-16 02:24:33 | [diff] [blame] | 120 | $ android_webview/tools/run_cts.py \ |
Nate Fischer | 19d894a4 | 2019-01-24 18:55:22 | [diff] [blame] | 121 | --apk-dir="$HOME/run-cts-apk-dir" \ # Any folder, to use as an optional cache |
Nate Fischer | 867117c3 | 2019-01-16 02:24:33 | [diff] [blame] | 122 | --verbose \ # Optional |
| 123 | -f=android.webkit.cts.WebViewTest#* # Supports similar test filters |
| 124 | ``` |
| 125 | |
| 126 | If you'd like to edit these tests, see internal documentation at |
| 127 | http://go/clank-webview for working with Android checkouts. |
| 128 | |
| 129 | ### AndroidX (Support Library) |
| 130 | |
| 131 | WebView also has an AndroidX module, which has its own tests (similar to CTS |
| 132 | tests). These tests live under the AOSP source tree, under |
| 133 | `//platform/frameworks/support/`. |
| 134 | |
| 135 | TODO(ntfschr): document the solution for http://crbug.com/891102, when that's |
| 136 | fixed. |