Unity 8
 All Classes Functions
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 import with_lightdm_mock
24 from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
25 
26 from autopilot.matchers import Eventually
27 import sys
28 from testtools.matchers import Equals
29 import logging
30 
31 logger = logging.getLogger(__name__)
32 
33 # py2 compatible alias for py3
34 if sys.version >= '3':
35  basestring = str
36 
37 
39 
40  """Tests for the lock screen."""
41 
42  scenarios = _get_device_emulation_scenarios()
43 
44  @with_lightdm_mock("single-pin")
46  """Must be able to unlock the PIN entry lock screen."""
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 
59  @with_lightdm_mock("single-passphrase")
61  """Must be able to unlock the passphrase entry screen."""
62  self.launch_unity()
63  greeter = self.main_window.get_greeter()
64 
65  if greeter.narrowMode:
66  greeter.swipe()
67  lockscreen = self._wait_for_lockscreen()
68  self._enter_pin_passphrase("password")
69  self.assertThat(lockscreen.shown, Eventually(Equals(False)))
70  else:
71  self._enter_prompt_passphrase("password")
72  self.assertThat(greeter.shown, Eventually(Equals(False)))
73 
74  @with_lightdm_mock("single-pin")
76  """Entering the wrong pin code must not dismiss the lock screen."""
77  self.launch_unity()
78  greeter = self.main_window.get_greeter()
79 
80  if greeter.narrowMode:
81  greeter.swipe()
82  lockscreen = self._wait_for_lockscreen()
83  self.main_window.enter_pin_code("4321")
84  pinentryField = self.main_window.get_pinentryField()
85  self.assertThat(pinentryField.text, Eventually(Equals("")))
86  self.assertThat(lockscreen.shown, Eventually(Equals(True)))
87  else:
88  self._enter_prompt_passphrase("4231\n")
89  prompt = self.main_window.get_greeter().get_prompt()
90  self.assertThat(prompt.text, Eventually(Equals("")))
91  self.assertThat(greeter.shown, Eventually(Equals(True)))
92 
93  @with_lightdm_mock("single-passphrase")
95  """Entering the wrong password must not dismiss the lock screen."""
96  self.launch_unity()
97  greeter = self.main_window.get_greeter()
98 
99  if greeter.narrowMode:
100  greeter.swipe()
101  lockscreen = self._wait_for_lockscreen()
102  self._enter_pin_passphrase("foobar")
103  pinentryField = self.main_window.get_pinentryField()
104  self.assertThat(pinentryField.text, Eventually(Equals("")))
105  self.assertThat(lockscreen.shown, Eventually(Equals(True)))
106  else:
107  self._enter_prompt_passphrase("foobar")
108  prompt = self.main_window.get_greeter().get_prompt()
109  self.assertThat(prompt.text, Eventually(Equals("")))
110  self.assertThat(greeter.shown, Eventually(Equals(True)))
111 
112  def _wait_for_lockscreen(self):
113  """Wait for the lock screen to load, and return it."""
114  pinPadLoader = self.main_window.get_pinPadLoader()
115  self.assertThat(pinPadLoader.progress, Eventually(Equals(1)))
116  lockscreen = self.main_window.get_lockscreen()
117  self.assertThat(lockscreen.shown, Eventually(Equals(True)))
118  return lockscreen
119 
120  def _enter_pin_passphrase(self, passphrase):
121  """Enter the password specified in 'passphrase' into the password entry
122  field of the pin lock screen.
123 
124  :param passphrase: The string you want to enter.
125  :raises: TypeError if passphrase is not a string.
126 
127  """
128  if not isinstance(passphrase, str):
129  raise TypeError(
130  "'passphrase' parameter must be a string, not %r."
131  % type(passphrase)
132  )
133 
134  pin_entry_field = self.main_window.get_pinentryField()
135  pin_entry_field.write(passphrase)
136  logger.debug("Typed passphrase: %s", pin_entry_field.text)
137  self.keyboard.type("\n")
138 
139  def _enter_prompt_passphrase(self, passphrase):
140  """Enter the password specified in 'passphrase' into the password entry
141  field of the main user list's prompt.
142 
143  :param passphrase: The string you want to enter.
144  :raises: TypeError if passphrase is not a string.
145 
146  """
147  if not isinstance(passphrase, basestring):
148  raise TypeError(
149  "'passphrase' parameter must be a string, not %r."
150  % type(passphrase)
151  )
152 
153  prompt = self.main_window.get_greeter().get_prompt()
154  prompt.write(passphrase)
155  logger.debug("Typed passphrase: %s", prompt.text)
156  self.keyboard.type("\n")