Unity 8
test_lock_screen.py
1 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2 #
3 # Unity Autopilot Test Suite
4 # Copyright (C) 2012, 2013, 2014 Canonical
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19 
20 
21 from __future__ import absolute_import
22 
23 from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
24 
25 from autopilot.matchers import Eventually
26 import sys
27 from testtools.matchers import Equals
28 import logging
29 
30 logger = logging.getLogger(__name__)
31 
32 # py2 compatible alias for py3
33 if sys.version >= '3':
34  basestring = str
35 
36 
38 
39  """Tests for the lock screen."""
40 
41  scenarios = _get_device_emulation_scenarios()
42 
44  """Must be able to unlock the PIN entry lock screen."""
45 
46  self._environment['LIBLIGHTDM_MOCK_MODE'] = "single-pin"
47  self.launch_unity()
48  greeter = self.main_window.get_greeter()
49 
50  if greeter.narrowMode:
51  greeter.swipe()
52  lockscreen = self._wait_for_lockscreen()
53  self.main_window.enter_pin_code("1234")
54  self.assertThat(lockscreen.shown, Eventually(Equals(False)))
55  else:
56  self._enter_prompt_passphrase("1234\n")
57  self.assertThat(greeter.shown, Eventually(Equals(False)))
58 
60  """Must be able to unlock the passphrase entry screen."""
61 
62  self._environment['LIBLIGHTDM_MOCK_MODE'] = "single-passphrase"
63  self.launch_unity()
64  greeter = self.main_window.get_greeter()
65 
66  if greeter.narrowMode:
67  greeter.swipe()
68  lockscreen = self._wait_for_lockscreen()
69  self._enter_pin_passphrase("password")
70  self.assertThat(lockscreen.shown, Eventually(Equals(False)))
71  else:
72  self._enter_prompt_passphrase("password")
73  self.assertThat(greeter.shown, Eventually(Equals(False)))
74 
76  """Entering the wrong pin code must not dismiss the lock screen."""
77  self._environment['LIBLIGHTDM_MOCK_MODE'] = "single-pin"
78  self.launch_unity()
79  greeter = self.main_window.get_greeter()
80 
81  if greeter.narrowMode:
82  greeter.swipe()
83  lockscreen = self._wait_for_lockscreen()
84  self.main_window.enter_pin_code("4321")
85  pinentryField = self.main_window.get_pinentryField()
86  self.assertThat(pinentryField.text, Eventually(Equals("")))
87  self.assertThat(lockscreen.shown, Eventually(Equals(True)))
88  else:
89  self._enter_prompt_passphrase("4231\n")
90  prompt = self.main_window.get_greeter().get_prompt()
91  self.assertThat(prompt.text, Eventually(Equals("")))
92  self.assertThat(greeter.shown, Eventually(Equals(True)))
93 
95  """Entering the wrong password must not dismiss the lock screen."""
96  self._environment['LIBLIGHTDM_MOCK_MODE'] = "single-passphrase"
97  self.launch_unity()
98  greeter = self.main_window.get_greeter()
99 
100  if greeter.narrowMode:
101  greeter.swipe()
102  lockscreen = self._wait_for_lockscreen()
103  self._enter_pin_passphrase("foobar")
104  pinentryField = self.main_window.get_pinentryField()
105  self.assertThat(pinentryField.text, Eventually(Equals("")))
106  self.assertThat(lockscreen.shown, Eventually(Equals(True)))
107  else:
108  self._enter_prompt_passphrase("foobar")
109  prompt = self.main_window.get_greeter().get_prompt()
110  self.assertThat(prompt.text, Eventually(Equals("")))
111  self.assertThat(greeter.shown, Eventually(Equals(True)))
112 
113  def _wait_for_lockscreen(self):
114  """Wait for the lock screen to load, and return it."""
115  pinPadLoader = self.main_window.get_pinPadLoader()
116  self.assertThat(pinPadLoader.progress, Eventually(Equals(1)))
117  lockscreen = self.main_window.get_lockscreen()
118  self.assertThat(lockscreen.shown, Eventually(Equals(True)))
119  return lockscreen
120 
121  def _enter_pin_passphrase(self, passphrase):
122  """Enter the password specified in 'passphrase' into the password entry
123  field of the pin lock screen.
124 
125  :param passphrase: The string you want to enter.
126  :raises: TypeError if passphrase is not a string.
127 
128  """
129  if not isinstance(passphrase, str):
130  raise TypeError(
131  "'passphrase' parameter must be a string, not %r."
132  % type(passphrase)
133  )
134 
135  pin_entry_field = self.main_window.get_pinentryField()
136  # pinentryField should automatically have focus
137  self.keyboard.type(passphrase)
138  logger.debug("Typed passphrase: %s", pin_entry_field.text)
139  self.assertEqual(pin_entry_field.text, passphrase)
140  self.keyboard.type("\n")
141 
142  def _enter_prompt_passphrase(self, passphrase):
143  """Enter the password specified in 'passphrase' into the password entry
144  field of the main user list's prompt.
145 
146  :param passphrase: The string you want to enter.
147  :raises: TypeError if passphrase is not a string.
148 
149  """
150  if not isinstance(passphrase, basestring):
151  raise TypeError(
152  "'passphrase' parameter must be a string, not %r."
153  % type(passphrase)
154  )
155 
156  prompt = self.main_window.get_greeter().get_prompt()
157  prompt.write(passphrase)
158  logger.debug("Typed passphrase: %s", prompt.text)
159  self.keyboard.type("\n")
def launch_unity(self, kwargs)
Definition: __init__.py:256