~fboucault/ubuntu-ui-toolkit/fix_tabs_ordering

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntuuitoolkit/emulators.py

  • Committer: Florian Boucault
  • Date: 2013-11-22 14:49:12 UTC
  • mfrom: (848 trunk)
  • mto: This revision was merged to the branch mainline in revision 858.
  • Revision ID: florian.boucault@canonical.com-20131122144912-vmv2mi3t9o2rd2dl
Merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
        :return: The toolbar.
89
89
 
90
90
        """
91
 
        toolbar = self.get_toolbar()
92
 
        toolbar.animating.wait_for(False)
93
 
        if not toolbar.opened:
94
 
            self._drag_to_open_toolbar()
95
 
            toolbar.opened.wait_for(True)
96
 
            toolbar.animating.wait_for(False)
97
 
 
98
 
        return toolbar
99
 
 
100
 
    def _drag_to_open_toolbar(self):
101
 
        x, y, _, _ = self.globalRect
102
 
        line_x = x + self.width * 0.50
103
 
        start_y = y + self.height - 1
104
 
        stop_y = y + self.height - self.get_toolbar().height
105
 
 
106
 
        self.pointing_device.drag(line_x, start_y, line_x, stop_y)
 
91
        return self.get_toolbar().open()
107
92
 
108
93
    def close_toolbar(self):
109
94
        """Close the toolbar if it's opened."""
110
 
        toolbar = self.get_toolbar()
111
 
        toolbar.animating.wait_for(False)
112
 
        if toolbar.opened:
113
 
            self._drag_to_close_toolbar()
114
 
            toolbar.opened.wait_for(False)
115
 
            toolbar.animating.wait_for(False)
116
 
 
117
 
    def _drag_to_close_toolbar(self):
118
 
        x, y, _, _ = self.globalRect
119
 
        line_x = x + self.width * 0.50
120
 
        start_y = y + self.height - self.get_toolbar().height
121
 
        stop_y = y + self.height - 1
122
 
 
123
 
        self.pointing_device.drag(line_x, start_y, line_x, stop_y)
 
95
        self.get_toolbar().close()
124
96
 
125
97
    def get_tabs(self):
126
98
        """Return the Tabs emulator of the MainView.
244
216
class Toolbar(UbuntuUIToolkitEmulatorBase):
245
217
    """Toolbar Autopilot emulator."""
246
218
 
 
219
    def open(self):
 
220
        """Open the toolbar if it's not already opened.
 
221
 
 
222
        :return: The toolbar.
 
223
 
 
224
        """
 
225
        self.animating.wait_for(False)
 
226
        if not self.opened:
 
227
            self._drag_to_open()
 
228
            self.opened.wait_for(True)
 
229
            self.animating.wait_for(False)
 
230
 
 
231
        return self
 
232
 
 
233
    def _drag_to_open(self):
 
234
        x, y, _, _ = self.globalRect
 
235
        line_x = x + self.width * 0.50
 
236
        start_y = y + self.height - 1
 
237
        stop_y = y
 
238
 
 
239
        self.pointing_device.drag(line_x, start_y, line_x, stop_y)
 
240
 
 
241
    def close(self):
 
242
        """Close the toolbar if it's opened."""
 
243
        self.animating.wait_for(False)
 
244
        if self.opened:
 
245
            self._drag_to_close()
 
246
            self.opened.wait_for(False)
 
247
            self.animating.wait_for(False)
 
248
 
 
249
    def _drag_to_close(self):
 
250
        x, y, _, _ = self.globalRect
 
251
        line_x = x + self.width * 0.50
 
252
        start_y = y
 
253
        stop_y = y + self.height - 1
 
254
 
 
255
        self.pointing_device.drag(line_x, start_y, line_x, stop_y)
 
256
 
247
257
    def click_button(self, object_name):
