on xenial help sign in
Update the screenlock autopilot tests.
2797093Leo Arias
tests/autopilot/unity8/process_helpers.py+3−3
@@ -162,7 +162,7 @@ def start_job(name, *args):
162 universal_newlines=True,
162 universal_newlines=True,
163 )
163 )
164 logger.info(output)
164 logger.info(output)
165− pid = _get_job_pid(name)
165+ pid = get_job_pid(name)
166 except subprocess.CalledProcessError as e:
166 except subprocess.CalledProcessError as e:
167 e.args += ('Failed to start {}: {}.'.format(name, e.output))
167 e.args += ('Failed to start {}: {}.'.format(name, e.output))
168 raise
168 raise
@@ -170,7 +170,7 @@ def start_job(name, *args):
170 return pid
170 return pid
171
171
172
172
173−def _get_job_pid(name):
173+def get_job_pid(name):
174 """Return the process id of a running job.
174 """Return the process id of a running job.
175
175
176 :param str name: The name of the job.
176 :param str name: The name of the job.
@@ -232,7 +232,7 @@ def _get_unity_status():
232
232
233def _get_unity_pid():
233def _get_unity_pid():
234 try:
234 try:
235− return _get_job_pid('unity8')
235+ return get_job_pid('unity8')
236 except JobError as error:
236 except JobError as error:
237 raise CannotAccessUnity(str(error))
237 raise CannotAccessUnity(str(error))
238
238
tests/autopilot/unity8/shell/emulators/greeter.py+4−1
@@ -17,6 +17,8 @@
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
18#
19
19
20+import ubuntuuitoolkit
21+
20from unity8.shell.emulators import UnityEmulatorBase
22from unity8.shell.emulators import UnityEmulatorBase
21
23
22
24
@@ -37,4 +39,5 @@ class Greeter(UnityEmulatorBase):
37 self.created.wait_for(False)
39 self.created.wait_for(False)
38
40
39 def get_prompt(self):
41 def get_prompt(self):
42+ return self.select_single(
40− return self.select_single("TextField", objectName="passwordInput")
43+ ubuntuuitoolkit.TextField, objectName='passwordInput')
tests/autopilot/unity8/shell/emulators/main_window.py+28−6
@@ -76,12 +76,6 @@ class QQuickView(emulators.UnityEmulatorBase):
76 objectName="pinPadLoader"
76 objectName="pinPadLoader"
77 )
77 )
78
78
79− def get_pinPadButton(self, buttonId):
80− return self.select_single(
81− "PinPadButton",
82− objectName="pinPadButton%i" % buttonId
83− )
84−
85 def get_lockscreen(self):
79 def get_lockscreen(self):
86 return self.select_single("Lockscreen")
80 return self.select_single("Lockscreen")
87
81
@@ -134,3 +128,31 @@ class QQuickView(emulators.UnityEmulatorBase):
134 @autopilot_logging.log_action(logger.info)
128 @autopilot_logging.log_action(logger.info)
135 def search(self, query):
129 def search(self, query):
136 self.get_dash().enter_search_query(query)
130 self.get_dash().enter_search_query(query)
131+
132+ @autopilot_logging.log_action(logger.info)
133+ def enter_pin_code(self, code):
134+ """Enter code 'code' into the single-pin lightdm pincode entry screen.
135+
136+ :param code: must be a string of numeric characters.
137+ :raises: TypeError if code is not a string.
138+ :raises: ValueError if code contains non-numeric characters.
139+
140+ """
141+ if not isinstance(code, str):
142+ raise TypeError(
143+ "'code' parameter must be a string, not %r."
144+ % type(code)
145+ )
146+ for num in code:
147+ if not num.isdigit():
148+ raise ValueError(
149+ "'code' parameter contains non-numeric characters."
150+ )
151+ self.pointing_device.click_object(
152+ self._get_pinpad_button(int(num)))
153+
154+ def _get_pinpad_button(self, button_id):
155+ return self.select_single(
156+ 'PinPadButton',
157+ objectName='pinPadButton{}'.format(button_id)
158+ )
tests/autopilot/unity8/shell/tests/__init__.py+15−8
@@ -24,6 +24,7 @@ try:
24except ImportError:
24except ImportError:
25 Gio = None
25 Gio = None
26
26
27+from autopilot import introspection
27from autopilot.platform import model
28from autopilot.platform import model
28from autopilot.testcase import AutopilotTestCase
29from autopilot.testcase import AutopilotTestCase
29from autopilot.matchers import Eventually
30from autopilot.matchers import Eventually
@@ -47,6 +48,7 @@ from unity8 import (
47 fixture_setup,
48 fixture_setup,
48 process_helpers
49 process_helpers
49)
50)
51+from unity8.shell import emulators
50from unity8.shell.emulators import (
52from unity8.shell.emulators import (
51 dash as dash_helpers,
53 dash as dash_helpers,
52 main_window as main_window_emulator,
54 main_window as main_window_emulator,
@@ -391,8 +393,13 @@ class UnityTestCase(AutopilotTestCase):
391
393
392
394
393 def get_dash(self):
395 def get_dash(self):
394− dash = self._proxy.wait_select_single(dash_helpers.Dash)
396+ pid = process_helpers.get_job_pid('unity8-dash')
397+ dash_proxy = introspection.get_proxy_object_for_existing_process(
398+ pid=pid,
399+ emulator_base=emulators.UnityEmulatorBase,
400+ )
401+ dash_app = dash_helpers.DashApp(dash_proxy)
395− return dash
402+ return dash_app.dash
396
403
397 @property
404 @property
398 def main_window(self):
405 def main_window(self):
@@ -433,6 +440,12 @@ class DashBaseTestCase(AutopilotTestCase):
433 self.dash_app = dash_helpers.DashApp(dash_proxy)
440 self.dash_app = dash_helpers.DashApp(dash_proxy)
434 self.dash = self.dash_app.dash
441 self.dash = self.dash_app.dash
435
442
443+ def launch_dash(self, binary_path, variables):
444+ launch_dash_app_fixture = fixture_setup.LaunchDashApp(
445+ binary_path, variables)
446+ self.useFixture(launch_dash_app_fixture)
447+ return launch_dash_app_fixture.application_proxy
448+
436 def should_simulate_device(self):
449 def should_simulate_device(self):
437 return (hasattr(self, 'app_width') and hasattr(self, 'app_height') and
450 return (hasattr(self, 'app_width') and hasattr(self, 'app_height') and
438 hasattr(self, 'grid_unit_px'))
451 hasattr(self, 'grid_unit_px'))
@@ -456,9 +469,3 @@ class DashBaseTestCase(AutopilotTestCase):
456 self.assertThat(
469 self.assertThat(
457 get_window_size,
470 get_window_size,
458 Eventually(Equals((self.app_width, self.app_height))))
471 Eventually(Equals((self.app_width, self.app_height))))
459−
460− def launch_dash(self, binary_path, variables):
461− launch_dash_app_fixture = fixture_setup.LaunchDashApp(
462− binary_path, variables)
463− self.useFixture(launch_dash_app_fixture)
464− return launch_dash_app_fixture.application_proxy
tests/autopilot/unity8/shell/tests/test_lock_screen.py+8−47
@@ -48,10 +48,11 @@ class TestLockscreen(UnityTestCase):
48 unity_proxy = self.launch_unity()
48 unity_proxy = self.launch_unity()
49 greeter = self.main_window.get_greeter()
49 greeter = self.main_window.get_greeter()
50
50
51+
51 if greeter.narrowMode:
52 if greeter.narrowMode:
52 unlock_unity(unity_proxy)
53 unlock_unity(unity_proxy)
53 lockscreen = self._wait_for_lockscreen()
54 lockscreen = self._wait_for_lockscreen()
54− self._enter_pincode("1234")
55+ self.main_window.enter_pin_code("1234")
55 self.assertThat(lockscreen.shown, Eventually(Equals(False)))
56 self.assertThat(lockscreen.shown, Eventually(Equals(False)))
56 else:
57 else:
57 self._enter_prompt_passphrase("1234")
58 self._enter_prompt_passphrase("1234")
@@ -81,7 +82,7 @@ class TestLockscreen(UnityTestCase):
81 if greeter.narrowMode:
82 if greeter.narrowMode:
82 unlock_unity(unity_proxy)
83 unlock_unity(unity_proxy)
83 lockscreen = self._wait_for_lockscreen()
84 lockscreen = self._wait_for_lockscreen()
84− self._enter_pincode("4321")
85+ self.main_window.enter_pin_code("4321")
85 pinentryField = self.main_window.get_pinentryField()
86 pinentryField = self.main_window.get_pinentryField()
86 self.assertThat(pinentryField.text, Eventually(Equals("")))
87 self.assertThat(pinentryField.text, Eventually(Equals("")))
87 self.assertThat(lockscreen.shown, Eventually(Equals(True)))
88 self.assertThat(lockscreen.shown, Eventually(Equals(True)))
@@ -118,28 +119,6 @@ class TestLockscreen(UnityTestCase):
118 self.assertThat(lockscreen.shown, Eventually(Equals(True)))
119 self.assertThat(lockscreen.shown, Eventually(Equals(True)))
119 return lockscreen
120 return lockscreen
120
121
121− def _enter_pincode(self, code):
122− """Enter code 'code' into the single-pin lightdm pincode entry
123− screen.
124−
125− :param code: must be a string of numeric characters.
126− :raises: TypeError if code is not a string.
127− :raises: ValueError if code contains non-numeric characters.
128−
129− """
130−
131− if not isinstance(code, basestring):
132− raise TypeError(
133− "'code' parameter must be a string, not %r."
134− % type(code)
135− )
136− for num in code:
137− if not num.isdigit():
138− raise ValueError(
139− "'code' parameter contains non-numeric characters."
140− )
141− self.touch.tap_object(self.main_window.get_pinPadButton(int(num)))
142−
143 def _enter_pin_passphrase(self, passphrase):
122 def _enter_pin_passphrase(self, passphrase):
144 """Enter the password specified in 'passphrase' into the password entry
123 """Enter the password specified in 'passphrase' into the password entry
145 field of the pin lock screen.
124 field of the pin lock screen.
@@ -148,18 +127,15 @@ class TestLockscreen(UnityTestCase):
148 :raises: TypeError if passphrase is not a string.
127 :raises: TypeError if passphrase is not a string.
149
128
150 """
129 """
151− if not isinstance(passphrase, basestring):
130+ if not isinstance(passphrase, str):
152 raise TypeError(
131 raise TypeError(
153 "'passphrase' parameter must be a string, not %r."
132 "'passphrase' parameter must be a string, not %r."
154 % type(passphrase)
133 % type(passphrase)
155 )
134 )
156
135
157− pinentryField = self.main_window.get_pinentryField()
136+ pin_entry_field = self.main_window.get_pinentryField()
158− self.touch.tap_object(pinentryField)
137+ pin_entry_field.write(passphrase)
159− self.assertThat(pinentryField.activeFocus, Eventually(Equals(True)))
160− for character in passphrase:
161− self._type_character(character, pinentryField)
162− logger.debug("Typed passphrase: %s", pinentryField.text)
138+ logger.debug("Typed passphrase: %s", pin_entry_field.text)
163 self.keyboard.type("\n")
139 self.keyboard.type("\n")
164
140
165 def _enter_prompt_passphrase(self, passphrase):
141 def _enter_prompt_passphrase(self, passphrase):
@@ -177,21 +153,6 @@ class TestLockscreen(UnityTestCase):
177 )
153 )
178
154
179 prompt = self.main_window.get_greeter().get_prompt()
155 prompt = self.main_window.get_greeter().get_prompt()
180− self.touch.tap_object(prompt)
181− self.assertThat(prompt.activeFocus, Eventually(Equals(True)))
182− for character in passphrase:
156+ prompt.write(passphrase)
183− self._type_character(character, prompt)
184 logger.debug("Typed passphrase: %s", prompt.text)
157 logger.debug("Typed passphrase: %s", prompt.text)
185 self.keyboard.type("\n")
158 self.keyboard.type("\n")
186−
187− def _type_character(self, character, prompt, retries=5):
188− current_text = prompt.text
189− self.keyboard.type(character)
190− try:
191− self.assertThat(
192− prompt.text, Eventually(Equals(current_text + character)))
193− except AssertionError:
194− if retries > 0:
195− self._type_character(character, prompt, retries-1)
196− else:
197− raise