diff --git a/tests/gnome-shell-dbus-runner.py.in b/tests/gnome-shell-dbus-runner.py.in new file mode 100755 index 000000000..ade110fc6 --- /dev/null +++ b/tests/gnome-shell-dbus-runner.py.in @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 + +import sys + +sys.path.insert(1, '@MUTTER_TEST_PKGDATADIR@') +sys.path.insert(2, '@SRCDIR@') + +from mutter_dbusrunner import meta_run +from gnomeshell_dbusrunner import GnomeShellDBusRunner + +if __name__ == '__main__': + result = meta_run(GnomeShellDBusRunner) + sys.exit(result) diff --git a/tests/gnomeshell_dbusrunner.py b/tests/gnomeshell_dbusrunner.py new file mode 100644 index 000000000..f3b7688a4 --- /dev/null +++ b/tests/gnomeshell_dbusrunner.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 + +import argparse +import sys +import os +import dbus +import pwd +#import dbus.lowlevel +import dbusmock + +from mutter_dbusrunner import MutterDBusRunner + +class MockDisplayManager: + BUS_NAME = 'org.gnome.DisplayManager' + MAIN_OBJ = '/org/gnome/DisplayManager/Manager' + MAIN_IFACE = 'org.gnome.DisplayManager.Manager' + SYSTEM_BUS = True + + @staticmethod + def load(mock, parameters={}): + mock.AddMethods(MockDisplayManager.MAIN_IFACE, + [('RegisterSession', 'a{sv}', '', '')]) + +class MockPermissionStore: + BUS_NAME = 'org.freedesktop.impl.portal.PermissionStore' + MAIN_OBJ = '/org/freedesktop/impl/portal/PermissionStore' + MAIN_IFACE = 'org.freedesktop.impl.portal.PermissionStore' + SYSTEM_BUS = False + + @staticmethod + def load(mock, parameters={}): + mock.AddMethod(MockPermissionStore.MAIN_IFACE, 'Lookup', 'ss', 'a{sas}v', + 'ret = (dbus.Dictionary([], signature="sas"), dbus.String("NONE", variant_level=2))') + + @staticmethod + def lookup_permission(self, table, id): + return dbus.Struct([]) + +class MockSessionManager: + BUS_NAME = 'org.gnome.SessionManager' + MAIN_OBJ = '/org/gnome/SessionManager' + MAIN_IFACE = 'org.gnome.SessionManager' + SYSTEM_BUS = False + + @staticmethod + def load(mock, parameters={}): + mock.AddMethods(MockSessionManager.MAIN_IFACE, + [('Setenv', 'ss', '', '')]) + +class MockGeoClue: + BUS_NAME = 'org.freedesktop.GeoClue2' + MAIN_OBJ = '/org/freedesktop/GeoClue2/Manager' + MAIN_IFACE = 'org.freedesktop.GeoClue2.Manager' + SYSTEM_BUS = True + + @staticmethod + def load(mock, parameters={}): + mock.AddMethods(MockGeoClue.MAIN_IFACE, + [('AddAgent', 's', '', '')]) + +class MockGnomeShellCalendarServer: + BUS_NAME = 'org.gnome.Shell.CalendarServer' + MAIN_OBJ = '/org/gnome/Shell/CalendarServer' + MAIN_IFACE = 'org.gnome.Shell.CalendarServer' + SYSTEM_BUS = False + + @staticmethod + def load(mock, parameters={}): + mock.AddMethods(MockGnomeShellCalendarServer.MAIN_IFACE, + [('SetTimeRange', 'xxb', '', '')]) + +class MockParentalControls: + BUS_NAME = 'com.endlessm.ParentalControls.AccountInfo' + MAIN_OBJ = '/com/endlessm/ParentalControls/AccountInfo' + MAIN_IFACE = 'com.endlessm.ParentalControls.AccountInfo' + SYSTEM_BUS = False + + @staticmethod + def load(mock, parameters={}): + pass + + +class GnomeShellDBusRunner(MutterDBusRunner): + @classmethod + def setUpClass(klass, enable_kvm, launch): + MutterDBusRunner.setUpClass(enable_kvm, launch) + + klass.add_template_dir(os.path.join(os.path.dirname(__file__), + 'dbusmock-templates')) + + systemd_system = klass.start_from_template('systemd', system_bus=True) + systemd_user = klass.start_from_template('systemd', system_bus=False) + klass.start_from_template('upower') + klass.start_from_template('networkmanager') + klass.start_from_template('polkitd') + klass.start_from_template('power_profiles_daemon') + + accounts_service = klass.start_from_local_template('accounts_service') + empty_dict = dbus.Dictionary({}, signature='sv') + accounts_service[1].AddUser(os.getuid(), + pwd.getpwuid(os.getuid()).pw_name, + '', + empty_dict) + + klass.start_from_class(MockDisplayManager) + klass.start_from_class(MockSessionManager) + klass.start_from_class(MockGeoClue) + klass.start_from_class(MockPermissionStore) + klass.start_from_class(MockParentalControls) + klass.start_from_class(MockGnomeShellCalendarServer) + + systemd_mock = dbus.Interface(systemd_user[1], dbusmock.MOCK_IFACE) + systemd_mock.AddMockUnit('org.freedesktop.IBus.session.GNOME.service') + systemd_mock.AddMockUnit('org.gnome.Shell.CalendarServer.service') + + accounts_service_mock = dbus.Interface(accounts_service[1], dbusmock.MOCK_IFACE) diff --git a/tests/meson.build b/tests/meson.build index 9d3925d36..72ac6170c 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -7,6 +7,17 @@ run_test = configure_file( configuration: testconf ) +mutter_tests_datadir = mutter_test_dep.get_variable('tests_datadir') +dbusrunnerconf = configuration_data() +dbusrunnerconf.set('MUTTER_TEST_PKGDATADIR', mutter_tests_datadir) +dbusrunnerconf.set('SRCDIR', meson.current_source_dir()) + +dbus_runner = configure_file( + input: 'gnome-shell-dbus-runner.py.in', + output: 'gnome-shell-dbus-runner.py', + configuration: dbusrunnerconf, +) + testenv = environment() testenv.set('GSETTINGS_SCHEMA_DIR', join_paths(meson.project_build_root(), 'data'))