Merge lp:~elopio/ubuntu-ui-toolkit/fix_tab_switch into lp:ubuntu-ui-toolkit

Proposed by Leo Arias
Status: Superseded
Proposed branch: lp:~elopio/ubuntu-ui-toolkit/fix_tab_switch
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 226 lines (+73/-5)
7 files modified
CHANGES (+1/-0)
components.api (+2/-0)
modules/Ubuntu/Components/Tab.qml (+16/-0)
modules/Ubuntu/Components/Tabs.qml (+5/-1)
tests/autopilot/ubuntuuitoolkit/emulators.py (+36/-4)
tests/unit/tst_components/tst_tab.qml (+4/-0)
tests/unit/tst_components/tst_tabs.qml (+9/-0)
To merge this branch: bzr merge lp:~elopio/ubuntu-ui-toolkit/fix_tab_switch
Reviewer Review Type Date Requested Status
Ubuntu SDK team Pending
Review via email: mp+188475@code.launchpad.net

This proposal has been superseded by a proposal from 2013-10-02.

Commit message

Fixed the tab switch on autopilot emulators that used to rely on the order of the tree.

Description of the change

There where two places where the autopilot emulators relied on the order of the tree. Now, instead of that, they rely on the index property of the elements.
For this, I had to merge zsombi's branch that added the index property to the Tabs.
Here I'm also adding debug information to the log while switching tabs, hoping that it will help to diagnose other failures that happen sometimes on Jenkins. This logs are temporary. Once we can update to autopilot 1.4 we will have a much more elegant way to log all the user actions simulated by autopilot.

To post a comment you must log in.
Revision history for this message
I Ahmad (iahmad) wrote :

This line import pdb; pdb.set_trace() below will stop the execution if this is picked up by ci. Any reason you are leaving this in your merge proposal?

Revision history for this message
Leo Arias (elopio) wrote :

> This line import pdb; pdb.set_trace() below will stop the execution if this
> is picked up by ci. Any reason you are leaving this in your merge proposal?

