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