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 not greeter.tabletMode:
51  greeter.swipe()
52  lockscreen = self._wait_for_lockscreen()
53  self.main_window.enter_pin_code("1234")
54  else:
55  self._enter_prompt_passphrase("1234\n")
56  self.assertThat(greeter.shown, Eventually(Equals(False)))
57 
59  """Must be able to unlock the passphrase entry screen."""
60 
61  self._environment['LIBLIGHTDM_MOCK_MODE'] = "single-passphrase"
62  self.launch_unity()
63  greeter = self.main_window.get_greeter()
64 
65  if not greeter.tabletMode:
66  greeter.swipe()
67  lockscreen = self._wait_for_lockscreen()
68  self._enter_pin_passphrase("password")
69  else:
70  self._enter_prompt_passphrase("password")
71  self.assertThat(greeter.shown, Eventually(Equals(False)))
72 
74  """Entering the wrong pin code must not dismiss the lock screen."""
75  self._environment['LIBLIGHTDM_MOCK_MODE'] = "single-pin"
76  self.launch_unity()
77  greeter = self.main_window.get_greeter()
78 
79  if not greeter.tabletMode:
80  greeter.swipe()
81  lockscreen = self._wait_for_lockscreen()
82  self.main_window.enter_pin_code("4321")
83  pinentryField = self.main_window.get_pinentryField()
84  self.assertThat(pinentryField.text, Eventually(Equals("")))
85  else:
86  self._enter_prompt_passphrase("4231\n")
87  prompt = self.main_window.get_greeter().get_prompt()
88  self.assertThat(prompt.text, Eventually(Equals("")))
89  self.assertThat(greeter.shown, Eventually(Equals(True)))
90 
92  """Entering the wrong password must not dismiss the lock screen."""
93  self._environment['LIBLIGHTDM_MOCK_MODE'] = "single-passphrase"
94  self.launch_unity()
95  greeter = self.main_window.get_greeter()
96 
97  if not greeter.tabletMode:
98  greeter.swipe()
99  lockscreen = self._wait_for_lockscreen()
100  self._enter_pin_passphrase("foobar")
101  pinentryField = self.main_window.get_pinentryField()
102  self.assertThat(pinentryField.text, Eventually(Equals("")))
103  else:
104  self._enter_prompt_passphrase("foobar")
105  prompt = self.main_window.get_greeter().get_prompt()
106  self.assertThat(prompt.text, Eventually(Equals("")))
107  self.assertThat(greeter.shown, Eventually(Equals(True)))
108 
109  def _wait_for_lockscreen(self):
110  """Wait for the lock screen to load, and return it."""
111  pinPadLoader = self.main_window.get_pinPadLoader()
112  self.assertThat(pinPadLoader.progress, Eventually(Equals(1)))
113  lockscreen = self.main_window.get_lockscreen()
114  self.assertThat(lockscreen.shown, Eventually(Equals(True)))
115  return lockscreen
116 
117  def _enter_pin_passphrase(self, passphrase):
118  """Enter the password specified in 'passphrase' into the password entry
119  field of the pin lock screen.
120 
121  :param passphrase: The string you want to enter.
122  :raises: TypeError if passphrase is not a string.
123 
124  """
125  if not isinstance(passphrase, str):
126  raise TypeError(
127  "'passphrase' parameter must be a string, not %r."
128  % type(passphrase)
129  )
130 
131  pin_entry_field = self.main_window.get_pinentryField()
132  # pinentryField should automatically have focus
133  self.keyboard.type(passphrase)
134  logger.debug("Typed passphrase: %s", pin_entry_field.text)
135  self.assertEqual(pin_entry_field.text, passphrase)
136  self.keyboard.type("\n")
137 
138  def _enter_prompt_passphrase(self, passphrase):
139  """Enter the password specified in 'passphrase' into the password entry
140  field of the main user list's prompt.
141 
142  :param passphrase: The string you want to enter.
143  :raises: TypeError if passphrase is not a string.
144 
145  """
146  if not isinstance(passphrase, basestring):
147  raise TypeError(
148  "'passphrase' parameter must be a string, not %r."
149  % type(passphrase)
150  )
151 
152  prompt = self.main_window.get_greeter().get_prompt()
153  prompt.write(passphrase)
154  logger.debug("Typed passphrase: %s", prompt.text)
155  self.keyboard.type("\n")
def launch_unity(self, kwargs)
Definition: __init__.py:256