on xenial help sign in
Do not use indexes.
commit8fa8eeb884c204ce180a5e553bd3f7e925ccef68 authorLeo Arias <leo.arias@canonical.com> dateWed 8 Jan 2014, 10:08 (13 years ago) parent55f8a31
2 files changed+40−32
tests/autopilot/unity8/shell/emulators/dash.py+21−25 tests/autopilot/unity8/shell/tests/test_emulators.py+19−7
tests/autopilot/unity8/shell/emulators/dash.py+21−25
@@ -22,6 +22,7 @@ import logging
2222from unity8.shell import emulators
2323
2424from autopilot import logging as autopilot_logging
25+from autopilot.introspection import dbus
2526
2627
2728logger = logging.getLogger(__name__)
@@ -67,49 +68,44 @@ class Dash(emulators.UnityEmulatorBase):
6768
6869 """
6970 scope_id = "%s.scope" % scope_name
70− scope_index = self._get_scope_index(scope_id)
71− if scope_index == self.dash_content_list.currentIndex:
71+ scope_loader = self._get_scope_loader(scope_id)
72+ if scope_loader.isCurrent:
7273 logger.info('The scope is already open.')
73− return self._get_scope_by_index(scope_index)
74− else:
75− return self._open_scope_scrolling(scope_index)
76−
77− def _get_scope_index(self, scope_id):
78− scope_loaders = self.dash_content_list.select_many('QQuickLoader')
79− for index, loader in enumerate(scope_loaders):
80− try:
81− if loader.scopeId == scope_id:
82− return index
83− except AttributeError:
84− pass
74+ return self._get_scope_from_loader(scope_loader)
8575 else:
76+ return self._open_scope_scrolling(scope_loader)
77+
78+ def _get_scope_loader(self, scope_id):
79+ try:
80+ return self.dash_content_list.select_single(
81+ 'QQuickLoader', scopeId=scope_id)
82+ except dbus.StateNotFoundError:
8683 raise emulators.UnityEmulatorException(
8784 'No scope found with id {0}'.format(scope_id))
8885
89− def _get_scope_by_index(self, scope_index):
90− scope_loaders = self.dash_content_list.select_many('QQuickLoader')
91− return self._get_scope_from_loader(scope_loaders[scope_index])
92−
9386 def _get_scope_from_loader(self, loader):
9487 if loader.scopeId == 'applications.scope':
9588 return loader.select_single(DashApps)
9689 else:
9790 return loader.select_single(GenericScopeView)
9891
99− def _open_scope_scrolling(self, scope_index):
100− scroll = self._get_scroll_direction(scope_index)
92+ def _open_scope_scrolling(self, scope_loader):
93+ scroll = self._get_scroll_direction(scope_loader)
10194
102− while scope_index != self.dash_content_list.currentIndex:
95+ while not scope_loader.isCurrent:
10396 scroll()
104− scope = self._get_scope_by_index(scope_index)
97+
98+ scope = self._get_scope_from_loader(scope_loader)
10599 scope.moving.wait_for(False)
106100 scope.isCurrent.wait_for(True)
107101 return scope
108102
109− def _get_scroll_direction(self, scope_index):
110− if scope_index < self.dash_content_list.currentIndex:
103+ def _get_scroll_direction(self, scope_loader):
104+ current_scope_loader = self.dash_content_list.select_single(
105+ 'QQuickLoader', isCurrent=True)
106+ if scope_loader.globalRect.x < current_scope_loader.globalRect.x:
111107 return self._scroll_to_left_scope
112− elif scope_index > self.dash_content_list.currentIndex:
108+ elif scope_loader.globalRect.x > current_scope_loader.globalRect.x:
113109 return self._scroll_to_right_scope
114110 else:
115111 raise emulators.UnityEmulatorException('The scope is already open')
tests/autopilot/unity8/shell/tests/test_emulators.py+19−7
@@ -32,8 +32,6 @@ class DashEmulatorTestCase(tests.UnityTestCase):
3232 self.launch_unity()
3333 self.main_window.get_greeter().swipe()
3434 self.dash = self.main_window.get_dash()
35− self.scope_loaders = self.dash.dash_content_list.select_many(
36− 'QQuickLoader')
3735
3836 def test_open_unexisting_scope(self):
3937 scope_name = 'unexisting'
@@ -61,7 +59,8 @@ class DashEmulatorTestCase(tests.UnityTestCase):
6159 self.assertEqual(scope_loader.scopeId, scope_id)
6260
6361 def _get_current_scope_id(self):
64− scope = self.scope_loaders[self.dash.dash_content_list.currentIndex]
62+ scope = self.dash.dash_content_list.select_single(
63+ 'QQuickLoader', isCurrent=True)
6564 return scope.scopeId
6665
6766 def test_open_scope_to_the_right(self):
@@ -74,16 +73,29 @@ class DashEmulatorTestCase(tests.UnityTestCase):
7473 self._assert_scope_is_opened(scope, scope_id)
7574
7675 def _get_leftmost_scope_id(self):
77− scope = self.scope_loaders[0]
78− return scope.scopeId
76+ scope_loaders = self._get_scope_loaders()
77+ leftmost_scope_loader = scope_loaders[0]
78+ for loader in scope_loaders[1:]:
79+ if loader.globalRect.x < leftmost_scope_loader:
80+ leftmost_scope_loader = loader
81+ return leftmost_scope_loader.scopeId
82+
83+ def _get_scope_loaders(self):
84+ item = self.dash.dash_content_list.get_children_by_type(
85+ 'QQuickItem')[0]
86+ return item.get_children_by_type('QQuickLoader')
7987
8088 def _get_scope_name_from_id(self, scope_id):
8189 if scope_id.endswith('.scope'):
8290 return scope_id[:-6]
8391
8492 def _get_rightmost_scope_id(self):
85− scope = self.scope_loaders[self.dash.dash_content_list.count - 1]
86− return scope.scopeId
93+ scope_loaders = self._get_scope_loaders()
94+ rightmost_scope_loader = scope_loaders[0]
95+ for loader in scope_loaders[1:]:
96+ if loader.globalRect.x > rightmost_scope_loader:
97+ rightmost_scope_loader = loader
98+ return rightmost_scope_loader.scopeId
8799
88100 def test_open_scope_to_the_left(self):
89101 rightmost_scope = self._get_scope_name_from_id(