| 1 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
# |
| 3 |
# This file is formatted with Python Black |
| 4 |
|
| 5 |
import tests as xdp |
| 6 |
|
| 7 |
import pytest |
| 8 |
import dbus |
| 9 |
import os |
| 10 |
from pathlib import Path |
| 11 |
|
| 12 |
|
| 13 |
SVG_IMAGE_DATA = """<?xml version="1.0" encoding="UTF-8"?> |
| 14 |
<svg xmlns="http://www.w3.org/2000/svg" height="16px" width="16px"/> |
| 15 |
""" |
| 16 |
|
| 17 |
DESKTOP_FILE = b"""[Desktop Entry] |
| 18 |
Version=1.0 |
| 19 |
Name=Dynamic Launcher Example |
| 20 |
Exec=true %u |
| 21 |
Type=Application |
| 22 |
""" |
| 23 |
|
| 24 |
|
| 25 |
@pytest.fixture |
| 26 |
def required_templates(): |
| 27 |
return {"dynamiclauncher": {}} |
| 28 |
|
| 29 |
|
| 30 |
class TestDynamicLauncher: |
| 31 |
def test_version(self, portals, dbus_con): |
| 32 |
"""tests the version of the interface""" |
| 33 |
|
| 34 |
xdp.check_version(dbus_con, "DynamicLauncher", 1) |
| 35 |
|
| 36 |
def test_basic(self, portals, dbus_con, app_id): |
| 37 |
"""test that the backend receives the expected data""" |
| 38 |
|
| 39 |
dynlauncher_intf = xdp.get_portal_iface(dbus_con, "DynamicLauncher") |
| 40 |
mock_intf = xdp.get_mock_iface(dbus_con) |
| 41 |
|
| 42 |
app_name = "App Name" |
| 43 |
bytes = SVG_IMAGE_DATA.encode("utf-8") |
| 44 |
|
| 45 |
request = xdp.Request(dbus_con, dynlauncher_intf) |
| 46 |
options = { |
| 47 |
"modal": False, |
| 48 |
} |
| 49 |
response = request.call( |
| 50 |
"PrepareInstall", |
| 51 |
parent_window="", |
| 52 |
name=app_name, |
| 53 |
icon_v=dbus.Struct( |
| 54 |
("bytes", dbus.ByteArray(bytes, variant_level=1)), |
| 55 |
signature="sv", |
| 56 |
variant_level=1, |
| 57 |
), |
| 58 |
options=options, |
| 59 |
) |
| 60 |
|
| 61 |
assert response |
| 62 |
assert response.response == 0 |
| 63 |
assert response.results["name"] == app_name |
| 64 |
token = response.results["token"] |
| 65 |
|
| 66 |
# Check the impl portal was called with the right args |
| 67 |
method_calls = mock_intf.GetMethodCalls("PrepareInstall") |
| 68 |
assert len(method_calls) > 0 |
| 69 |
_, args = method_calls[-1] |
| 70 |
assert args[2] == "" # parent window |
| 71 |
assert args[3] == app_name # name |
| 72 |
# args[4] == icon |
| 73 |
assert not args[5]["modal"] |
| 74 |
|
| 75 |
desktop_file_name = app_id + ".ExampleApp.desktop" |
| 76 |
dynlauncher_intf.Install( |
| 77 |
token, |
| 78 |
desktop_file_name, |
| 79 |
DESKTOP_FILE, |
| 80 |
{}, |
| 81 |
) |
| 82 |
|
| 83 |
file = Path(os.environ["XDG_DATA_HOME"]) / "applications" / desktop_file_name |
| 84 |
assert file.exists() |