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