Debian Codegraph @

tests/autopilot/lomiriuitoolkit/_custom_proxy_objects/popups.py

raw
1 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2 #
3 # Copyright (C) 2012, 2013, 2014 Canonical Ltd.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation; version 3.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 import logging
18
19 from autopilot import logging as autopilot_logging
20 from autopilot.introspection import dbus
21 from autopilot import introspection
22
23 from lomiriuitoolkit._custom_proxy_objects import _common
24
25
26 logger = logging.getLogger(__name__)
27
28
29 class Dialog(_common.LomiriUIToolkitCustomProxyObjectBase):
30 """Autopilot helper for the Dialog component."""
31
32
33 class TextInputPopover(_common.LomiriUIToolkitCustomProxyObjectBase):
34 """TextInputPopover Autopilot emulator ."""
35
36 def click_option_by_text(self, text):
37 """Click a button on the popover.
38
39 XXX We are receiving the text because there's no way to set the
40 objectName on the action. This is reported at
41 https://bugs.launchpad.net/lomiri-ui-toolkit/+bug/1205144
42 --elopio - 2013-07-25
43
44 :parameter text: The text of the button.
45 :raise ToolkitException: If the popover is not open.
46
47 """
48 if not self.visible:
49 raise _common.ToolkitException('The popover is not open.')
50 button = self._get_button(text)
51 if button is None:
52 raise _common.ToolkitException(
53 'Button with text "{0}" not found.'.format(text))
54 self.pointing_device.click_object(button)
55 if self.autoClose:
56 try:
57 self.visible.wait_for(False)
58 except dbus.StateNotFoundError:
59 # The popover was removed from the tree.
60 pass
61
62 def _get_button(self, text):
63 # Try the C++ class name in case this is a 1.3 AbstractButton
64 try:
65 return self.wait_select_single(
66 'LomiriToolkit::UCAbstractButton', text=text)
67 except dbus.StateNotFoundError:
68 return self.wait_select_single('AbstractButton', text=text)
69
70
71 class ActionSelectionPopover(_common.LomiriUIToolkitCustomProxyObjectBase):
72 """ActionSelectionPopover Autopilot custom proxy object."""
73
74 @classmethod
75 def validate_dbus_object(cls, path, state):
76 if super().validate_dbus_object(path, state):
77 return True
78
79 name = introspection.get_classname_from_path(path)
80 if name == b'OverflowPanel':
81 return True
82 if name == b'ListItemPopover':
83 return True
84
85 return False
86
87 def click_action_button(self, action_object_name):
88 """Click an action button on the popover.
89
90 :parameter object_name: The QML objectName property of the action
91 :raise ToolkitException: If there is no visible button with that object
92 name or the popover is not open.
93
94 """
95
96 if not self.visible:
97 raise _common.ToolkitException('The popover is not open.')
98 try:
99 object_name = action_object_name + "_button"
100 button = self.select_single(objectName=object_name)
101 except dbus.StateNotFoundError:
102 raise _common.ToolkitException(
103 'Button for action with objectName "{0}" not found.'.format(
104 action_object_name))
105 if not button.visible:
106 raise _common.ToolkitException(
107 'Button for action with objectName "{0}" not visible.'.format(
108 action_object_name))
109 self.pointing_device.click_object(button)
110 if self.autoClose:
111 try:
112 self.visible.wait_for(False)
113 except dbus.StateNotFoundError:
114 # The popover was removed from the tree.
115 pass
116
117 def click_button_by_text(self, text):
118 """Click a button on the popover.
119
120 :parameter text: The text of the button.
121 :raise ToolkitException: If there is no visible button with that label
122 or the popover is not open.
123
124 """
125 if not self.visible:
126 raise _common.ToolkitException('The popover is not open.')
127 button = self._get_button(text)
128 if button is None:
129 raise _common.ToolkitException(
130 'Button with text "{0}" not found.'.format(text))
131 self.pointing_device.click_object(button)
132 if self.autoClose:
133 try:
134 self.visible.wait_for(False)
135 except dbus.StateNotFoundError:
136 # The popover was removed from the tree.
137 pass
138
139 def _get_button(self, text):
140 buttons = self.select_many('Empty')
141 for button in buttons:
142 if button.text == text:
143 return button
144
145
146 class ComposerSheet(_common.LomiriUIToolkitCustomProxyObjectBase):
147 """ComposerSheet Autopilot custom proxy object."""
148
149 @autopilot_logging.log_action(logger.info)
150 def confirm(self):
151 """Confirm the composer sheet."""
152 button = self.select_single('Button', objectName='confirmButton')
153 self.pointing_device.click_object(button)
154 self.wait_until_destroyed()
155
156 @autopilot_logging.log_action(logger.info)
157 def cancel(self):
158 """Cancel the composer sheet."""
159 button = self.select_single('Button', objectName='cancelButton')
160 self.pointing_device.click_object(button)
161 self.wait_until_destroyed()