248
258
        """Click a button of the toolbar.
249
259
 
 
260
        The toolbar should be opened before clicking the button, or an
 
261
        exception will be raised. If the toolbar is closed for some reason
 
262
        (e.g., timer finishes) after moving the mouse cursor and before
 
263
        clicking the button, it is re-opened automatically by this function.
 
264
 
250
265
        :parameter object_name: The QML objectName property of the button.
251
266
        :raise ToolkitEmulatorException: If there is no button with that object
252
267
            name.
257
272
        except dbus.StateNotFoundError:
258
273
            raise ToolkitEmulatorException(
259
274
                'Button with objectName "{0}" not found.'.format(object_name))
 
275
        # ensure the toolbar is open
 
276
        if not self.opened:
 
277
            raise ToolkitEmulatorException(
 
278
                'Toolbar must be opened before calling click_button().')
 
279
        self.pointing_device.move_to_object(button)
 
280
        # ensure the toolbar is still open (may have closed due to timeout)
 
281
        self.open()
 
282
        # click the button
260
283
        self.pointing_device.click_object(button)
261
284
 
262
285
    def _get_button(self, object_name):
403
426
 
404
427
 
405
428
class Empty(UbuntuUIToolkitEmulatorBase):
406
 
    """Base class to emulate swipe to delete"""
 
429
    """Base class to emulate swipe to delete."""
 
430
 
 
431
    def exists(self):
 
432
        try:
 
433
            return self.implicitHeight > 0
 
434
        except dbus.StateNotFoundError:
 
435
            return False
407
436
 
408
437
    def _get_confirm_button(self):
409
438
        return self.select_single(
410
439
            'QQuickItem', objectName='confirmRemovalDialog')
411
440
 
412
441
    def swipe_to_delete(self, direction='right'):
413
 
        """ Swipe the item in a specific direction """
 
442
        """Swipe the item in a specific direction."""
414
443
        if (self.removable):
415
 
            x, y, w, h = self.globalRect
416
 
            tx = x + (w / 8)
417
 
            ty = y + (h / 2)
418
 
 
419
 
            if (direction == 'right'):
420
 
                self.pointing_device.drag(tx, ty, w, ty)
421
 
            elif (direction == 'left'):
422
 
                self.pointing_device.drag(w - (w*0.1), ty, x, ty)
 
444
            self._drag_pointing_device_to_delete(direction)
 
445
            if self.confirmRemoval:
 
446
                self.waitingConfirmationForRemoval.wait_for(True)
423
447
            else:
424
 
                raise ToolkitEmulatorException(
425
 
                    'Invalid direction "{0}" used on swipe to delete function'
426
 
                    .format(direction))
427
 
 
428
 
            self.waitingConfirmationForRemoval.wait_for(True)
 
448
                self._wait_until_deleted()
429
449
        else:
430
450
            raise ToolkitEmulatorException(
431
451
                'The item "{0}" is not removable'.format(self.objectName))
432
452
 
 
453
    def _drag_pointing_device_to_delete(self, direction):
 
454
        x, y, w, h = self.globalRect
 
455
        tx = x + (w / 8)
 
456
        ty = y + (h / 2)
 
457
 
 
458
        if (direction == 'right'):
 
459
            self.pointing_device.drag(tx, ty, w, ty)
 
460
        elif (direction == 'left'):
 
461
            self.pointing_device.drag(w - (w*0.1), ty, x, ty)
 
462
        else:
 
463
            raise ToolkitEmulatorException(
 
464
                'Invalid direction "{0}" used on swipe to delete function'
 
465
                .format(direction))
 
466
 
 
467
    def _wait_until_deleted(self):
 
468
        try:
 
469
            # The item was hidden.
 
470
            self.implicitHeight.wait_for(0)
 
471
        except dbus.StateNotFoundError:
 
472
            # The item was destroyed.
 
473
            pass
 
474
 
433
475
    def confirm_removal(self):
434
 
        """ Comfirm item removal if this was already swiped """
 
476
        """Comfirm item removal if this was already swiped."""
435
477
        if (self.waitingConfirmationForRemoval):
436
478
            deleteButton = self._get_confirm_button()
437
479
            self.pointing_device.click_object(deleteButton)
438
 
            self.implicitHeight.wait_for(0)
 
480
            self._wait_until_deleted()
439
481
        else:
440
482
            raise ToolkitEmulatorException(
441
483
                'The item "{0}" is not waiting for removal confirmation'.