~canonical-platform-qa/ubuntu-system-tests/change-protected-modules-to-public

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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-

#
# Ubuntu System Tests
# Copyright (C) 2015, 2016 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 import logging as autopilot_logging
from unity8 import UnityException

from ubuntu_system_tests.helpers.autopilot import validate_dbus_object
from ubuntu_system_tests.helpers.indicators.message import NotificationsIndicatorItem  # NOQA
from ubuntu_system_tests.helpers.notifications.utils import Notifications
from ubuntu_system_tests.helpers.unity8 import UNITY8_PATH_ROOT
from ubuntu_system_tests.helpers.ubuntuuitoolkit._custom_proxy_objects._common import UbuntuUIToolkitCustomProxyObjectBase  # NOQA
logger = logging.getLogger(__name__)


class ShellView(UbuntuUIToolkitCustomProxyObjectBase):
    """Class to extend Unity8 main window ShellView."""

    @classmethod
    def validate_dbus_object(cls, path, state):
        return validate_dbus_object(
            path, state, UNITY8_PATH_ROOT, b'ShellView', title='Unity8')

    def get_notifications_list(self):
        """Return a list of notifications currently being displayed."""
        return self.select_single(
            Notifications, objectName='notificationList')

    def get_notifications_panel(self):
        """Return 'Notifications' panel object."""
        return self._get_indicator_panel_item('indicator-messages')

    def clear_notifications(self):
        """
        Clear all existing notifications from 'Notifications' indicator.

        """
        if self.is_new_notification_displayed():
            self.open_indicator_page('indicator-messages').clear_all()
            self.close_indicator_page()

    def open_notifications_indicator(self):
        """Swipe down to display the notifications indicator."""
        return self.open_indicator_page('indicator-messages')

    def is_new_notification_displayed(self):
        """Return True if new notification message icon is displayed."""
        return self.get_notifications_panel().is_new_message_displayed()

    def get_passphrase_unlock_screen(self):
        """Wait for input method to be in shown state and return lockscreen."""
        from ubuntu_system_tests.helpers.unity8 import lock_screen
        input_method = self.wait_select_single(
            'InputMethod', objectName='inputMethod', visible=True)
        input_method.state.wait_for('shown')
        return self.select_single(lock_screen.PassphraseLockscreen)

    def get_missed_call_snap_decision(self):
        """Return missed call snap decision menu."""
        from ubuntu_system_tests.helpers.snap_decision import missed_call
        return self.select_single(
            missed_call.SnapDecisionMenu, objectName='snapDecision',
            visible=True)

    def get_phone_stage(self):
        from ubuntu_system_tests.helpers.unity8 import phone_stage
        return self.select_single(phone_stage.PhoneStage, objectName='stage')

    def swipe_to_show_app_switcher(self):
        """Swipe from right edge to reveal task switcher."""
        stage = self.get_phone_stage()
        stage.swipe_to_top()
        return stage

    def get_settings_wizard(self):
        """Return settings wizard custom proxy object."""
        from ubuntu_system_tests.helpers.unity8.settings_wizard import Wizard
        return self.select_single(Wizard)

    def get_current_focused_app(self):
        """Return Id for current focused app."""
        return self.select_single('Shell').focusedApplicationId

    def get_info_popup(self, **kwargs):
        """Return information popup dialog or None if not found."""
        from ubuntu_system_tests.helpers.unity8.shell_dialog import ShellDialog
        # Use get_children_by_type to make the search fast
        shell = self.get_children_by_type('OrientedShell')[0]
        popup_list = shell.get_children_by_type(
            ShellDialog, objectName='infoPopup', **kwargs)
        if popup_list:
            popup = popup_list[0]
            popup.visible.wait_for(True)
            return popup
        return None

    def _is_indicator_panel_opened(self):
        indicator_page = self.wait_select_single('IndicatorsMenu')
        return indicator_page.fullyOpened

    def close_indicator_page(self):
        """Swipe to close the opened indicator, wait until it's closed."""
        if self._is_indicator_panel_opened():
            indicators_menu = self.wait_select_single('IndicatorsMenu')
            end_x, end_y = input.get_center_point(indicators_menu)
            start_x = end_x
            start_y = self.height
            self.pointing_device.drag(start_x, start_y, end_x, end_y)
            indicators_menu.fullyClosed.wait_for(True)

    def is_indicator_item_hidden(self, indicator_name):
        """
        Return bool representing if the requested indicator item is hidden or
        not.
        """
        item = self.select_single('IndicatorItem',
                                  objectName=indicator_name + '-panelItem')
        return item.hidden

    def get_greeter(self):
        return self.select_single('Greeter')

    def get_login_loader(self):
        return self.select_single("QQuickLoader", objectName="loginLoader")

    def get_login_list(self):
        return self.select_single("LoginList")

    def get_bottombar(self):
        return self.select_single("Bottombar")

    def get_pinPadLoader(self):
        return self.select_single(
            "QQuickLoader",
            objectName="pinPadLoader"
        )

    def get_lockscreen(self):
        return self.select_single("Lockscreen")

    def get_pinentryField(self):
        return self.select_single(objectName="pinentryField")

    def _get_indicator_panel_item(self, indicator_name):
        return self.select_single(
            'IndicatorItem',
            objectName=indicator_name + '-panelItem'
        )

    def _get_indicator_page(self, indicator_name):
        return self.select_single(
            'IndicatorPage',
            objectName=indicator_name + '-page'
        )

    @autopilot_logging.log_action(logger.info)
    def open_indicator_page(self, indicator_name):
        """Swipe to open the indicator, wait until it's open.

        :returns: The indicator page.
        """
        widget = self._get_indicator_panel_item(indicator_name)
        start_x, start_y = input.get_center_point(widget)
        end_x = start_x
        end_y = self.height
        self.pointing_device.drag(start_x, start_y, end_x, end_y)
        self.wait_select_single('IndicatorsMenu', fullyOpened=True)
        return self._get_indicator_page(indicator_name)

    @autopilot_logging.log_action(logger.info)
    def show_dash_swiping(self):
        """Show the dash swiping from the left."""
        x, y, width, height = self._get_shell().globalRect
        start_x = x
        end_x = x + width
        start_y = end_y = y + height // 2

        self.pointing_device.drag(start_x, start_y, end_x, end_y)
        self.get_current_focused_app_id().wait_for('unity8-dash')

    def _get_shell(self):
        return self.select_single('Shell')

    def get_current_focused_app_id(self):
        """Return the id of the focused application."""
        return self._get_shell().focusedApplicationId

    @autopilot_logging.log_action(logger.info)
    def show_dash_from_launcher(self):
        """Open the dash clicking the dash icon on the launcher."""
        launcher = self.open_launcher()
        launcher.click_dash_icon()
        self.get_current_focused_app_id().wait_for('unity8-dash')
        launcher.shown.wait_for(False)

    @autopilot_logging.log_action(logger.info)
    def open_launcher(self):
        launcher = self._get_launcher()
        launcher.show()
        return launcher

    def _get_launcher(self):
        return self.select_single(Launcher)

    def is_launcher_open(self):
        return self._get_launcher().shown

    @autopilot_logging.log_action(logger.info)
    def launch_application(self, application_name):
        """Launch an application.

        :parameter application_name: The name of the application to launch.

        """
        launcher = self.open_launcher()
        launcher.click_application_launcher_icon(application_name)
        self.get_current_focused_app_id().wait_for(application_name)
        launcher.shown.wait_for(False)

    def enter_pin_code(self, code):
        """Enter code 'code' into the single-pin lightdm pincode entry screen.

        :param code: must be a string of numeric characters.
        :raises: TypeError if code is not a string.
        :raises: ValueError if code contains non-numeric characters.

        """
        if not isinstance(code, str):
            raise TypeError(
                "'code' parameter must be a string, not %r."
                % type(code)
            )
        for num in code:
            if not num.isdigit():
                raise ValueError(
                    "'code' parameter contains non-numeric characters."
                )
            self.pointing_device.click_object(
                self._get_pinpad_button(int(num)))

    def _get_pinpad_button(self, button_id):
        return self.select_single(
            'PinPadButton',
            objectName='pinPadButton{}'.format(button_id)
        )

    def get_shell_orientation_angle(self):
        return self._get_shell().orientationAngle

    def get_shell_orientation(self):
        return self._get_shell().orientation

    def get_shell_primary_orientation(self):
        return self._get_shell().primaryOrientation

    def get_shell_native_orientation(self):
        return self._get_shell().nativeOrientation

    @autopilot_logging.log_action(logger.info)
    def wait_for_notification(self):
        """Wait for a notification dialog to appear.

        :return: An object for the notification dialog data.
        :raise StateNotFoundError: if the timeout expires when the
        notification has not appeared.

        """
        notify_list = self.select_single('Notifications',
                                         objectName='notificationList')
        visible_notification = notify_list.wait_select_single('Notification',
                                                              visible=True)
        return {'summary': visible_notification.summary,
                'body': visible_notification.body,
                'iconSource': visible_notification.iconSource}


class Launcher(UbuntuUIToolkitCustomProxyObjectBase):

    """A helper that understands the Launcher."""

    def show(self):
        """Show the launcher swiping it to the right."""
        if not self.shown:
            self._swipe_to_show_launcher()
            self.shown.wait_for(True)
        else:
            logger.debug('The launcher is already opened.')

    def _swipe_to_show_launcher(self):
        view = self.get_root_instance().select_single('ShellView')
        start_y = stop_y = view.y + view.height // 2

        start_x = view.x + 1
        stop_x = start_x + self.panelWidth - 1

        self.pointing_device.drag(start_x, start_y, stop_x, stop_y)

    def click_dash_icon(self):
        if self.shown:
            dash_icon = self.select_single(
                'QQuickImage', objectName='dashItem')
            self.pointing_device.click_object(dash_icon)
        else:
            raise UnityException('The launcher is closed.')

    def click_application_launcher_icon(self, application_name):
        launcher_delegate = self.select_single(
            'LauncherDelegate', appId=application_name)
        self.pointing_device.click_object(launcher_delegate)