Merge lp:~nick-dedekind/unity8/lp1328646 into lp:unity8
- lp1328646
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | kevin gunn |
Approved revision: | 1186 |
Merged at revision: | 1182 |
Proposed branch: | lp:~nick-dedekind/unity8/lp1328646 |
Merge into: | lp:unity8 |
Diff against target: |
491 lines (+206/-89) 14 files modified
plugins/Unity/Indicators/qmldir (+0/-3) plugins/Unity/Indicators/unitymenumodelcache.cpp (+26/-11) plugins/Unity/Indicators/unitymenumodelcache.h (+5/-3) qml/Greeter/Clock.qml (+2/-1) qml/Panel/Indicators/CachedUnityMenuModel.qml (+10/-31) qml/Panel/Indicators/DefaultIndicatorWidget.qml (+2/-1) qml/Panel/Indicators/IndicatorBase.qml (+4/-2) tests/mocks/QMenuModel/unitymenumodel.cpp (+4/-5) tests/mocks/Unity/Indicators/CMakeLists.txt (+6/-1) tests/mocks/Unity/Indicators/CachedUnityMenuModel.qml (+0/-30) tests/mocks/Unity/Indicators/fakeplugin.cpp (+9/-0) tests/mocks/Unity/Indicators/qmldir (+0/-1) tests/qmltests/CMakeLists.txt (+1/-0) tests/qmltests/Panel/Indicators/tst_CachedUnityMenuModel.qml (+137/-0) |
To merge this branch: | bzr merge lp:~nick-dedekind/unity8/lp1328646 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
kevin gunn (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Needs Fixing | |
Albert Astals Cid (community) | Needs Information | ||
Michał Sawicz | Needs Information | ||
Review via email:
|
Commit message
Fixed CachedUnityMenu
Description of the change
Fixed CachedUnityMenu
Destroying cached model was causing menu path to update to "".
Added tests for CachedMenuModel
* Are there any related MPs required for this MP to build/function as expected? Please list.
No
* Did you perform an exploratory manual test run of your code change and any related functionality?
Yes
* Did you make sure that your branch does not contain spurious tags?
Yes
* If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
N/A
* If you changed the UI, has there been a design review?
N/A
- 1181. By Nick Dedekind
-
added test for lp1328646
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1181
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 1182. By Nick Dedekind
-
use qml ownership for models
- 1183. By Nick Dedekind
-
review comments
- 1184. By Nick Dedekind
-
removed debug
- 1185. By Nick Dedekind
-
Added tests for model delete
- 1186. By Nick Dedekind
-
Reverted shell change
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Nick Dedekind (nick-dedekind) wrote : | # |
> I really hate the ref/deref happening on QML side, could we use QML ownership
> to do this?
I think I've addressed all your concerns. Was able to move the model instantiation into the cache now that i've fixed up the QMenuModel mocking.
The GC looks a bit hairy in the qmltests for testing the deletion, but it seems to work.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Albert Astals Cid (aacid) wrote : | # |
Code looks good, testing it in the phone now
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1184
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Albert Astals Cid (aacid) wrote : | # |
So i guess it is fixed, but still suffers from only updating every X seconds, so if i locked at 47, wait will 50, unlock, it will still say 47 for a few seconds, that is very bad.
Is there that in any way related to this fixes or shall a new bug be opened about that?
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
kevin gunn (kgunn72) wrote : | # |
> So i guess it is fixed, but still suffers from only updating every X seconds,
> so if i locked at 47, wait will 50, unlock, it will still say 47 for a few
> seconds, that is very bad.
>
> Is there that in any way related to this fixes or shall a new bug be opened
> about that?
Is that only on the indicator ? i assume greeter is reflecting the correct time?
agreed, we should open another bug in an effort to land this and unblock the train
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1186
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
kevin gunn (kgunn72) wrote : | # |
approving as albert was ok with code & it fixes the primary problem. will open bug for secondary issue of lagging clock update after waking.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Charles Kerr (charlesk) wrote : | # |
Preview Diff
1 | === modified file 'plugins/Unity/Indicators/qmldir' |
2 | --- plugins/Unity/Indicators/qmldir 2014-07-30 08:10:40 +0000 |
3 | +++ plugins/Unity/Indicators/qmldir 2014-08-20 09:19:41 +0000 |
4 | @@ -1,6 +1,3 @@ |
5 | module Unity.Indicators |
6 | plugin IndicatorsQml |
7 | typeinfo Indicators.qmltypes |
8 | - |
9 | -CachedUnityMenuModel 0.1 CachedUnityMenuModel.qml |
10 | -IndicatorBase 0.1 IndicatorBase.qml |
11 | |
12 | === modified file 'plugins/Unity/Indicators/unitymenumodelcache.cpp' |
13 | --- plugins/Unity/Indicators/unitymenumodelcache.cpp 2013-08-30 08:17:10 +0000 |
14 | +++ plugins/Unity/Indicators/unitymenumodelcache.cpp 2014-08-20 09:19:41 +0000 |
15 | @@ -29,14 +29,29 @@ |
16 | { |
17 | } |
18 | |
19 | - |
20 | -UnityMenuModel* UnityMenuModelCache::model(const QString& path) const |
21 | -{ |
22 | - return m_menuModels.value(path, NULL); |
23 | -} |
24 | - |
25 | -void UnityMenuModelCache::registerModel(const QString& path, UnityMenuModel* menuModel) |
26 | -{ |
27 | - menuModel->setParent(this); |
28 | - m_menuModels[path] = menuModel; |
29 | -} |
30 | \ No newline at end of file |
31 | +UnityMenuModel* UnityMenuModelCache::model(const QByteArray& bus, |
32 | + const QByteArray& path, |
33 | + const QVariantMap& actions) |
34 | +{ |
35 | + if (m_registry.contains(path)) |
36 | + return m_registry[path]; |
37 | + |
38 | + UnityMenuModel* menuModel = new UnityMenuModel; |
39 | + connect(menuModel, &QObject::destroyed, this, [menuModel, this](QObject*) { |
40 | + QList<QByteArray> keys = m_registry.keys(menuModel); |
41 | + Q_FOREACH(const QByteArray& key, keys) { |
42 | + m_registry.remove(key); |
43 | + } |
44 | + }); |
45 | + m_registry[path] = menuModel; |
46 | + |
47 | + menuModel->setBusName(bus); |
48 | + menuModel->setMenuObjectPath(path); |
49 | + menuModel->setActions(actions); |
50 | + return menuModel; |
51 | +} |
52 | + |
53 | +bool UnityMenuModelCache::contains(const QByteArray& path) |
54 | +{ |
55 | + return m_registry.contains(path); |
56 | +} |
57 | |
58 | === modified file 'plugins/Unity/Indicators/unitymenumodelcache.h' |
59 | --- plugins/Unity/Indicators/unitymenumodelcache.h 2013-08-30 08:17:10 +0000 |
60 | +++ plugins/Unity/Indicators/unitymenumodelcache.h 2014-08-20 09:19:41 +0000 |
61 | @@ -34,11 +34,13 @@ |
62 | UnityMenuModelCache(QObject*parent=NULL); |
63 | ~UnityMenuModelCache(); |
64 | |
65 | - Q_INVOKABLE UnityMenuModel* model(const QString& path) const; |
66 | - Q_INVOKABLE void registerModel(const QString& path, UnityMenuModel* menuModel); |
67 | + Q_INVOKABLE UnityMenuModel* model(const QByteArray& bus, |
68 | + const QByteArray& path, |
69 | + const QVariantMap& actions); |
70 | + Q_INVOKABLE bool contains(const QByteArray& path); |
71 | |
72 | private: |
73 | - QHash<QString, UnityMenuModel*> m_menuModels; |
74 | + QHash<QByteArray, UnityMenuModel*> m_registry; |
75 | }; |
76 | |
77 | #endif // UNITYMENUMODELCACHE_H |
78 | |
79 | === modified file 'qml/Greeter/Clock.qml' |
80 | --- qml/Greeter/Clock.qml 2014-06-12 15:03:20 +0000 |
81 | +++ qml/Greeter/Clock.qml 2014-08-20 09:19:41 +0000 |
82 | @@ -16,6 +16,7 @@ |
83 | |
84 | import QtQuick 2.0 |
85 | import Ubuntu.Components 0.1 |
86 | +import "../Panel/Indicators" |
87 | import Unity.Indicators 0.1 as Indicators |
88 | |
89 | Item { |
90 | @@ -33,7 +34,7 @@ |
91 | } |
92 | } |
93 | |
94 | - Indicators.CachedUnityMenuModel { |
95 | + CachedUnityMenuModel { |
96 | id: timeModel |
97 | objectName: "timeModel" |
98 | |
99 | |
100 | === renamed file 'plugins/Unity/Indicators/CachedUnityMenuModel.qml' => 'qml/Panel/Indicators/CachedUnityMenuModel.qml' |
101 | --- plugins/Unity/Indicators/CachedUnityMenuModel.qml 2014-06-26 10:00:41 +0000 |
102 | +++ qml/Panel/Indicators/CachedUnityMenuModel.qml 2014-08-20 09:19:41 +0000 |
103 | @@ -18,43 +18,22 @@ |
104 | */ |
105 | |
106 | import QtQuick 2.0 |
107 | -import QMenuModel 0.1 as QMenuModel |
108 | +import QMenuModel 0.1 |
109 | import Unity.Indicators 0.1 as Indicators |
110 | |
111 | // Make sure we don't duplicate models. |
112 | Item { |
113 | id: cachedModel |
114 | - property string busName: "" |
115 | - property string actionsObjectPath: "" |
116 | - property string menuObjectPath: "" |
117 | - |
118 | + property string busName |
119 | + property string actionsObjectPath |
120 | + property string menuObjectPath |
121 | readonly property bool ready: busName!=="" && actionsObjectPath!=="" && menuObjectPath!=="" |
122 | |
123 | - property QtObject model: { |
124 | - if (!ready) { |
125 | - return null; |
126 | - } |
127 | - |
128 | - var component = Indicators.UnityMenuModelCache.model(menuObjectPath); |
129 | - if (!component) { |
130 | - component = modelComponent.createObject(cachedModel); |
131 | - return component; |
132 | - } |
133 | - return component; |
134 | - } |
135 | - |
136 | - Component { |
137 | - id: modelComponent |
138 | - |
139 | - QMenuModel.UnityMenuModel { |
140 | - id: unityModel |
141 | - busName: cachedModel.busName |
142 | - actions: { "indicator": cachedModel.actionsObjectPath } |
143 | - menuObjectPath: cachedModel.menuObjectPath |
144 | - |
145 | - Component.onCompleted: { |
146 | - Indicators.UnityMenuModelCache.registerModel(cachedModel.menuObjectPath, unityModel); |
147 | - } |
148 | - } |
149 | + property var model: { |
150 | + if (!ready) return null; |
151 | + |
152 | + return Indicators.UnityMenuModelCache.model(cachedModel.busName, |
153 | + cachedModel.menuObjectPath, |
154 | + { "indicator": cachedModel.actionsObjectPath }); |
155 | } |
156 | } |
157 | |
158 | === modified file 'qml/Panel/Indicators/DefaultIndicatorWidget.qml' |
159 | --- qml/Panel/Indicators/DefaultIndicatorWidget.qml 2014-07-03 14:47:28 +0000 |
160 | +++ qml/Panel/Indicators/DefaultIndicatorWidget.qml 2014-08-20 09:19:41 +0000 |
161 | @@ -63,6 +63,7 @@ |
162 | } |
163 | |
164 | Row { |
165 | + id: iconRow |
166 | anchors { |
167 | top: parent.top |
168 | bottom: parent.bottom |
169 | @@ -73,7 +74,7 @@ |
170 | |
171 | Item { |
172 | width: itemImage.width + units.gu(1) |
173 | - anchors { top: parent.top; bottom: parent.bottom } |
174 | + height: iconRow.height |
175 | |
176 | StatusIcon { |
177 | id: itemImage |
178 | |
179 | === modified file 'qml/Panel/Indicators/IndicatorBase.qml' |
180 | --- qml/Panel/Indicators/IndicatorBase.qml 2014-06-27 09:16:16 +0000 |
181 | +++ qml/Panel/Indicators/IndicatorBase.qml 2014-08-20 09:19:41 +0000 |
182 | @@ -34,6 +34,7 @@ |
183 | property string deviceMenuObjectPath: menuObjectPath |
184 | |
185 | property alias menuModel: cachedModel.model |
186 | + property alias rootActionState: rootAction |
187 | |
188 | CachedUnityMenuModel { |
189 | id: cachedModel |
190 | @@ -42,8 +43,9 @@ |
191 | menuObjectPath: indicatorItem.deviceMenuObjectPath |
192 | } |
193 | |
194 | - property RootActionState rootActionState: RootActionState { |
195 | - menu: menuModel |
196 | + RootActionState { |
197 | + id: rootAction |
198 | + menu: menuModel ? menuModel : null |
199 | onUpdated: indicatorItem.rootActionStateChanged() |
200 | } |
201 | } |
202 | |
203 | === modified file 'tests/mocks/QMenuModel/unitymenumodel.cpp' |
204 | --- tests/mocks/QMenuModel/unitymenumodel.cpp 2014-07-22 14:46:01 +0000 |
205 | +++ tests/mocks/QMenuModel/unitymenumodel.cpp 2014-08-20 09:19:41 +0000 |
206 | @@ -17,7 +17,6 @@ |
207 | */ |
208 | |
209 | #include "unitymenumodel.h" |
210 | -#include <QDebug> |
211 | |
212 | enum MenuRoles { |
213 | LabelRole = Qt::DisplayRole + 1, |
214 | @@ -38,6 +37,10 @@ |
215 | { |
216 | } |
217 | |
218 | +UnityMenuModel::~UnityMenuModel() |
219 | +{ |
220 | +} |
221 | + |
222 | QVariant UnityMenuModel::modelData() const |
223 | { |
224 | return m_modelData; |
225 | @@ -83,10 +86,6 @@ |
226 | endRemoveRows(); |
227 | } |
228 | |
229 | -UnityMenuModel::~UnityMenuModel() |
230 | -{ |
231 | -} |
232 | - |
233 | QByteArray UnityMenuModel::busName() const |
234 | { |
235 | return m_busName; |
236 | |
237 | === modified file 'tests/mocks/Unity/Indicators/CMakeLists.txt' |
238 | --- tests/mocks/Unity/Indicators/CMakeLists.txt 2014-05-02 23:35:51 +0000 |
239 | +++ tests/mocks/Unity/Indicators/CMakeLists.txt 2014-08-20 09:19:41 +0000 |
240 | @@ -14,6 +14,7 @@ |
241 | fakeplugin.cpp |
242 | ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/indicators.h |
243 | ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/menucontentactivator.cpp |
244 | + ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelcache.cpp |
245 | ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelstack.cpp |
246 | ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/visibleindicatorsmodel.cpp |
247 | fakeindicatorsmodel.cpp |
248 | @@ -33,7 +34,11 @@ |
249 | ) |
250 | add_definitions(-DUNITYINDICATORS_LIBRARY) |
251 | |
252 | -target_link_libraries(IndicatorsFakeQml) |
253 | +add_dependencies(IndicatorsFakeQml QMenuModelQml) |
254 | +target_link_libraries(IndicatorsFakeQml |
255 | + -L${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel |
256 | + -lqmenumodel |
257 | +) |
258 | |
259 | qt5_use_modules(IndicatorsFakeQml Core Qml Quick) |
260 | |
261 | |
262 | === removed file 'tests/mocks/Unity/Indicators/CachedUnityMenuModel.qml' |
263 | --- tests/mocks/Unity/Indicators/CachedUnityMenuModel.qml 2013-10-11 18:58:51 +0000 |
264 | +++ tests/mocks/Unity/Indicators/CachedUnityMenuModel.qml 1970-01-01 00:00:00 +0000 |
265 | @@ -1,30 +0,0 @@ |
266 | -/* |
267 | - * Copyright 2013 Canonical Ltd. |
268 | - * |
269 | - * This program is free software; you can redistribute it and/or modify |
270 | - * it under the terms of the GNU Lesser General Public License as published by |
271 | - * the Free Software Foundation; version 3. |
272 | - * |
273 | - * This program is distributed in the hope that it will be useful, |
274 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
275 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
276 | - * GNU Lesser General Public License for more details. |
277 | - * |
278 | - * You should have received a copy of the GNU Lesser General Public License |
279 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
280 | - * |
281 | - * Authors: |
282 | - * Nick Dedekind <nick.dedekind@canonical.com> |
283 | - */ |
284 | - |
285 | -import QtQuick 2.0 |
286 | - |
287 | -Item { |
288 | - property string busName: "" |
289 | - property string actionsObjectPath: "" |
290 | - property string menuObjectPath: "" |
291 | - |
292 | - readonly property bool ready: false |
293 | - |
294 | - property QtObject model: null |
295 | -} |
296 | |
297 | === modified file 'tests/mocks/Unity/Indicators/fakeplugin.cpp' |
298 | --- tests/mocks/Unity/Indicators/fakeplugin.cpp 2014-03-03 12:03:30 +0000 |
299 | +++ tests/mocks/Unity/Indicators/fakeplugin.cpp 2014-08-20 09:19:41 +0000 |
300 | @@ -26,9 +26,16 @@ |
301 | #include "fakeindicatorsmodel.h" |
302 | #include "indicators.h" |
303 | #include "menucontentactivator.h" |
304 | +#include "unitymenumodelcache.h" |
305 | #include "unitymenumodelstack.h" |
306 | #include "visibleindicatorsmodel.h" |
307 | |
308 | +static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) { |
309 | + Q_UNUSED(engine); |
310 | + Q_UNUSED(scriptEngine); |
311 | + return new UnityMenuModelCache; |
312 | +} |
313 | + |
314 | void IndicatorsFakePlugin::registerTypes(const char * uri) |
315 | { |
316 | Q_INIT_RESOURCE(indicators_fake); |
317 | @@ -41,6 +48,8 @@ |
318 | qmlRegisterType<UnityMenuModelStack>(uri, 0, 1, "UnityMenuModelStack"); |
319 | qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel"); |
320 | |
321 | + qmlRegisterSingletonType<UnityMenuModelCache>(uri, 0, 1, "UnityMenuModelCache", menuModelCacheSingleton); |
322 | + |
323 | // external uncreatables |
324 | qmlRegisterUncreatableType<MenuContentState>(uri, 0, 1, "MenuContentState", "Can't create MenuContentState class"); |
325 | qmlRegisterUncreatableType<ActionState>(uri, 0, 1, "ActionState", "Can't create ActionState class"); |
326 | |
327 | === modified file 'tests/mocks/Unity/Indicators/qmldir' |
328 | --- tests/mocks/Unity/Indicators/qmldir 2014-06-27 09:16:16 +0000 |
329 | +++ tests/mocks/Unity/Indicators/qmldir 2014-08-20 09:19:41 +0000 |
330 | @@ -2,7 +2,6 @@ |
331 | plugin IndicatorsFakeQml |
332 | typeinfo Indicators.qmltypes |
333 | |
334 | -CachedUnityMenuModel 0.1 CachedUnityMenuModel.qml |
335 | IndicatorsModel 0.1 IndicatorsModel.qml |
336 | FakeMenuPage 0.1 FakeMenuPage.qml |
337 | RootActionState 0.1 RootActionState.qml |
338 | |
339 | === modified file 'tests/qmltests/CMakeLists.txt' |
340 | --- tests/qmltests/CMakeLists.txt 2014-08-14 11:35:05 +0000 |
341 | +++ tests/qmltests/CMakeLists.txt 2014-08-20 09:19:41 +0000 |
342 | @@ -72,6 +72,7 @@ |
343 | add_qml_test(Panel SearchIndicator) |
344 | add_qml_test(Panel/Indicators DefaultIndicatorWidget ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel") |
345 | add_qml_test(Panel/Indicators DefaultIndicatorPage ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel") |
346 | +add_qml_test(Panel/Indicators CachedUnityMenuModel ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel") |
347 | # These MenuItemFactory tests need the test/mocks/ to come before plugins/ |
348 | add_qml_test(Panel/Indicators MenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS}) |
349 | add_qml_test(Panel/Indicators MessageMenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS}) |
350 | |
351 | === added file 'tests/qmltests/Panel/Indicators/tst_CachedUnityMenuModel.qml' |
352 | --- tests/qmltests/Panel/Indicators/tst_CachedUnityMenuModel.qml 1970-01-01 00:00:00 +0000 |
353 | +++ tests/qmltests/Panel/Indicators/tst_CachedUnityMenuModel.qml 2014-08-20 09:19:41 +0000 |
354 | @@ -0,0 +1,137 @@ |
355 | +/* |
356 | + * Copyright 2014 Canonical Ltd. |
357 | + * |
358 | + * This program is free software; you can redistribute it and/or modify |
359 | + * it under the terms of the GNU General Public License as published by |
360 | + * the Free Software Foundation; version 3. |
361 | + * |
362 | + * This program is distributed in the hope that it will be useful, |
363 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
364 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
365 | + * GNU General Public License for more details. |
366 | + * |
367 | + * You should have received a copy of the GNU General Public License |
368 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
369 | + */ |
370 | + |
371 | +import QtQuick 2.0 |
372 | +import QtTest 1.0 |
373 | +import Unity.Test 0.1 as UT |
374 | +import QMenuModel 0.1 |
375 | +import Unity.Indicators 0.1 as Indicators |
376 | +import "../../../../qml/Panel/Indicators" |
377 | + |
378 | +Item { |
379 | + id: root |
380 | + width: units.gu(40) |
381 | + height: units.gu(70) |
382 | + |
383 | + Component { |
384 | + id: model |
385 | + CachedUnityMenuModel {} |
386 | + } |
387 | + |
388 | + UT.UnityTestCase { |
389 | + name: "CachedUnityMenuModel" |
390 | + when: windowShown |
391 | + |
392 | + function cleanup() { |
393 | + doGC(); |
394 | + } |
395 | + |
396 | + function doGC() { |
397 | + // need to put some wait cycles here to get gc going properly. |
398 | + wait(10); |
399 | + gc(); |
400 | + wait(10); |
401 | + } |
402 | + |
403 | + function test_createDifferent() { |
404 | + var cachedObject = model.createObject(null, |
405 | + { |
406 | + "busName": "com.canonical.test1", |
407 | + "menuObjectPath": "/com/canonical/test1", |
408 | + "actionsObjectPath": "/com/canonical/test1" |
409 | + }); |
410 | + |
411 | + var cachedObject2 = model.createObject(null, |
412 | + { |
413 | + "busName": "com.canonical.test2", |
414 | + "menuObjectPath": "/com/canonical/test2", |
415 | + "actionsObjectPath": "/com/canonical/test2" |
416 | + }); |
417 | + |
418 | + verify(cachedObject.model !== cachedObject2.model); |
419 | + } |
420 | + |
421 | + function test_createSame() { |
422 | + var cachedObject = model.createObject(null, |
423 | + { |
424 | + "busName": "com.canonical.test3", |
425 | + "menuObjectPath": "/com/canonical/test3", |
426 | + "actionsObjectPath": "/com/canonical/test3" |
427 | + }); |
428 | + |
429 | + var cachedObject2 = model.createObject(null, |
430 | + { |
431 | + "busName": "com.canonical.test3", |
432 | + "menuObjectPath": "/com/canonical/test3", |
433 | + "actionsObjectPath": "/com/canonical/test3" |
434 | + }); |
435 | + |
436 | + verify(cachedObject.model === cachedObject2.model); |
437 | + } |
438 | + |
439 | + // Tests that changing cached model data does not change the model path of others |
440 | + function test_lp1328646() { |
441 | + var cachedObject = model.createObject(null, |
442 | + { |
443 | + "busName": "com.canonical.test4", |
444 | + "menuObjectPath": "/com/canonical/test4", |
445 | + "actionsObjectPath": "/com/canonical/test4" |
446 | + }); |
447 | + |
448 | + var cachedObject2 = model.createObject(null, |
449 | + { |
450 | + "busName": "com.canonical.test4", |
451 | + "menuObjectPath": "/com/canonical/test4", |
452 | + "actionsObjectPath": "/com/canonical/test4" |
453 | + }); |
454 | + |
455 | + cachedObject.menuObjectPath = "/com/canonical/test5"; |
456 | + compare(cachedObject.model.menuObjectPath, "/com/canonical/test5"); |
457 | + compare(cachedObject2.model.menuObjectPath, "/com/canonical/test4"); |
458 | + |
459 | + verify(cachedObject.model !== cachedObject2.model); |
460 | + } |
461 | + |
462 | + function createAndDestroy(test) { |
463 | + var cachedObject = model.createObject(null, |
464 | + { |
465 | + "busName": "com.canonical."+test, |
466 | + "menuObjectPath": "/com/canonical/"+test, |
467 | + "actionsObjectPath": "/com/canonical/"+test |
468 | + }); |
469 | + var cachedObject2 = model.createObject(null, |
470 | + { |
471 | + "busName": "com.canonical."+test, |
472 | + "menuObjectPath": "/com/canonical/"+test, |
473 | + "actionsObjectPath": "/com/canonical/"+test |
474 | + }); |
475 | + cachedObject.destroy(); |
476 | + return cachedObject2; |
477 | + } |
478 | + |
479 | + function test_destroyAllDeletesModel() { |
480 | + createAndDestroy("test6"); |
481 | + doGC(); |
482 | + compare(Indicators.UnityMenuModelCache.contains("/com/canonical/test6"), false); |
483 | + } |
484 | + |
485 | + function test_destroyPartialKeepsModel() { |
486 | + var model = createAndDestroy("test7"); |
487 | + doGC(); |
488 | + compare(Indicators.UnityMenuModelCache.contains("/com/canonical/test7"), true); |
489 | + } |
490 | + } |
491 | +} |
I really hate the ref/deref happening on QML side, could we use QML ownership to do this?