on xenial help sign in
CachedUnityMenuModel -> SharedUnityMenuModel
commitf38a47faaf8b80d9631fbfbac9e1e985288b8dba authorNick Dedekind <nick.dedekind@canonical.com> dateFri 12 Sep 2014, 14:01 (12 years ago) parent6798389
15 files changed+284−200
plugins/Unity/Indicators/CMakeLists.txt+1 plugins/Unity/Indicators/plugin.cpp+3−1 plugins/Unity/Indicators/sharedunitymenumodel.cpp+87 plugins/Unity/Indicators/sharedunitymenumodel.h+66 plugins/Unity/Indicators/unitymenumodelcache.cpp+25−12 plugins/Unity/Indicators/unitymenumodelcache.h+10−5 qml/Greeter/Clock.qml+2−2 qml/Panel/Indicators/CachedUnityMenuModel.qml−39 qml/Panel/Indicators/IndicatorBase.qml+2−2 tests/mocks/Unity/Indicators/CMakeLists.txt+1 tests/mocks/Unity/Indicators/fakeplugin.cpp+3−1 tests/plugins/Unity/Indicators/CMakeLists.txt+1 tests/plugins/Unity/Indicators/sharedunitymenumodeltest.cpp+83 tests/qmltests/CMakeLists.txt−1 tests/qmltests/Panel/Indicators/tst_CachedUnityMenuModel.qml−137
plugins/Unity/Indicators/CMakeLists.txt+1
@@ -24,6 +24,7 @@ set(IndicatorsQML_SOURCES
2424 modelprinter.cpp
2525 plugin.cpp
2626 rootactionstate.cpp
27+ sharedunitymenumodel.cpp
2728 unitymenumodelcache.cpp
2829 unitymenumodelstack.cpp
2930 visibleindicatorsmodel.cpp
plugins/Unity/Indicators/plugin.cpp+3−1
@@ -30,6 +30,7 @@
3030#include "menucontentactivator.h"
3131#include "modelprinter.h"
3232#include "rootactionstate.h"
33+#include "sharedunitymenumodel.h"
3334#include "unitymenumodelcache.h"
3435#include "unitymenumodelstack.h"
3536#include "visibleindicatorsmodel.h"
@@ -37,7 +38,7 @@
3738static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
3839 Q_UNUSED(engine);
3940 Q_UNUSED(scriptEngine);
40− return new UnityMenuModelCache;
41+ return UnityMenuModelCache::singleton();
4142}
4243
4344void Indicators2Plugin::registerTypes(const char *uri)
@@ -51,6 +52,7 @@ void Indicators2Plugin::registerTypes(const char *uri)
5152 qmlRegisterType<RootActionState>(uri, 0, 1, "RootActionState");
5253 qmlRegisterType<ModelPrinter>(uri, 0, 1, "ModelPrinter");
5354 qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel");
55+ qmlRegisterType<SharedUnityMenuModel>(uri, 0, 1, "SharedUnityMenuModel");
5456
5557 qmlRegisterSingletonType<UnityMenuModelCache>(uri, 0, 1, "UnityMenuModelCache", menuModelCacheSingleton);
5658
plugins/Unity/Indicators/sharedunitymenumodel.cppnew file+87
@@ -0,0 +1,87 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ */
17+
18+#include "sharedunitymenumodel.h"
19+#include "unitymenumodelcache.h"
20+
21+SharedUnityMenuModel::SharedUnityMenuModel(QObject* parent)
22+ : QObject(parent)
23+{
24+}
25+
26+QByteArray SharedUnityMenuModel::busName() const
27+{
28+ return m_busName;
29+}
30+
31+void SharedUnityMenuModel::setBusName(const QByteArray& busName)
32+{
33+ if (m_busName != busName) {
34+ m_busName = busName;
35+ Q_EMIT busNameChanged();
36+ initialize();
37+ }
38+}
39+
40+QByteArray SharedUnityMenuModel::menuObjectPath() const
41+{
42+ return m_menuObjectPath;
43+}
44+
45+void SharedUnityMenuModel::setMenuObjectPath(const QByteArray& menuObjectPath)
46+{
47+ if (m_menuObjectPath != menuObjectPath) {
48+ m_menuObjectPath = menuObjectPath;
49+ Q_EMIT menuObjectPathChanged();
50+ initialize();
51+ }
52+}
53+
54+QVariantMap SharedUnityMenuModel::actions() const
55+{
56+ return m_actions;
57+}
58+
59+void SharedUnityMenuModel::setActions(const QVariantMap& actions)
60+{
61+ if (m_actions != actions) {
62+ m_actions = actions;
63+ Q_EMIT actionsChanged();
64+ initialize();
65+ }
66+}
67+
68+UnityMenuModel* SharedUnityMenuModel::model() const
69+{
70+ return m_model ? m_model.data() : nullptr;
71+}
72+
73+void SharedUnityMenuModel::initialize()
74+{
75+ if (m_busName.isEmpty() || m_menuObjectPath.isEmpty() || m_actions.isEmpty()) {
76+ if (!m_model.isNull()) {
77+ m_model.clear();
78+ Q_EMIT modelChanged();
79+ }
80+ } else {
81+ QSharedPointer<UnityMenuModel> model = UnityMenuModelCache::singleton()->model(m_busName, m_menuObjectPath, m_actions);
82+ if (model != m_model) {
83+ m_model = model;
84+ Q_EMIT modelChanged();
85+ }
86+ }
87+}
plugins/Unity/Indicators/sharedunitymenumodel.hnew file+66
@@ -0,0 +1,66 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ */
17+
18+#ifndef SHAREDUNITYMENUMODEL_H
19+#define SHAREDUNITYMENUMODEL_H
20+
21+#include "unityindicatorsglobal.h"
22+
23+#include <QObject>
24+#include <QSharedPointer>
25+#include <QVariantMap>
26+
27+class UnityMenuModel;
28+
29+class UNITYINDICATORS_EXPORT SharedUnityMenuModel : public QObject
30+{
31+ Q_OBJECT
32+ Q_PROPERTY(QByteArray busName READ busName WRITE setBusName NOTIFY busNameChanged)
33+ Q_PROPERTY(QByteArray menuObjectPath READ menuObjectPath WRITE setMenuObjectPath NOTIFY menuObjectPathChanged)
34+ Q_PROPERTY(QVariantMap actions READ actions WRITE setActions NOTIFY actionsChanged)
35+ Q_PROPERTY(UnityMenuModel* model READ model NOTIFY modelChanged)
36+
37+public:
38+ SharedUnityMenuModel(QObject* parent = nullptr);
39+
40+ QByteArray busName() const;
41+ void setBusName(const QByteArray&);
42+
43+ QByteArray menuObjectPath() const;
44+ void setMenuObjectPath(const QByteArray&);
45+
46+ QVariantMap actions() const;
47+ void setActions(const QVariantMap&);
48+
49+ UnityMenuModel* model() const;
50+
51+Q_SIGNALS:
52+ void busNameChanged();
53+ void menuObjectPathChanged();
54+ void actionsChanged();
55+ void modelChanged();
56+
57+private:
58+ void initialize();
59+
60+ QByteArray m_busName;
61+ QByteArray m_menuObjectPath;
62+ QVariantMap m_actions;
63+ QSharedPointer<UnityMenuModel> m_model;
64+};
65+
66+#endif // SHAREDUNITYMENUMODEL_H
plugins/Unity/Indicators/unitymenumodelcache.cpp+25−12
@@ -19,31 +19,44 @@
1919
2020#include "unitymenumodelcache.h"
2121#include <unitymenumodel.h>
22+#include <QDebug>
2223
23−UnityMenuModelCache::UnityMenuModelCache(QObject* parent)
24− : QObject(parent)
24+UnityMenuModelCache* UnityMenuModelCache::theCache = nullptr;
25+
26+
27+UnityMenuModelCache* UnityMenuModelCache::singleton()
2528{
29+ if (!theCache) {
30+ theCache = new UnityMenuModelCache();
31+ }
32+ return theCache;
2633}
2734
28−UnityMenuModelCache::~UnityMenuModelCache()
35+UnityMenuModelCache::UnityMenuModelCache(QObject* parent)
36+ : QObject(parent)
2937{
3038}
3139
32−UnityMenuModel* UnityMenuModelCache::model(const QByteArray& bus,
33− const QByteArray& path,
34− const QVariantMap& actions)
40+QSharedPointer<UnityMenuModel> UnityMenuModelCache::model(const QByteArray& bus,
41+ const QByteArray& path,
42+ const QVariantMap& actions)
3543{
3644 if (m_registry.contains(path))
3745 return m_registry[path];
3846
39− UnityMenuModel* menuModel = new UnityMenuModel;
40− connect(menuModel, &QObject::destroyed, this, [menuModel, this](QObject*) {
41− QList<QByteArray> keys = m_registry.keys(menuModel);
42− Q_FOREACH(const QByteArray& key, keys) {
43− m_registry.remove(key);
47+ UnityMenuModel* model = new UnityMenuModel;
48+ QSharedPointer<UnityMenuModel> menuModel(model);
49+ connect(model, &QObject::destroyed, this, [this] {
50+ QMutableHashIterator<QByteArray, QWeakPointer<UnityMenuModel>> iter(m_registry);
51+ while(iter.hasNext()) {
52+ auto keyVal = iter.next();
53+ if (keyVal.value().toStrongRef().isNull()) {
54+ qDebug() << "BAH: destroyed model! " << keyVal.key();
55+ iter.remove();
56+ }
4457 }
4558 });
46− m_registry[path] = menuModel;
59+ m_registry[path] = menuModel.toWeakRef();
4760
4861 menuModel->setBusName(bus);
4962 menuModel->setMenuObjectPath(path);
plugins/Unity/Indicators/unitymenumodelcache.h+10−5
@@ -24,6 +24,7 @@
2424
2525#include <QObject>
2626#include <QHash>
27+#include <QWeakPointer>
2728
2829class UnityMenuModel;
2930
@@ -32,15 +33,19 @@ class UNITYINDICATORS_EXPORT UnityMenuModelCache : public QObject
3233 Q_OBJECT
3334public:
3435 UnityMenuModelCache(QObject*parent=nullptr);
35− ~UnityMenuModelCache();
3636
37− Q_INVOKABLE UnityMenuModel* model(const QByteArray& bus,
38− const QByteArray& path,
39− const QVariantMap& actions);
37+ static UnityMenuModelCache* singleton();
38+
39+ QSharedPointer<UnityMenuModel> model(const QByteArray& bus,
40+ const QByteArray& path,
41+ const QVariantMap& actions);
42+
43+ // for tests use
4044 Q_INVOKABLE bool contains(const QByteArray& path);
4145
4246private:
43− QHash<QByteArray, UnityMenuModel*> m_registry;
47+ QHash<QByteArray, QWeakPointer<UnityMenuModel>> m_registry;
48+ static UnityMenuModelCache* theCache;
4449};
4550
4651#endif // UNITYMENUMODELCACHE_H
qml/Greeter/Clock.qml+2−2
@@ -34,12 +34,12 @@ Item {
3434 }
3535 }
3636
37− CachedUnityMenuModel {
37+ SharedUnityMenuModel {
3838 id: timeModel
3939 objectName: "timeModel"
4040
4141 busName: "com.canonical.indicator.datetime"
42− actionsObjectPath: "/com/canonical/indicator/datetime"
42+ actions: { "indicator": "/com/canonical/indicator/datetime" }
4343 menuObjectPath: clock.visible ? "/com/canonical/indicator/datetime/phone" : ""
4444
4545 Indicators.RootActionState {
qml/Panel/Indicators/CachedUnityMenuModel.qmldeleted−39
@@ -1,39 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU Lesser General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors:
17− * Nick Dedekind <nick.dedekind@canonical.com>
18− */
19−
20−import QtQuick 2.0
21−import QMenuModel 0.1
22−import Unity.Indicators 0.1 as Indicators
23−
24−// Make sure we don't duplicate models.
25−Item {
26− id: cachedModel
27− property string busName
28− property string actionsObjectPath
29− property string menuObjectPath
30− readonly property bool ready: busName!=="" && actionsObjectPath!=="" && menuObjectPath!==""
31−
32− property var model: {
33− if (!ready) return null;
34−
35− return Indicators.UnityMenuModelCache.model(cachedModel.busName,
36− cachedModel.menuObjectPath,
37− { "indicator": cachedModel.actionsObjectPath });
38− }
39−}
qml/Panel/Indicators/IndicatorBase.qml+2−2
@@ -36,10 +36,10 @@ Item {
3636 property alias menuModel: cachedModel.model
3737 property alias rootActionState: rootAction
3838
39− CachedUnityMenuModel {
39+ SharedUnityMenuModel {
4040 id: cachedModel
4141 busName: indicatorItem.busName
42− actionsObjectPath: indicatorItem.actionsObjectPath
42+ actions: { "indicator": indicatorItem.actionsObjectPath }
4343 menuObjectPath: indicatorItem.deviceMenuObjectPath
4444 }
4545
tests/mocks/Unity/Indicators/CMakeLists.txt+1
@@ -14,6 +14,7 @@ set(IndicatorsFakeQml_SOURCES
1414 fakeplugin.cpp
1515 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/indicators.h
1616 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/menucontentactivator.cpp
17+ ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/sharedunitymenumodel.cpp
1718 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelcache.cpp
1819 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelstack.cpp
1920 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/visibleindicatorsmodel.cpp
tests/mocks/Unity/Indicators/fakeplugin.cpp+3−1
@@ -26,6 +26,7 @@
2626#include "fakeindicatorsmodel.h"
2727#include "indicators.h"
2828#include "menucontentactivator.h"
29+#include "sharedunitymenumodel.h"
2930#include "unitymenumodelcache.h"
3031#include "unitymenumodelstack.h"
3132#include "visibleindicatorsmodel.h"
@@ -33,7 +34,7 @@
3334static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
3435 Q_UNUSED(engine);
3536 Q_UNUSED(scriptEngine);
36− return new UnityMenuModelCache;
37+ return UnityMenuModelCache::singleton();
3738}
3839
3940void IndicatorsFakePlugin::registerTypes(const char * uri)
@@ -47,6 +48,7 @@ void IndicatorsFakePlugin::registerTypes(const char * uri)
4748 qmlRegisterType<MenuContentActivator>(uri, 0, 1, "MenuContentActivator");
4849 qmlRegisterType<UnityMenuModelStack>(uri, 0, 1, "UnityMenuModelStack");
4950 qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel");
51+ qmlRegisterType<SharedUnityMenuModel>(uri, 0, 1, "SharedUnityMenuModel");
5052
5153 qmlRegisterSingletonType<UnityMenuModelCache>(uri, 0, 1, "UnityMenuModelCache", menuModelCacheSingleton);
5254
tests/plugins/Unity/Indicators/CMakeLists.txt+1
@@ -40,3 +40,4 @@ indicator_test(indicatorsmodeltest ADDITIONAL_LIBS IndicatorsQml)
4040indicator_test(menucontentactivatortest ADDITIONAL_CPPS ${INDICATORS_DIR}/menucontentactivator.cpp)
4141indicator_test(unitymenumodelstacktest ADDITIONAL_CPPS ${TEST_DIR}/mocks/QMenuModel/unitymenumodel.cpp ${INDICATORS_DIR}/unitymenumodelstack.cpp)
4242indicator_test(rootactionstatetest ADDITIONAL_LIBS IndicatorsQml)
43+indicator_test(sharedunitymenumodeltest ADDITIONAL_LIBS IndicatorsQml)
tests/plugins/Unity/Indicators/sharedunitymenumodeltest.cppnew file+83
@@ -0,0 +1,83 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ */
17+
18+#include "sharedunitymenumodel.h"
19+#include "unitymenumodelcache.h"
20+
21+#include <QtTest>
22+#include <unitymenumodel.h>
23+
24+class SharedUnityMenuModelTest : public QObject
25+{
26+ Q_OBJECT
27+
28+ SharedUnityMenuModel* createFullModel(const QByteArray& testId)
29+ {
30+ SharedUnityMenuModel* model = new SharedUnityMenuModel;
31+ model->setBusName("com.canonical." + testId);
32+ model->setMenuObjectPath("/com/canonical/" + testId);
33+ QVariantMap actions;
34+ actions["test"] = QString("/com/canonical/%1/actions").arg(QString(testId));
35+ model->setActions(actions);
36+
37+// QVERIFY(model->model() != nullptr);
38+ return model;
39+ }
40+
41+private Q_SLOTS:
42+
43+ void testDifferentDataCreatesDifferentModels() {
44+ QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
45+ QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test2"));
46+
47+ QVERIFY(model1->model() != model2->model());
48+ }
49+
50+ void testSameDataCreatesSameModels() {
51+ QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
52+ QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test1"));
53+
54+ QCOMPARE(model1->model(), model2->model());
55+ }
56+
57+ void testSharedOwnership() {
58+ QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
59+ QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test1"));
60+
61+ QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), true);
62+ model1.clear();
63+ QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), true);
64+ model2.clear();
65+ QCOMPARE(UnityMenuModelCache::singleton()->contains("/com/canonical/test1"), false);
66+ }
67+
68+ // Tests that changing cached model data does not change the model path of others
69+ void testLP1328646() {
70+ QSharedPointer<SharedUnityMenuModel> model1(createFullModel("test1"));
71+ QSharedPointer<SharedUnityMenuModel> model2(createFullModel("test1"));
72+
73+ model2->setMenuObjectPath("/com/canonical/LP1328646");
74+
75+ QVERIFY(model1->model() != model2->model());
76+ QCOMPARE(model1->model()->menuObjectPath(), QByteArray("/com/canonical/test1"));
77+ QCOMPARE(model2->model()->menuObjectPath(), QByteArray("/com/canonical/LP1328646"));
78+ }
79+
80+};
81+
82+QTEST_GUILESS_MAIN(SharedUnityMenuModelTest)
83+#include "sharedunitymenumodeltest.moc"
tests/qmltests/CMakeLists.txt−1
@@ -78,7 +78,6 @@ add_qml_test(Panel Panel)
7878add_qml_test(Panel SearchIndicator)
7979add_qml_test(Panel/Indicators DefaultIndicatorWidget ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
8080add_qml_test(Panel/Indicators DefaultIndicatorPage ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
81−add_qml_test(Panel/Indicators CachedUnityMenuModel ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
8281# These MenuItemFactory tests need the test/mocks/ to come before plugins/
8382add_qml_test(Panel/Indicators MenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})
8483add_qml_test(Panel/Indicators MessageMenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})
tests/qmltests/Panel/Indicators/tst_CachedUnityMenuModel.qmldeleted−137
@@ -1,137 +0,0 @@
1−/*
2− * Copyright 2014 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0
18−import QtTest 1.0
19−import Unity.Test 0.1 as UT
20−import QMenuModel 0.1
21−import Unity.Indicators 0.1 as Indicators
22−import "../../../../qml/Panel/Indicators"
23−
24−Item {
25− id: root
26− width: units.gu(40)
27− height: units.gu(70)
28−
29− Component {
30− id: model
31− CachedUnityMenuModel {}
32− }
33−
34− UT.UnityTestCase {
35− name: "CachedUnityMenuModel"
36− when: windowShown
37−
38− function cleanup() {
39− doGC();
40− }
41−
42− function doGC() {
43− // need to put some wait cycles here to get gc going properly.
44− wait(10);
45− gc();
46− wait(10);
47− }
48−
49− function test_createDifferent() {
50− var cachedObject = model.createObject(null,
51− {
52− "busName": "com.canonical.test1",
53− "menuObjectPath": "/com/canonical/test1",
54− "actionsObjectPath": "/com/canonical/test1"
55− });
56−
57− var cachedObject2 = model.createObject(null,
58− {
59− "busName": "com.canonical.test2",
60− "menuObjectPath": "/com/canonical/test2",
61− "actionsObjectPath": "/com/canonical/test2"
62− });
63−
64− verify(cachedObject.model !== cachedObject2.model);
65− }
66−
67− function test_createSame() {
68− var cachedObject = model.createObject(null,
69− {
70− "busName": "com.canonical.test3",
71− "menuObjectPath": "/com/canonical/test3",
72− "actionsObjectPath": "/com/canonical/test3"
73− });
74−
75− var cachedObject2 = model.createObject(null,
76− {
77− "busName": "com.canonical.test3",
78− "menuObjectPath": "/com/canonical/test3",
79− "actionsObjectPath": "/com/canonical/test3"
80− });
81−
82− verify(cachedObject.model === cachedObject2.model);
83− }
84−
85− // Tests that changing cached model data does not change the model path of others
86− function test_lp1328646() {
87− var cachedObject = model.createObject(null,
88− {
89− "busName": "com.canonical.test4",
90− "menuObjectPath": "/com/canonical/test4",
91− "actionsObjectPath": "/com/canonical/test4"
92− });
93−
94− var cachedObject2 = model.createObject(null,
95− {
96− "busName": "com.canonical.test4",
97− "menuObjectPath": "/com/canonical/test4",
98− "actionsObjectPath": "/com/canonical/test4"
99− });
100−
101− cachedObject.menuObjectPath = "/com/canonical/test5";
102− compare(cachedObject.model.menuObjectPath, "/com/canonical/test5");
103− compare(cachedObject2.model.menuObjectPath, "/com/canonical/test4");
104−
105− verify(cachedObject.model !== cachedObject2.model);
106− }
107−
108− function createAndDestroy(test) {
109− var cachedObject = model.createObject(null,
110− {
111− "busName": "com.canonical."+test,
112− "menuObjectPath": "/com/canonical/"+test,
113− "actionsObjectPath": "/com/canonical/"+test
114− });
115− var cachedObject2 = model.createObject(null,
116− {
117− "busName": "com.canonical."+test,
118− "menuObjectPath": "/com/canonical/"+test,
119− "actionsObjectPath": "/com/canonical/"+test
120− });
121− cachedObject.destroy();
122− return cachedObject2;
123− }
124−
125− function test_destroyAllDeletesModel() {
126− createAndDestroy("test6");
127− doGC();
128− compare(Indicators.UnityMenuModelCache.contains("/com/canonical/test6"), false);
129− }
130−
131− function test_destroyPartialKeepsModel() {
132− var model = createAndDestroy("test7");
133− doGC();
134− compare(Indicators.UnityMenuModelCache.contains("/com/canonical/test7"), true);
135− }
136− }
137−}