on xenial help sign in
Do not use indexes.
8fa8eebLeo Arias
tests/autopilot/unity8/shell/emulators/dash.py+21−25
@@ -22,6 +22,7 @@ import logging
22from unity8.shell import emulators
22from unity8.shell import emulators
23
23
24from autopilot import logging as autopilot_logging
24from autopilot import logging as autopilot_logging
25+from autopilot.introspection import dbus
25
26
26
27
27logger = logging.getLogger(__name__)
28logger = logging.getLogger(__name__)
@@ -67,49 +68,44 @@ class Dash(emulators.UnityEmulatorBase):
67
68
68 """
69 """
69 scope_id = "%s.scope" % scope_name
70 scope_id = "%s.scope" % scope_name
70− scope_index = self._get_scope_index(scope_id)
71+ scope_loader = self._get_scope_loader(scope_id)
71− if scope_index == self.dash_content_list.currentIndex:
72+ if scope_loader.isCurrent:
72 logger.info('The scope is already open.')
73 logger.info('The scope is already open.')
73− return self._get_scope_by_index(scope_index)
74+ return self._get_scope_from_loader(scope_loader)
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
85 else:
75 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:
86 raise emulators.UnityEmulatorException(
83 raise emulators.UnityEmulatorException(
87 'No scope found with id {0}'.format(scope_id))
84 'No scope found with id {0}'.format(scope_id))
88
85
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−
93 def _get_scope_from_loader(self, loader):
86 def _get_scope_from_loader(self, loader):
94 if loader.scopeId == 'applications.scope':
87 if loader.scopeId == 'applications.scope':
95 return loader.select_single(DashApps)
88 return loader.select_single(DashApps)
96 else:
89 else:
97 return loader.select_single(GenericScopeView)
90 return loader.select_single(GenericScopeView)
98
91
99− def _open_scope_scrolling(self, scope_index):
92+ def _open_scope_scrolling(self, scope_loader):
100− scroll = self._get_scroll_direction(scope_index)
93+ scroll = self._get_scroll_direction(scope_loader)
101
94
102− while scope_index != self.dash_content_list.currentIndex:
95+ while not scope_loader.isCurrent:
103 scroll()
96 scroll()
104− scope = self._get_scope_by_index(scope_index)
97+
98+ scope = self._get_scope_from_loader(scope_loader)
105 scope.moving.wait_for(False)
99 scope.moving.wait_for(False)
106 scope.isCurrent.wait_for(True)
100 scope.isCurrent.wait_for(True)
107 return scope
101 return scope
108
102
109− def _get_scroll_direction(self, scope_index):
103+ def _get_scroll_direction(self, scope_loader):
110− if scope_index < self.dash_content_list.currentIndex:
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:
111 return self._scroll_to_left_scope
107 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:
113 return self._scroll_to_right_scope
109 return self._scroll_to_right_scope
114 else:
110 else:
115 raise emulators.UnityEmulatorException('The scope is already open')
111 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):
32 self.launch_unity()
32 self.launch_unity()
33 self.main_window.get_greeter().swipe()
33 self.main_window.get_greeter().swipe()
34 self.dash = self.main_window.get_dash()
34 self.dash = self.main_window.get_dash()
35− self.scope_loaders = self.dash.dash_content_list.select_many(
36− 'QQuickLoader')
37
35
38 def test_open_unexisting_scope(self):
36 def test_open_unexisting_scope(self):
39 scope_name = 'unexisting'
37 scope_name = 'unexisting'
@@ -61,7 +59,8 @@ class DashEmulatorTestCase(tests.UnityTestCase):
61 self.assertEqual(scope_loader.scopeId, scope_id)
59 self.assertEqual(scope_loader.scopeId, scope_id)
62
60
63 def _get_current_scope_id(self):
61 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)
65 return scope.scopeId
64 return scope.scopeId
66
65
67 def test_open_scope_to_the_right(self):
66 def test_open_scope_to_the_right(self):
@@ -74,16 +73,29 @@ class DashEmulatorTestCase(tests.UnityTestCase):
74 self._assert_scope_is_opened(scope, scope_id)
73 self._assert_scope_is_opened(scope, scope_id)
75
74
76 def _get_leftmost_scope_id(self):
75 def _get_leftmost_scope_id(self):
76+ scope_loaders = self._get_scope_loaders()
77− scope = self.scope_loaders[0]
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
78− return scope.scopeId
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')
79
87
80 def _get_scope_name_from_id(self, scope_id):
88 def _get_scope_name_from_id(self, scope_id):
81 if scope_id.endswith('.scope'):
89 if scope_id.endswith('.scope'):
82 return scope_id[:-6]
90 return scope_id[:-6]
83
91
84 def _get_rightmost_scope_id(self):
92 def _get_rightmost_scope_id(self):
85− scope = self.scope_loaders[self.dash.dash_content_list.count - 1]
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
86− return scope.scopeId
98+ return rightmost_scope_loader.scopeId
87
99
88 def test_open_scope_to_the_left(self):
100 def test_open_scope_to_the_left(self):
89 rightmost_scope = self._get_scope_name_from_id(
101 rightmost_scope = self._get_scope_name_from_id(