| 1 |
xdg-desktop-portal test suite |
| 2 |
============================= |
| 3 |
|
| 4 |
## Unit tests |
| 5 |
|
| 6 |
This directory contains a number of unit tests. The tests are written in C and |
| 7 |
are using the glib testing framework (https://docs.gtk.org/glib/testing.html). |
| 8 |
|
| 9 |
The files follow the pattern `test-$NAME.c` and are compiled by meson. The tests |
| 10 |
can be run with `meson test --suite unit`. |
| 11 |
|
| 12 |
## Integration tests |
| 13 |
|
| 14 |
The integration tests usually test a specific portal in a fully integrated |
| 15 |
environment. The tests are written in python using the pytest framework. |
| 16 |
|
| 17 |
The files follow the pattern `test_$NAME.py`. The tests can be run with |
| 18 |
`meson test --suite integration` or with `run-test.sh` in the source directory. |
| 19 |
|
| 20 |
The environment is being set up by fixtures in `conftest.py` which can be |
| 21 |
overwritten or parameterized by the tests themselves. There are a bunch of |
| 22 |
convenient functions and classes in `__init__.py`. The portal backends are |
| 23 |
implemented using dbusmock templates in the `templates` directory. |
| 24 |
|
| 25 |
### Environment |
| 26 |
|
| 27 |
Some environment variables need to be set for the integration tests to function |
| 28 |
properly and the harness will refuse to launch if they are not set. If the |
| 29 |
harness is executed by meson or run-test.sh, they will be set automatically. |
| 30 |
|
| 31 |
* `XDG_DESKTOP_PORTAL_PATH`: The path to the xdg-desktop-portal binary |
| 32 |
|
| 33 |
* `XDG_PERMISSION_STORE_PATH`: The path to the xdg-permission-store binary |
| 34 |
|
| 35 |
* `XDG_DOCUMENT_PORTAL_PATH`: The path to the xdg-document-portal binary |
| 36 |
|
| 37 |
* `XDP_VALIDATE_ICON`: The path to the xdg-desktop-portal-validate-icon binary |
| 38 |
|
| 39 |
* `XDP_VALIDATE_SOUND`: The path to the xdg-desktop-portal-validate-sound binary |
| 40 |
|
| 41 |
* `XDP_VALIDATE_AUTO`: If set, automatically discovers the icon and sound |
| 42 |
validators (only useful for installed tests) instead of using |
| 43 |
`XDP_VALIDATE_ICON` and `XDP_VALIDATE_SOUND`. |
| 44 |
|
| 45 |
Some optional environment variables that can be set to influence how the test |
| 46 |
harness behaves. |
| 47 |
|
| 48 |
* `XDP_TEST_IN_CI`: If set (to any value), some unreliable tests might get |
| 49 |
skipped and some tests might run less iterations or otherwise test less |
| 50 |
thoroughly. |
| 51 |
Set this for automated QA testing, leave it unset during development. |
| 52 |
|
| 53 |
* `XDP_TEST_RUN_LONG`: If set (to any value), some tests will run more |
| 54 |
iterations or otherwise test more thoroughly |
| 55 |
|
| 56 |
* `FLATPAK_BWRAP`: Path to the **bwrap**(1) executable |
| 57 |
(default: discovered at build-time) |
| 58 |
|
| 59 |
* `XDP_VALIDATE_ICON_INSECURE`: If set (to any value), x-d-p doesn't |
| 60 |
sandbox the icon validator using **bwrap**(1), even if sandboxed |
| 61 |
validation was enabled at compile time. |
| 62 |
This can be used to run build-time tests in a chroot or unprivileged |
| 63 |
container environment, where **bwrap**(1) normally can't work. |
| 64 |
It should never be set on a production system that will be validating |
| 65 |
untrusted icons! |
| 66 |
|
| 67 |
* `XDP_VALIDATE_SOUND_INSECURE`: Same as `XDP_VALIDATE_ICON_INSECURE`, |
| 68 |
but for sounds |
| 69 |
|
| 70 |
Some optional environment variables that can be set to help with debugging. |
| 71 |
|
| 72 |
* `XDP_DBUS_MONITOR`: If set, starts dbus-monitor on the test dbus server |
| 73 |
|
| 74 |
* `XDP_DBUS_TIMEOUT`: Maximum timeout for dbus calls in ms (default: 5s) |
| 75 |
|
| 76 |
* `XDG_DESKTOP_PORTAL_WAIT_FOR_DEBUGGER`: Makes xdg-desktop-portal wait for |
| 77 |
a debugger to attach by raising SIGSTOP |
| 78 |
|
| 79 |
* `XDG_DOCUMENT_PORTAL_WAIT_FOR_DEBUGGER`: Makes xdg-document-portal wait |
| 80 |
for a debugger to attach by raising SIGSTOP |
| 81 |
|
| 82 |
* `XDG_PERMISSION_STORE_WAIT_FOR_DEBUGGER`: Makes xdg-permission-store wait |
| 83 |
for a debugger to attach by raising SIGSTOP |
| 84 |
|
| 85 |
Internal environment variables the tests use via pytest fixtures to set up the |
| 86 |
environment they need. |
| 87 |
|
| 88 |
* `XDG_DESKTOP_PORTAL_TEST_APP_ID`: If set, the portal will use a host |
| 89 |
XdpAppInfo with the app id set to the variable. This is used to get a |
| 90 |
predictable app id for tests. |
| 91 |
|
| 92 |
* `XDG_DESKTOP_PORTAL_TEST_USB_QUERIES`: The USB queries for the USB device |
| 93 |
portal testing |
| 94 |
|
| 95 |
### Adding new tests |
| 96 |
|
| 97 |
Make sure the required portals are listed in |
| 98 |
`xdg_desktop_portal_dir_default_files` in `conftest.py`. |
| 99 |
|
| 100 |
Add a `test_${name}.py` file to this directory and add the file to |
| 101 |
`meson.build`. |
| 102 |
|
| 103 |
If the portal that is being tested requires a backend implementation, add |
| 104 |
it to the `templates` directory and add the file to `meson.build`. See the |
| 105 |
dbusmock documentation for details on those templates. |