1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2013 Canonical
5
# This program is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 3, as published
7
# by the Free Software Foundation.
11
from autopilot.introspection import ApplicationIntrospectionTestMixin, get_autopilot_proxy_object_for_process
12
from autopilot.emulators.dbus_handler import get_session_bus
16
def find_process(process_name):
17
"""Returns a psutil process similar to a Popen process."""
19
def process_name_equals(process):
20
if process.name == process_name:
24
processes = filter(process_name_equals, psutil.get_process_list())
31
class UnityPanelServiceTestMixin(ApplicationIntrospectionTestMixin):
33
def _update_activation_environment_with_autopilot(self):
34
"""Add 'autopilot' to GTK_MODULES via Unity dbus-activation.
36
When unity-panel-service automatically re-launches, it'll come back with
37
'autopilot' in its GTK_MODULES.
40
session_bus = get_session_bus()
41
proxy = session_bus.get_object('org.freedesktop.DBus',
42
"/org/freedesktop/DBus")
43
proxy.UpdateActivationEnvironment({'GTK_MODULES':
47
def _kill_unity_panel_service(self):
48
"""Kill the process named 'unity-panel-service'."""
50
unity_panel_service = find_process('unity-panel-service')
51
if unity_panel_service==None:
53
unity_panel_service.kill()
56
def prepare_environment(self):
57
"""Set up 'unity-panel-service' as our app."""
59
# add our GTK_MODULES to Unity's DBus launching env
60
self._update_activation_environment_with_autopilot()
61
# kill the indicators; they'll come back with 'autopilot' appended to GTK_MODULES
62
self._kill_unity_panel_service()
63
# wait until the unity-panel-service comes back
64
unity_panel_service_process = None
65
while unity_panel_service_process == None:
66
unity_panel_service_process = find_process('unity-panel-service')
67
self.app = get_autopilot_proxy_object_for_process(
68
unity_panel_service_process)