on xenial help sign in
Better fix for tests for the old bug and for a new one introduced by the previous fix
fd9dd23Albert Astals
qml/Dash/GenericScopeView.qml+4−4
@@ -186,10 +186,10 @@ FocusScope {
186 onClicked: {
186 onClicked: {
187 // Prepare the preview in case activate() triggers a preview only
187 // Prepare the preview in case activate() triggers a preview only
188 openEffect.positionPx = Math.max(mapToItem(categoryView, 0, itemY).y, pageHeader.height + categoryView.stickyHeaderHeight);
188 openEffect.positionPx = Math.max(mapToItem(categoryView, 0, itemY).y, pageHeader.height + categoryView.stickyHeaderHeight);
189− previewListView.needsInit = true;
190 previewListView.categoryId = categoryId
189 previewListView.categoryId = categoryId
191 previewListView.categoryDelegate = rendererLoader.item
190 previewListView.categoryDelegate = rendererLoader.item
192 previewListView.model = target.model;
191 previewListView.model = target.model;
192+ previewListView.init = true;
193 previewListView.currentIndex = index;
193 previewListView.currentIndex = index;
194
194
195 var item = target.model.get(index);
195 var item = target.model.get(index);
@@ -207,10 +207,10 @@ FocusScope {
207 }
207 }
208 onPressAndHold: {
208 onPressAndHold: {
209 openEffect.positionPx = Math.max(mapToItem(categoryView, 0, itemY).y, pageHeader.height + categoryView.stickyHeaderHeight);
209 openEffect.positionPx = Math.max(mapToItem(categoryView, 0, itemY).y, pageHeader.height + categoryView.stickyHeaderHeight);
210− previewListView.needsInit = true;
211 previewListView.categoryId = categoryId
210 previewListView.categoryId = categoryId
212 previewListView.categoryDelegate = rendererLoader.item
211 previewListView.categoryDelegate = rendererLoader.item
213 previewListView.model = target.model;
212 previewListView.model = target.model;
213+ previewListView.init = true;
214 previewListView.currentIndex = index;
214 previewListView.currentIndex = index;
215 previewListView.open = true
215 previewListView.open = true
216
216
@@ -364,7 +364,7 @@ FocusScope {
364 Connections {
364 Connections {
365 target: scopeView.scope
365 target: scopeView.scope
366 onPreviewReady: {
366 onPreviewReady: {
367− if (previewListView.needsInit) {
367+ if (previewListView.init) {
368 // Preview was triggered because of a click on the item. Need to expand now.
368 // Preview was triggered because of a click on the item. Need to expand now.
369 if (!previewListView.open) {
369 if (!previewListView.open) {
370 previewListView.open = true
370 previewListView.open = true
@@ -372,8 +372,8 @@ FocusScope {
372
372
373 var index = previewListView.currentIndex
373 var index = previewListView.currentIndex
374 previewListView.currentIndex = -1
374 previewListView.currentIndex = -1
375− previewListView.needsInit = false
376 previewListView.currentIndex = index
375 previewListView.currentIndex = index
376+ previewListView.init = false
377 }
377 }
378 previewListView.currentItem.previewData = preview
378 previewListView.currentItem.previewData = preview
379 }
379 }
qml/Dash/PreviewListView.qml+9−8
@@ -28,7 +28,7 @@ Item {
28 property alias onScreen: previewListView.onScreen
28 property alias onScreen: previewListView.onScreen
29 property alias categoryId: previewListView.categoryId
29 property alias categoryId: previewListView.categoryId
30 property alias categoryDelegate: previewListView.categoryDelegate
30 property alias categoryDelegate: previewListView.categoryDelegate
31− property alias needsInit: previewListView.needsInit
31+ property alias init: previewListView.init
32 property alias model: previewListView.model
32 property alias model: previewListView.model
33 property alias currentIndex: previewListView.currentIndex
33 property alias currentIndex: previewListView.currentIndex
34 property alias currentItem: previewListView.currentItem
34 property alias currentItem: previewListView.currentItem
@@ -82,14 +82,16 @@ Item {
82 // because the ListView is built asynchronous, setting the
82 // because the ListView is built asynchronous, setting the
83 // currentIndex directly won't work. We need to refresh it
83 // currentIndex directly won't work. We need to refresh it
84 // when the first preview is ready to be displayed.
84 // when the first preview is ready to be displayed.
85− property bool needsInit: true
85+ property bool init: true
86
86
87 PreviewDelegateMapper {
87 PreviewDelegateMapper {
88 id: previewDelegateMapper
88 id: previewDelegateMapper
89 }
89 }
90
90
91− onCurrentIndexChanged: {
91+ onCurrentIndexChanged: positionListView();
92− if (needsInit) {
92+
93+ function positionListView() {
94+ if (!open) {
93 return;
95 return;
94 }
96 }
95
97
@@ -98,11 +100,9 @@ Item {
98 categoryView.expandedCategoryId = categoryId
100 categoryView.expandedCategoryId = categoryId
99 }
101 }
100
102
101− if (open) {
102− categoryDelegate.highlightIndex = currentIndex
103+ categoryDelegate.highlightIndex = currentIndex
103− }
104
104
105− if (model !== undefined) {
105+ if (!init && model !== undefined) {
106 var item = model.get(currentIndex)
106 var item = model.get(currentIndex)
107 scope.preview(item.uri, item.icon, item.category, 0, item.mimetype, item.title, item.comment, item.dndUri, item.metadata)
107 scope.preview(item.uri, item.icon, item.category, 0, item.mimetype, item.title, item.comment, item.dndUri, item.metadata)
108 }
108 }
@@ -141,6 +141,7 @@ Item {
141 onScreen = true;
141 onScreen = true;
142 categoryDelegate.highlightIndex = currentIndex;
142 categoryDelegate.highlightIndex = currentIndex;
143 pageHeader.unfocus();
143 pageHeader.unfocus();
144+ positionListView();
144 } else {
145 } else {
145 // Cancel any pending preview requests or actions
146 // Cancel any pending preview requests or actions
146 if (previewListView.currentItem.previewData !== undefined) {
147 if (previewListView.currentItem.previewData !== undefined) {
tests/mocks/Unity/fake_scope.cpp+4−4
@@ -36,9 +36,9 @@ Scope::Scope(QString const& id, QString const& name, bool visible, QObject* pare
36 , m_visible(visible)
36 , m_visible(visible)
37 , m_searching(false)
37 , m_searching(false)
38 , m_isActive(false)
38 , m_isActive(false)
39+ , m_previewRendererName("preview-generic")
39 , m_categories(new Categories(this))
40 , m_categories(new Categories(this))
40 , m_results(new DeeListModel(this))
41 , m_results(new DeeListModel(this))
41− , m_previewRendererName("preview-generic")
42{
42{
43 DeeModel* results_model = create_results_model(20, 300);
43 DeeModel* results_model = create_results_model(20, 300);
44 m_categories->setResultModel(results_model);
44 m_categories->setResultModel(results_model);
@@ -155,7 +155,6 @@ void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVari
155 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
155 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
156 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
156 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
157{
157{
158− Q_UNUSED(uri);
159 Q_UNUSED(icon_hint);
158 Q_UNUSED(icon_hint);
160 Q_UNUSED(category);
159 Q_UNUSED(category);
161 Q_UNUSED(result_type);
160 Q_UNUSED(result_type);
@@ -165,7 +164,8 @@ void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVari
165 Q_UNUSED(dnd_uri);
164 Q_UNUSED(dnd_uri);
166 Q_UNUSED(metadata);
165 Q_UNUSED(metadata);
167
166
167+ if (uri != "uri://result.2")
168− m_timer.start();
168+ m_timer.start();
169}
169}
170
170
171void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
171void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
@@ -202,7 +202,7 @@ DeeModel* create_categories_model(unsigned category_count) {
202 for(unsigned i = 0; i < category_count; ++i)
202 for(unsigned i = 0; i < category_count; ++i)
203 {
203 {
204 dee_model_append(category_model,
204 dee_model_append(category_model,
205− std::to_string(i).c_str(),
205+ (i == 2) ? "installed" : std::to_string(i).c_str(),
206 ("Category "+std::to_string(i)).c_str(),
206 ("Category "+std::to_string(i)).c_str(),
207 "gtk-apply",
207 "gtk-apply",
208 i % 2 == 0 ? "grid" : "carousel",
208 i % 2 == 0 ? "grid" : "carousel",
tests/mocks/Unity/fake_scopes.cpp+1−1
@@ -54,7 +54,7 @@ Scopes::~Scopes()
54void Scopes::updateScopes()
54void Scopes::updateScopes()
55{
55{
56 clear();
56 clear();
57− addScope(new Scope("MockScope1", "People", true, this));
57+ addScope(new Scope("applications.scope", "People", true, this));
58 addScope(new Scope("MockScope2", "Music", false, this));
58 addScope(new Scope("MockScope2", "Music", false, this));
59 addScope(new Scope("home.scope", "Home", true, this));
59 addScope(new Scope("home.scope", "Home", true, this));
60 addScope(new ApplicationsScope(true, this));
60 addScope(new ApplicationsScope(true, this));
tests/qmltests/Dash/tst_GenericScopeView.qml+43−12
@@ -87,19 +87,26 @@ Item {
87 tryCompare(previewListView, "open", false);
87 tryCompare(previewListView, "open", false);
88 }
88 }
89
89
90− function openPreview() {
90+ function openPreview(filterGridName, willOpen) {
91− var categoryListView = findChild(genericScopeView, "categoryListView");
91+ if (filterGridName === undefined)
92− categoryListView.positionAtBeginning();
92+ filterGridName = "0";
93−
93+ if (willOpen === undefined)
94+ willOpen = true;
94 tryCompareFunction(function() {
95 tryCompareFunction(function() {
95− var tile = findChild(findChild(genericScopeView, "0"), "delegate0");
96+ var filterGrid = findChild(genericScopeView, filterGridName);
97+ console.log(filterGrid)
98+ if (filterGrid != null) {
99+ var tile = findChild(filterGrid, "delegate0");
96− return tile != undefined;
100+ return tile != undefined;
101+ }
102+ return false;
97 },
103 },
98 true);
104 true);
99− var tile = findChild(findChild(genericScopeView, "0"), "delegate0");
105+ var tile = findChild(findChild(genericScopeView, filterGridName), "delegate0");
106+ console.log(tile, tile.x, tile.y, tile.width, tile.height)
100 mouseClick(tile, tile.width / 2, tile.height / 2);
107 mouseClick(tile, tile.width / 2, tile.height / 2);
101− tryCompare(previewListView, "open", true);
108+ tryCompare(previewListView, "open", willOpen);
102− tryCompare(openEffect, "gap", 1);
109+ tryCompare(openEffect, "gap", willOpen ? 1 : 0);
103 }
110 }
104
111
105 function checkArrowPosition(index) {
112 function checkArrowPosition(index) {
@@ -129,6 +136,8 @@ Item {
129
136
130 function test_previewOpenClose() {
137 function test_previewOpenClose() {
131 tryCompare(previewListView, "open", false);
138 tryCompare(previewListView, "open", false);
139+ var categoryListView = findChild(genericScopeView, "categoryListView");
140+ categoryListView.positionAtBeginning();
132
141
133 openPreview();
142 openPreview();
134
143
@@ -168,6 +177,9 @@ Item {
168 }
177 }
169
178
170 function test_previewCycle() {
179 function test_previewCycle() {
180+ var categoryListView = findChild(genericScopeView, "categoryListView");
181+ categoryListView.positionAtBeginning();
182+
171 tryCompare(previewListView, "open", false);
183 tryCompare(previewListView, "open", false);
172 tryCompare(openEffect, "gap", 0);
184 tryCompare(openEffect, "gap", 0);
173
185
@@ -222,8 +234,13 @@ Item {
222 }
234 }
223
235
224 function test_show_spinner() {
236 function test_show_spinner() {
237+ var categoryListView = findChild(genericScopeView, "categoryListView");
238+ waitForRendering(categoryListView);
239+ categoryListView.contentY = units.gu(13);
225 openPreview();
240 openPreview();
226 var previewLoader = findChild(previewListView, "previewLoader0");
241 var previewLoader = findChild(previewListView, "previewLoader0");
242+ compare(previewLoader.source.toString().split("/").pop(), "DashPreviewPlaceholder.qml");
243+ compare(categoryListView.contentY, 0)
227 tryCompare(previewLoader, "progress", 1.0);
244 tryCompare(previewLoader, "progress", 1.0);
228 tryCompareFunction(function() { return previewLoader.item != undefined; }, true);
245 tryCompareFunction(function() { return previewLoader.item != undefined; }, true);
229
246
@@ -295,13 +312,13 @@ Item {
295
312
296 function test_filter_expand_expand() {
313 function test_filter_expand_expand() {
297 // wait for the item to be there
314 // wait for the item to be there
298− tryCompareFunction(function() { return findChild(genericScopeView, "dashSectionHeader2") != undefined; }, true);
315+ tryCompareFunction(function() { return findChild(genericScopeView, "dashSectionHeaderinstalled") != undefined; }, true);
299
316
300 var categoryListView = findChild(genericScopeView, "categoryListView");
317 var categoryListView = findChild(genericScopeView, "categoryListView");
301 categoryListView.contentY = categoryListView.height;
318 categoryListView.contentY = categoryListView.height;
302
319
303− var header2 = findChild(genericScopeView, "dashSectionHeader2")
320+ var header2 = findChild(genericScopeView, "dashSectionHeaderinstalled")
304− var category2 = findChild(genericScopeView, "dashCategory2")
321+ var category2 = findChild(genericScopeView, "dashCategoryinstalled")
305 var category2FilterGrid = category2.children[0].children[0].children[0];
322 var category2FilterGrid = category2.children[0].children[0].children[0];
306 verify(UT.Util.isInstanceOf(category2FilterGrid, "FilterGrid"));
323 verify(UT.Util.isInstanceOf(category2FilterGrid, "FilterGrid"));
307
324
@@ -330,6 +347,20 @@ Item {
330 tryCompare(category2, "filtered", true);
347 tryCompare(category2, "filtered", true);
331 tryCompare(category2FilterGrid, "filter", true);
348 tryCompare(category2FilterGrid, "filter", true);
332 }
349 }
350+
351+ function test_no_move_y_no_preview() {
352+ waitForRendering(genericScopeView);
353+ var categoryListView = findChild(genericScopeView, "categoryListView");
354+ waitForRendering(categoryListView);
355+ var category = findChild(genericScopeView, "dashCategoryinstalled")
356+ categoryListView.contentY = category.y;
357+ waitForRendering(categoryListView);
358+ var contentYBefore = categoryListView.contentY
359+ openPreview("installed", false); // This actually doesn't open anything because we
360+ // have code so that the item of installed
361+ // does activate instead of preview and never shows a preview
362+ compare(categoryListView.contentY, contentYBefore);
363+ }
333 }
364 }
334 }
365 }
335
366