No, thanks for catching it.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CHANGES'
2--- CHANGES 2013-09-24 19:47:54 +0000
3+++ CHANGES 2013-10-02 07:01:34 +0000
4@@ -9,6 +9,7 @@
5
6 API Changes
7 ***********
8+* ADDED IN: Tab: readonly property int index
9 * ADDED IN: ListItem.Empty: property bool confirmRemoval
10 * ADDED IN: OptionSelectorDelegate: property bool constrainImage
11 * ADDED IN: Empty: property alias divider
12
13=== modified file 'components.api'
14--- components.api 2013-09-30 12:00:41 +0000
15+++ components.api 2013-10-02 07:01:34 +0000
16@@ -197,6 +197,8 @@
17 property string title
18 property url iconSource
19 property Item page
20+ readonly property int index
21+ property internal __protected
22 modules/Ubuntu/Components/TabBar.qml
23 StyledItem
24 property Item tabsItem
25
26=== modified file 'modules/Ubuntu/Components/Tab.qml'
27--- modules/Ubuntu/Components/Tab.qml 2013-05-22 10:04:59 +0000
28+++ modules/Ubuntu/Components/Tab.qml 2013-10-02 07:01:34 +0000
29@@ -49,6 +49,13 @@
30 property Item page: null
31
32 /*!
33+ \qmlproperty int index
34+ \readonly
35+ The property holds the index of the tab within the Tabs.
36+ */
37+ readonly property alias index: internal.index
38+
39+ /*!
40 When page is updated, set its parent to be tab.
41 */
42 onPageChanged: if (page) page.parent = tab
43@@ -73,4 +80,13 @@
44 }
45 }
46 }
47+
48+ /*!
49+ \internal
50+ */
51+ property alias __protected: internal
52+ QtObject {
53+ id: internal
54+ property int index: -1
55+ }
56 }
57
58=== modified file 'modules/Ubuntu/Components/Tabs.qml'
59--- modules/Ubuntu/Components/Tabs.qml 2013-08-22 17:15:35 +0000
60+++ modules/Ubuntu/Components/Tabs.qml 2013-10-02 07:01:34 +0000
61@@ -212,8 +212,12 @@
62
63 function updateTabList() {
64 var list = [];
65+ var index = 0;
66 for (var i=0; i < children.length; i++) {
67- if (isTab(tabsModel.children[i])) list.push(tabsModel.children[i]);
68+ if (isTab(tabsModel.children[i])) {
69+ tabsModel.children[i].__protected.index = index++;
70+ list.push(tabsModel.children[i]);
71+ }
72 }
73 tabList = list;
74 tabs.modelChanged();
75
76=== modified file 'tests/autopilot/ubuntuuitoolkit/emulators.py'
77--- tests/autopilot/ubuntuuitoolkit/emulators.py 2013-09-21 19:08:50 +0000
78+++ tests/autopilot/ubuntuuitoolkit/emulators.py 2013-10-02 07:01:34 +0000
79@@ -14,11 +14,15 @@
80 # You should have received a copy of the GNU Lesser General Public License
81 # along with this program. If not, see <http://www.gnu.org/licenses/>.
82
83+import logging
84+
85 from autopilot import input, platform
86 from autopilot.introspection import dbus
87
88 _NO_TABS_ERROR = 'The MainView has no Tabs.'
89
90+logger = logging.getLogger(__name__)
91+
92
93 class ToolkitEmulatorException(Exception):
94 """Exception raised when there is an error with the emulator."""
95@@ -111,6 +115,7 @@
96 :return: The newly opened tab.
97
98 """
99+ logger.debug('Switch to next tab.')
100 self.get_header().switch_to_next_tab()
101 current_tab = self.get_tabs().get_current_tab()
102 current_tab.visible.wait_for(True)
103@@ -123,6 +128,7 @@
104 :return: The newly opened tab.
105
106 """
107+ logger.debug('Switch to tab with index {0}.'.format(index))
108 tabs = self.get_tabs()
109 number_of_tabs = tabs.get_number_of_tabs()
110 if index >= number_of_tabs:
111@@ -130,6 +136,8 @@
112 current_tab = tabs.get_current_tab()
113 number_of_switches = 0
114 while not tabs.selectedTabIndex == index:
115+ logger.debug(
116+ 'Current tab index: {0}.'.format(tabs.selectedTabIndex))
117 if number_of_switches >= number_of_tabs - 1:
118 # This prevents a loop. But if this error is ever raised, it's
119 # likely there's a bug on the emulator or on the QML Tab.
120@@ -162,7 +170,7 @@
121 tabs = self.get_tabs()
122 for index, tab in enumerate(tabs.select_many('Tab')):
123 if tab.objectName == object_name:
124- return self.switch_to_tab_by_index(index)
125+ return self.switch_to_tab_by_index(tab.index)
126 raise ValueError(
127 'Tab with objectName "{0}" not found.'.format(object_name))
128
129@@ -221,11 +229,23 @@
130
131 def get_current_tab(self):
132 """Return the currently selected tab."""
133- return self.select_many('Tab')[self.selectedTabIndex]
134+ return self._get_tab(self.selectedTabIndex)
135+
136+ def _get_tab(self, index):
137+ tabs = self._get_tabs()
138+ for tab in tabs:
139+ if tab.index == index:
140+ return tab
141+ else:
142+ raise ToolkitEmulatorException(
143+ 'There is no tab with index {0}.'.format(index))
144+
145+ def _get_tabs(self):
146+ return self.select_many('Tab')
147
148 def get_number_of_tabs(self):
149 """Return the number of tabs."""
150- return len(self.select_many('Tab'))
151+ return len(self._get_tabs())
152
153
154 class TabBar(UbuntuUIToolkitEmulatorBase):
155@@ -234,16 +254,19 @@
156 def switch_to_next_tab(self):
157 """Open the next tab."""
158 # Click the tab bar to switch to selection mode.
159+ logger.debug('Click the tab bar to enable selection mode.')
160 self.pointing_device.click_object(self)
161 if not self.selectionMode:
162+ logger.debug('Selection mode not enabled, try again.')
163 # in case someone stole the click, like the open toolbar
164 self.pointing_device.click_object(self)
165+ logger.debug('Click the next tab bar button.')
166 self.pointing_device.click_object(self._get_next_tab_button())
167
168 def _get_next_tab_button(self):
169 current_index = self._get_selected_button_index()
170 next_index = (current_index + 1) % self._get_number_of_tab_buttons()
171- return self._get_tab_buttons()[next_index]
172+ return self._get_tab_button(next_index)
173
174 def _get_selected_button_index(self):
175 return self.select_single('QQuickPathView').selectedButtonIndex
176@@ -254,6 +277,15 @@
177 def _get_tab_buttons(self):
178 return self.select_many('AbstractButton')
179
180+ def _get_tab_button(self, index):
181+ buttons = self._get_tab_buttons()
182+ for button in buttons:
183+ if button.buttonIndex == index:
184+ return button
185+ else:
186+ raise ToolkitEmulatorException(
187+ 'There is no tab button with index {0}.'.format(index))
188+
189
190 class ActionSelectionPopover(UbuntuUIToolkitEmulatorBase):
191 """ActionSelectionPopover Autopilot emulator."""
192
193=== modified file 'tests/unit/tst_components/tst_tab.qml'
194--- tests/unit/tst_components/tst_tab.qml 2013-05-06 13:11:21 +0000
195+++ tests/unit/tst_components/tst_tab.qml 2013-10-02 07:01:34 +0000
196@@ -39,6 +39,10 @@
197 compare(tab.title,newTitle,"can set/get")
198 }
199
200+ function test_index() {
201+ compare(tab.index, -1, "is -1 by default")
202+ }
203+
204 Tab {
205 id: tab
206 }
207
208=== modified file 'tests/unit/tst_components/tst_tabs.qml'
209--- tests/unit/tst_components/tst_tabs.qml 2013-07-29 10:05:05 +0000
210+++ tests/unit/tst_components/tst_tabs.qml 2013-10-02 07:01:34 +0000
211@@ -76,6 +76,15 @@
212 tabs.selectedTabIndex = 0;
213 }
214
215+ function test_index() {
216+ compare(tab1.index, 0, "tab1 is at 0");
217+ compare(tab2.index, 1, "tab2 is at 1");
218+ compare(tab3.index, 2, "tab3 is at 2");
219+ compare(tabFlick1.index, 3, "tabFlick1 is at 3");
220+ compare(tabFlick2.index, 4, "tabFlick2 is at 4");
221+ compare(tabFlickLoader.index, 5, "tabFlickLoader is at 5");
222+ }
223+
224 Tabs {
225 id: emptyTabs
226 }

Subscribers

People subscribed via source and target branches

to status/vote changes: