forked from flatpak/xdg-desktop-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add tests for Registry host portal
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import tests as xdp | ||
|
||
import dbus | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def app_id(): | ||
return "org.example.WrongAppId" | ||
|
||
|
||
@pytest.fixture | ||
def required_templates(): | ||
return {"remotedesktop": {}} | ||
|
||
|
||
class TestRegistry: | ||
def test_version(self, portals, dbus_con): | ||
xdp.check_version(dbus_con, "Registry", 1, domain="host") | ||
|
||
def create_dummy_session(self, dbus_con): | ||
remotedesktop_intf = xdp.get_portal_iface(dbus_con, "RemoteDesktop") | ||
request = xdp.Request(dbus_con, remotedesktop_intf) | ||
|
||
session_counter_attr_name = "session_counter" | ||
if hasattr(self, session_counter_attr_name): | ||
session_counter = getattr(self, session_counter_attr_name) | ||
else: | ||
session_counter = 0 | ||
setattr(self, session_counter_attr_name, session_counter + 1) | ||
|
||
print(f"session_handle_token: {session_counter}") | ||
options = { | ||
"session_handle_token": f"session_token{session_counter}", | ||
} | ||
response = request.call( | ||
"CreateSession", | ||
options=options, | ||
) | ||
assert response.response == 0 | ||
|
||
return xdp.Session.from_response(dbus_con, response) | ||
|
||
def test_registerless(self, portals, dbus_con): | ||
mock_intf = xdp.get_mock_iface(dbus_con) | ||
|
||
expected_app_id = "org.example.WrongAppId" | ||
|
||
session = self.create_dummy_session(dbus_con) | ||
|
||
app_id = mock_intf.GetSessionAppId(session.handle) | ||
assert app_id == expected_app_id | ||
|
||
def test_register(self, portals, dbus_con): | ||
registry_intf = xdp.get_portal_iface(dbus_con, "Registry", domain="host") | ||
mock_intf = xdp.get_mock_iface(dbus_con) | ||
|
||
expected_app_id = "org.example.CorrectAppId" | ||
registry_intf.Register(expected_app_id, {}) | ||
|
||
session = self.create_dummy_session(dbus_con) | ||
|
||
app_id = mock_intf.GetSessionAppId(session.handle) | ||
assert app_id == expected_app_id | ||
|
||
def test_late_register(self, portals, dbus_con): | ||
registry_intf = xdp.get_portal_iface(dbus_con, "Registry", domain="host") | ||
mock_intf = xdp.get_mock_iface(dbus_con) | ||
|
||
expected_app_id = "org.example.WrongAppId" | ||
unexpected_app_id = "org.example.CorrectAppId" | ||
|
||
session = self.create_dummy_session(dbus_con) | ||
|
||
app_id = mock_intf.GetSessionAppId(session.handle) | ||
assert app_id == expected_app_id | ||
|
||
with pytest.raises(dbus.exceptions.DBusException): | ||
registry_intf.Register(unexpected_app_id, {}) | ||
|
||
new_session = self.create_dummy_session(dbus_con) | ||
|
||
new_app_id = mock_intf.GetSessionAppId(new_session.handle) | ||
assert new_app_id == expected_app_id |