28
29
from autopilot.testcase import AutopilotTestCase
29
30
from autopilot.input import Pointer, Touch
31
from autopilot.introspection import get_proxy_object_for_existing_process
30
32
from autopilot.matchers import Eventually
31
33
from autopilot.platform import model
34
from unity8 import process_helpers
35
from unity8.shell.emulators.dash import Dash
36
from unity8.shell.emulators import UnityEmulatorBase
32
37
from ubuntuuitoolkit import base
34
39
from ubuntu_keyboard.emulators.keyboard import Keyboard
40
45
logger = logging.getLogger(__name__)
43
def _get_maliit_server_status():
45
return subprocess.check_output([
50
except subprocess.CalledProcessError as e:
51
e.args += ("maliit-server appears to be an unknown service.", )
55
def _stop_maliit_server():
56
status = _get_maliit_server_status()
49
status = process_helpers._get_unity_status()
57
50
if "start/" in status:
59
logger.debug("Stopping maliit server")
60
subprocess.check_call(['initctl', 'stop', 'maliit-server'])
52
logger.debug("Stopping unity8")
53
subprocess.check_call(['initctl', 'stop', 'unity8'])
61
54
except subprocess.CalledProcessError as e:
62
e.args += ("Unable to stop mallit server",)
55
e.args += ("Unable to stop unity8",)
65
logger.debug("No need to stop server.")
68
def _start_maliit_server(args):
69
status = _get_maliit_server_status()
58
logger.debug("No need to stop unity.")
62
status = process_helpers._get_unity_status()
70
63
if "stop/" in status:
73
"Starting maliit-server with the args: '%s'" % ",".join(args)
75
subprocess.check_call(
76
['initctl', 'start', 'maliit-server'] + args
65
logger.debug("Starting unity8")
66
subprocess.check_call(['initctl', 'start', 'unity8'])
78
67
except subprocess.CalledProcessError as e:
79
e.args += ("Unable to start mallit server",)
68
e.args += ("Unable to start unity8",)
82
71
raise RuntimeError(
83
"Unable to start maliit-server: server is currently running."
87
def _restart_maliit_server(args=None):
91
_start_maliit_server(args)
72
"Unable to start unity8: server is currently running."
76
def _assertUnityReady():
77
unity_pid = process_helpers._get_unity_pid()
78
unity = get_proxy_object_for_existing_process(
80
emulator_base=UnityEmulatorBase,
82
dash = unity.wait_select_single(Dash)
83
home_scope = dash.get_scope('home')
85
home_scope.isLoaded.wait_for(True)
86
home_scope.isCurrent.wait_for(True)
89
def _restart_unity8():
94
94
class UbuntuKeyboardTests(AutopilotTestCase):
95
maliit_override_file = os.path.expanduser(
96
"~/.config/upstart/maliit-server.override"
96
100
def setUpClass(cls):
97
_restart_maliit_server(['QT_LOAD_TESTABILITY=1'])
102
logger.debug("Creating the override file.")
104
UbuntuKeyboardTests.maliit_override_file, 'w'
106
override_file.write("exec maliit-server -testability")
108
process_helpers.restart_unity_with_testability()
110
#### FIXME: This is a work around re: lp:1238417 ####
111
if model() != "Desktop":
112
from autopilot.input import _uinput
113
_uinput._touch_device = _uinput.create_touch_device()
116
#### FIXME: Workaround re: lp:1248902 and lp:1248913
117
logger.debug("Waiting for maliit-server to be ready")
123
"Failed attempting to write override file to {file}".format(
124
file=UbuntuKeyboardTests.maliit_override_file
100
130
def tearDownClass(cls):
101
_restart_maliit_server()
132
os.remove(UbuntuKeyboardTests.maliit_override_file)
134
logger.warning("Attempted to remove non-existent override file")
104
138
if model() == "Desktop":