Unity 8
__init__.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, 2015 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 import dbus
21 
22 import ubuntuuitoolkit
23 from autopilot.matchers import Eventually
24 from testtools.matchers import Equals
25 from autopilot.utilities import sleep
26 
27 
28 def hide_greeter_with_dbus():
29  dbus_proxy = _get_greeter_dbus_proxy()
30  if _is_greeter_active():
31  dbus_proxy.HideGreeter()
32 
33 
34 def show_greeter_with_dbus():
35  dbus_proxy = _get_greeter_dbus_proxy()
36  if not _is_greeter_active():
37  dbus_proxy.ShowGreeter()
38 
39 
40 def wait_for_greeter():
41  Eventually(Equals(True), timeout=300).match(_is_greeter_active)
42 
43 
44 def _get_greeter_dbus_proxy():
45  bus = dbus.SessionBus()
46  return bus.get_object('com.canonical.UnityGreeter', '/')
47 
48 
49 def _is_greeter_active():
50  try:
51  dbus_proxy = _get_greeter_dbus_proxy()
52  return dbus_proxy.Get('com.canonical.UnityGreeter', 'IsActive')
53  except:
54  return False
55 
56 
57 class Greeter(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
58  """A helper that understands the greeter screen."""
59 
60  def wait_swiped_away(self):
61  # We have to be careful here, because coverPage can go away at any time
62  # if there isn't a lockscreen behind it (it hides completely, then
63  # the greeter disposes it). But if there *is* a lockscreen, then we
64  # need a different check, by looking at its showProgress. So make our
65  # own wait_for loop and check both possibilities.
66  for i in range(10):
67  if not self.required:
68  return
69  coverPage = self.select_single(objectName='coverPage')
70  if coverPage.showProgress == 0:
71  return
72  sleep(1)
73 
74  raise AssertionError("Greeter cover page still up after 10s")
75 
76  def swipe(self):
77  """Swipe the greeter screen away."""
78  self.waiting.wait_for(False)
79  coverPage = self.select_single(objectName='coverPage')
80  coverPage.showProgress.wait_for(1)
81 
82  rect = self.globalRect
83  start_x = rect[0] + rect[2] - 3
84  start_y = int(rect[1] + rect[3] / 2)
85  stop_x = int(rect[0] + rect[2] * 0.2)
86  stop_y = start_y
87  self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
88 
89  self.wait_swiped_away()
90 
91  def get_prompt(self):
92  return self.select_single(
93  ubuntuuitoolkit.TextField, objectName='passwordInput')
def wait_swiped_away(self)
Definition: __init__.py:60