on xenial help sign in
better mocking
commit682562d543a3f4a3e4c907c4c21f1f3157e51ffa authorNick Dedekind <nick.dedekind@canonical.com> dateTue 7 Oct 2014, 08:58 (12 years ago) parent2cc60b0
34 files changed+397−586
plugins/Unity/Indicators/plugin.cpp+1−1 plugins/Unity/Indicators/plugin.h+1−1 plugins/Unity/Indicators/unitymenumodelcache.cpp−1 plugins/Unity/Indicators/unitymenumodelcache.h+3−3 qml/Greeter/Clock.qml+1−1 tests/mocks/QMenuModel/unitymenumodel.cpp+1−2 tests/mocks/QMenuModel/unitymenumodel.h+6−2 tests/mocks/Unity/Indicators/CMakeLists.txt+2−10 tests/mocks/Unity/Indicators/FakeMenuPage.qml−27 tests/mocks/Unity/Indicators/IndicatorsModel.qml+143−35 tests/mocks/Unity/Indicators/RootActionState.qml+17−9 tests/mocks/Unity/Indicators/fakeindicatorsmodel.cpp+50−19 tests/mocks/Unity/Indicators/fakeindicatorsmodel.h+8−2 tests/mocks/Unity/Indicators/fakeplugin.cpp+3−4 tests/mocks/Unity/Indicators/indicators_fake.qrc−14 tests/mocks/Unity/Indicators/qml/fake_menu_page1.qml−35 tests/mocks/Unity/Indicators/qml/fake_menu_page2.qml−35 tests/mocks/Unity/Indicators/qml/fake_menu_page3.qml−35 tests/mocks/Unity/Indicators/qml/fake_menu_page4.qml−35 tests/mocks/Unity/Indicators/qml/fake_menu_page5.qml−35 tests/mocks/Unity/Indicators/qml/fake_menu_widget1.qml−23 tests/mocks/Unity/Indicators/qml/fake_menu_widget2.qml−23 tests/mocks/Unity/Indicators/qml/fake_menu_widget3.qml−23 tests/mocks/Unity/Indicators/qml/fake_menu_widget4.qml−23 tests/mocks/Unity/Indicators/qml/fake_menu_widget5.qml−23 tests/mocks/Unity/Indicators/qmldir−1 tests/qmltests/CMakeLists.txt+6−6 tests/qmltests/Greeter/tst_Clock.qml+51−34 tests/qmltests/Panel/Indicators/tst_DefaultIndicatorPage.qml+77−80 tests/qmltests/Panel/Indicators/tst_DefaultIndicatorWidget.qml−8 tests/qmltests/Panel/tst_IndicatorItem.qml+1−1 tests/qmltests/Panel/tst_IndicatorRow.qml+17−19 tests/qmltests/Panel/tst_Indicators.qml+9−8 tests/qmltests/Panel/tst_MenuContent.qml−8
plugins/Unity/Indicators/plugin.cpp+1−1
@@ -43,7 +43,7 @@ static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEng
4343 return UnityMenuModelCache::singleton();
4444}
4545
46−void Indicators2Plugin::registerTypes(const char *uri)
46+void IndicatorsPlugin::registerTypes(const char *uri)
4747{
4848 qRegisterMetaType<UnityMenuModel*>("UnityMenuModel*");
4949
plugins/Unity/Indicators/plugin.h+1−1
@@ -22,7 +22,7 @@
2222
2323#include <QtQml/QQmlExtensionPlugin>
2424
25−class Indicators2Plugin : public QQmlExtensionPlugin
25+class IndicatorsPlugin : public QQmlExtensionPlugin
2626{
2727 Q_OBJECT
2828 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
plugins/Unity/Indicators/unitymenumodelcache.cpp−1
@@ -24,7 +24,6 @@
2424
2525UnityMenuModelCache* UnityMenuModelCache::theCache = nullptr;
2626
27−
2827UnityMenuModelCache* UnityMenuModelCache::singleton()
2928{
3029 if (!theCache) {
plugins/Unity/Indicators/unitymenumodelcache.h+3−3
@@ -36,14 +36,14 @@ public:
3636
3737 static UnityMenuModelCache* singleton();
3838
39− QSharedPointer<UnityMenuModel> model(const QByteArray& bus,
39+ virtual QSharedPointer<UnityMenuModel> model(const QByteArray& bus,
4040 const QByteArray& path,
4141 const QVariantMap& actions);
4242
4343 // for tests use
44− Q_INVOKABLE bool contains(const QByteArray& path);
44+ Q_INVOKABLE virtual bool contains(const QByteArray& path);
4545
46−private:
46+protected:
4747 QHash<QByteArray, QWeakPointer<UnityMenuModel>> m_registry;
4848 static UnityMenuModelCache* theCache;
4949};
qml/Greeter/Clock.qml+1−1
@@ -47,7 +47,7 @@ Item {
4747 menu: timeModel.model
4848 onUpdated: {
4949 if (timeLabel.text != rightLabel) {
50− timeLabel.text = rightLabel;
50+ if (rightLabel != "") timeLabel.text = rightLabel;
5151 clock.currentDate = new Date();
5252 }
5353 }
tests/mocks/QMenuModel/unitymenumodel.cpp+1−2
@@ -50,13 +50,12 @@ void UnityMenuModel::setModelData(const QVariant& data)
5050{
5151 beginResetModel();
5252
53− m_modelData.clear();
5453 m_modelData = data.toList();
54+ Q_EMIT modelDataChanged();
5555
5656 endResetModel();
5757}
5858
59−
6059void UnityMenuModel::insertRow(int row, const QVariant& data)
6160{
6261 row = qMin(row, rowCount());
tests/mocks/QMenuModel/unitymenumodel.h+6−2
@@ -27,13 +27,15 @@ class ActionStateParser;
2727class Q_DECL_EXPORT UnityMenuModel : public QAbstractListModel
2828{
2929 Q_OBJECT
30− Q_PROPERTY(QVariant modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
3130 Q_PROPERTY(QByteArray busName READ busName WRITE setBusName NOTIFY busNameChanged)
3231 Q_PROPERTY(QVariantMap actions READ actions WRITE setActions NOTIFY actionsChanged)
3332 Q_PROPERTY(QByteArray menuObjectPath READ menuObjectPath WRITE setMenuObjectPath NOTIFY menuObjectPathChanged)
3433 Q_PROPERTY(ActionStateParser* actionStateParser READ actionStateParser WRITE setActionStateParser NOTIFY actionStateParserChanged)
3534 Q_PROPERTY(QString nameOwner READ nameOwner NOTIFY nameOwnerChanged)
3635
36+ // internal mock properties
37+ Q_PROPERTY(QVariant modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
38+
3739public:
3840 UnityMenuModel(QObject *parent = nullptr);
3941 virtual ~UnityMenuModel();
@@ -81,9 +83,11 @@ Q_SIGNALS:
8183 void actionsChanged();
8284 void menuObjectPathChanged();
8385 void actionStateParserChanged();
84− void modelDataChanged();
8586 void nameOwnerChanged();
8687
88+ // Internal mock usage
89+ void modelDataChanged();
90+
8791private:
8892 QVariantMap rowData(int row) const;
8993 QVariant subMenuData(int row) const;
tests/mocks/Unity/Indicators/CMakeLists.txt+2−10
@@ -12,25 +12,17 @@ include_directories(
1212
1313set(IndicatorsFakeQml_SOURCES
1414 fakeplugin.cpp
15+ fakeindicatorsmodel.cpp
16+ fakeunitymenumodelcache.cpp
1517 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/indicators.h
1618 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/menucontentactivator.cpp
1719 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/sharedunitymenumodel.cpp
1820 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelcache.cpp
1921 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelstack.cpp
2022 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/visibleindicatorsmodel.cpp
21− fakeindicatorsmodel.cpp
22−)
23−
24−set(IndicatorsFakeQml_RESOURCES
25− indicators_fake.qrc
26−)
27−
28−qt5_add_resources(IndicatorsFakeQml_RESOURCES_RCC
29− ${IndicatorsFakeQml_RESOURCES}
3023)
3124
3225add_library(IndicatorsFakeQml SHARED
33− ${IndicatorsFakeQml_RESOURCES_RCC}
3426 ${IndicatorsFakeQml_SOURCES}
3527)
3628add_definitions(-DUNITYINDICATORS_LIBRARY)
tests/mocks/Unity/Indicators/FakeMenuPage.qmldeleted−27
@@ -1,27 +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 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−
19−Flickable {
20− objectName: "fakeMenuPlugin"
21− // Make it compatible with the PluginItem interface
22− function reset() {
23− if (shell != undefined && shell.indicator_status != undefined) {
24− shell.indicator_status[objectName].reset++;
25− }
26− }
27−}
tests/mocks/Unity/Indicators/IndicatorsModel.qml+143−35
@@ -18,43 +18,151 @@ import QtQuick 2.0
1818import Unity.Indicators 0.1 as Indicators
1919
2020Indicators.FakeIndicatorsModel {
21+ id: root
22+
23+ Component.onCompleted: {
24+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake1",
25+ "/com/canonical/indicators/fake1",
26+ "/com/canonical/indicators/fake1",
27+ getUnityMenuModelData("fake-indicator-bluetooth",
28+ "Bluetooth (F)",
29+ "",
30+ [ "image://theme/bluetooth-active" ]));
31+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake2",
32+ "/com/canonical/indicators/fake2",
33+ "/com/canonical/indicators/fake2",
34+ getUnityMenuModelData("fake-indicator-network",
35+ "Network (F)",
36+ "",
37+ [ "image://theme/simcard-error", "image://theme/wifi-high" ]));
38+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake3",
39+ "/com/canonical/indicators/fake3",
40+ "/com/canonical/indicators/fake3",
41+ getUnityMenuModelData("fake-indicator-sound",
42+ "Messages (F)",
43+ "",
44+ [ "image://theme/messages-new" ]));
45+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake4",
46+ "/com/canonical/indicators/fake4",
47+ "/com/canonical/indicators/fake4",
48+ getUnityMenuModelData("fake-indicator-power",
49+ "Sound (F)",
50+ "",
51+ [ "image://theme/audio-volume-high" ]));
52+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake5",
53+ "/com/canonical/indicators/fake5",
54+ "/com/canonical/indicators/fake5",
55+ getUnityMenuModelData("fake-indicator-power",
56+ "Battery (F)",
57+ "",
58+ [ "image://theme/battery-020" ]));
59+ }
60+
61+ function getUnityMenuModelData(identifier, title, label, icons) {
62+ var root = [{
63+ "rowData": { // 1
64+ "label": "",
65+ "sensitive": true,
66+ "isSeparator": false,
67+ "icon": "",
68+ "type": "com.canonical.indicator.root",
69+ "ext": {},
70+ "action": "",
71+ "actionState": {
72+ "title": title,
73+ "label": label,
74+ "icons": icons
75+ },
76+ "isCheck": false,
77+ "isRadio": false,
78+ "isToggled": false,
79+ },
80+ "submenu": []
81+ }];
82+
83+ var submenus = [];
84+ for (var i = 0; i < 8; i++) {
85+ var submenu = {
86+ "rowData": { // 1.1
87+ "label": identifier,
88+ "sensitive": true,
89+ "isSeparator": false,
90+ "icon": "",
91+ "type": undefined,
92+ "ext": {},
93+ "action": "",
94+ "actionState": {},
95+ "isCheck": false,
96+ "isRadio": false,
97+ "isToggled": false,
98+ }};
99+ submenus.push(submenu);
100+ }
101+ root[0]["submenu"] = submenus;
102+
103+ return root;
104+ }
105+
106+ property var originalModelData: [
107+ {
108+ "identifier": "fake-indicator-1",
109+ "widgetSource": "Indicators/DefaultIndicatorWidget.qml",
110+ "pageSource": "Indicators/DefaultIndicatorPage.qml",
111+ "indicatorProperties": {
112+ "enabled": true,
113+ "busName": "com.canonical.indicators.fake1",
114+ "menuObjectPath": "/com/canonical/indicators/fake1",
115+ "actionsObjectPath": "/com/canonical/indicators/fake1"
116+ }
117+ },
118+ {
119+ "identifier": "fake-indicator-2",
120+ "widgetSource": "Indicators/DefaultIndicatorWidget.qml",
121+ "pageSource": "Indicators/DefaultIndicatorPage.qml",
122+ "indicatorProperties": {
123+ "enabled": true,
124+ "busName": "com.canonical.indicators.fake2",
125+ "menuObjectPath": "/com/canonical/indicators/fake2",
126+ "actionsObjectPath": "/com/canonical/indicators/fake2"
127+ }
128+ },
129+ {
130+ "identifier": "fake-indicator-3",
131+ "widgetSource": "Indicators/DefaultIndicatorWidget.qml",
132+ "pageSource": "Indicators/DefaultIndicatorPage.qml",
133+ "indicatorProperties": {
134+ "enabled": true,
135+ "busName": "com.canonical.indicators.fake3",
136+ "menuObjectPath": "/com/canonical/indicators/fake3",
137+ "actionsObjectPath": "/com/canonical/indicators/fake3"
138+ }
139+ },
140+ {
141+ "identifier": "fake-indicator-4",
142+ "widgetSource": "Indicators/DefaultIndicatorWidget.qml",
143+ "pageSource": "Indicators/DefaultIndicatorPage.qml",
144+ "indicatorProperties": {
145+ "enabled": true,
146+ "busName": "com.canonical.indicators.fake4",
147+ "menuObjectPath": "/com/canonical/indicators/fake4",
148+ "actionsObjectPath": "/com/canonical/indicators/fake4"
149+ }
150+ },
151+ {
152+ "identifier": "fake-indicator-5",
153+ "widgetSource": "Indicators/DefaultIndicatorWidget.qml",
154+ "pageSource": "Indicators/DefaultIndicatorPage.qml",
155+ "indicatorProperties": {
156+ "enabled": true,
157+ "busName": "com.canonical.indicators.fake5",
158+ "menuObjectPath": "/com/canonical/indicators/fake5",
159+ "actionsObjectPath": "/com/canonical/indicators/fake5"
160+ }
161+ }
162+ ]
21163
22164 function load(profile) {
23165 unload();
24−
25− append({ "identifier": "indicator-fake1",
26− "position": 0,
27− "widgetSource": "qrc:/tests/indciators/qml/fake_menu_widget1.qml",
28− "pageSource": "qrc:/tests/indciators/qml/fake_menu_page1.qml",
29− "indicatorProperties": { enabled: true }
30− });
31−
32− append({ "identifier": "indicator-fake2",
33− "position": 1,
34− "widgetSource": "qrc:/tests/indciators/qml/fake_menu_widget2.qml",
35− "pageSource": "qrc:/tests/indciators/qml/fake_menu_page2.qml",
36− "indicatorProperties": { enabled: true }
37− });
38−
39− append({ "identifier": "indicator-fake3",
40− "position": 2,
41− "widgetSource": "qrc:/tests/indciators/qml/fake_menu_widget3.qml",
42− "pageSource": "qrc:/tests/indciators/qml/fake_menu_page3.qml",
43− "indicatorProperties": { enabled: true }
44− });
45−
46− append({ "identifier": "indicator-fake4",
47− "position": 3,
48− "widgetSource": "qrc:/tests/indciators/qml/fake_menu_widget4.qml",
49− "pageSource": "qrc:/tests/indciators/qml/fake_menu_page4.qml",
50− "indicatorProperties": { enabled: true }
51− });
52−
53− append({ "identifier": "indicator-fake5",
54− "position": 4,
55− "widgetSource": "qrc:/tests/indciators/qml/fake_menu_widget5.qml",
56− "pageSource": "qrc:/tests/indciators/qml/fake_menu_page5.qml",
57− "indicatorProperties": { enabled: true }
58− });
166+ root.modelData = originalModelData;
59167 }
60168}
tests/mocks/Unity/Indicators/RootActionState.qml+17−9
@@ -19,15 +19,23 @@
1919
2020import QtQuick 2.0
2121
22−QtObject {
23− property var menu
24− property bool valid: false
25− property string title
26− property string leftLabel
27− property string rightLabel
28− property var icons
29− property string accessibleName
30− property bool visible: true
22+Item {
23+ property var menu: null
24+ property bool valid: cachedState !== undefined
25+ property string title: cachedState && cachedState.hasOwnProperty("title") ? cachedState["title"] : ""
26+ property string leftLabel: cachedState && cachedState.hasOwnProperty("pre-label") ? cachedState["pre-label"] : ""
27+ property string rightLabel: cachedState && cachedState.hasOwnProperty("label") ? cachedState["label"] : ""
28+ property var icons: cachedState && cachedState.hasOwnProperty("icons") ? cachedState["icons"] : []
29+ property string accessibleName: cachedState && cachedState.hasOwnProperty("accessible-desc") ? cachedState["accessible-desc"] : ""
30+ visible: cachedState && cachedState.hasOwnProperty("visible") ? cachedState["visible"] : true
31+
32+ property var cachedState: menu ? menu.get(0, "actionState") : undefined
33+ Connections {
34+ target: menu
35+ onModelDataChanged: {
36+ cachedState = menu.get(0, "actionState");
37+ }
38+ }
3139
3240 signal updated
3341
tests/mocks/Unity/Indicators/fakeindicatorsmodel.cpp+50−19
@@ -31,7 +31,6 @@ FakeIndicatorsModel::FakeIndicatorsModel(QObject *parent)
3131/*! \internal */
3232FakeIndicatorsModel::~FakeIndicatorsModel()
3333{
34− qDeleteAll(m_indicators);
3534}
3635
3736int FakeIndicatorsModel::count() const
@@ -47,31 +46,63 @@ void FakeIndicatorsModel::unload()
4746{
4847 beginResetModel();
4948
50− qDeleteAll(m_indicators);
51− m_indicators.clear();
49+ m_modelData.clear();
50+ Q_EMIT modelDataChanged();
5251
5352 endResetModel();
5453}
5554
5655
57−void FakeIndicatorsModel::append(const QVariantMap& row)
56+void FakeIndicatorsModel::append(const QVariantMap& data)
5857{
59− Indicator* new_row = new QHash<int, QVariant>();
60− for (auto iter = row.begin(); iter != row.end(); ++iter )
61− {
62− int key = roleNames().key(iter.key().toUtf8(), -1);
63− if (key != -1) {
64− new_row->insert(key, iter.value());
65− }
66− }
58+ QList<QVariant> allData = m_modelData.toList();
59+ beginInsertRows(QModelIndex(), allData.count(), allData.count());
60+
61+ allData.append(data);
62+ m_modelData = allData;
63+ Q_EMIT modelDataChanged();
6764
68− beginInsertRows(QModelIndex(), m_indicators.count(), m_indicators.count());
65+ endInsertRows();
66+}
6967
70− m_indicators.append(new_row);
68+void FakeIndicatorsModel::insert(int row, const QVariantMap& data)
69+{
70+ QList<QVariant> allData = m_modelData.toList();
71+ row = qMax(0, qMin(row, allData.count()));
72+
73+ beginInsertRows(QModelIndex(), row, row);
74+
75+ allData.insert(row, data);
76+ m_modelData = allData;
77+ Q_EMIT modelDataChanged();
7178
7279 endInsertRows();
7380}
7481
82+void FakeIndicatorsModel::remove(int row)
83+{
84+ QList<QVariant> allData = m_modelData.toList();
85+ row = qMax(0, qMin(row, allData.count()));
86+
87+ beginRemoveRows(QModelIndex(), row, row);
88+
89+ allData.removeAt(row);
90+ m_modelData = allData;
91+ Q_EMIT modelDataChanged();
92+
93+ endRemoveRows();
94+}
95+
96+void FakeIndicatorsModel::setModelData(const QVariant& modelData)
97+{
98+ beginResetModel();
99+
100+ m_modelData = modelData;
101+ Q_EMIT modelDataChanged();
102+
103+ endResetModel();
104+}
105+
75106QHash<int, QByteArray> FakeIndicatorsModel::roleNames() const
76107{
77108 static QHash<int, QByteArray> roles;
@@ -91,18 +122,18 @@ int FakeIndicatorsModel::columnCount(const QModelIndex &) const
91122 return 1;
92123}
93124
94−Q_INVOKABLE QVariant FakeIndicatorsModel::data(int row, int role) const
125+QVariant FakeIndicatorsModel::data(int row, int role) const
95126{
96127 return data(index(row, 0), role);
97128}
98129
99130QVariant FakeIndicatorsModel::data(const QModelIndex &index, int role) const
100131{
101− if (!index.isValid() || index.row() >= m_indicators.size())
132+ QList<QVariant> dataList = m_modelData.toList();
133+ if (!index.isValid() || index.row() >= dataList.size())
102134 return QVariant();
103135
104− Indicator* indicator = m_indicators[index.row()];
105− return indicator->value(role, QVariant());
136+ return dataList[index.row()].toMap()[roleNames()[role]];
106137}
107138
108139QModelIndex FakeIndicatorsModel::parent(const QModelIndex&) const
@@ -112,5 +143,5 @@ QModelIndex FakeIndicatorsModel::parent(const QModelIndex&) const
112143
113144int FakeIndicatorsModel::rowCount(const QModelIndex&) const
114145{
115− return m_indicators.count();
146+ return m_modelData.toList().count();
116147}
tests/mocks/Unity/Indicators/fakeindicatorsmodel.h+8−2
@@ -27,6 +27,7 @@ class FakeIndicatorsModel : public QAbstractListModel
2727 Q_OBJECT
2828 Q_ENUMS(Roles)
2929 Q_PROPERTY(int count READ count NOTIFY countChanged)
30+ Q_PROPERTY(QVariant modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
3031public:
3132
3233 FakeIndicatorsModel(QObject *parent=0);
@@ -36,9 +37,14 @@ public:
3637 Q_INVOKABLE void unload();
3738
3839 Q_INVOKABLE void append(const QVariantMap& row);
40+ Q_INVOKABLE void insert(int row, const QVariantMap& data);
41+ Q_INVOKABLE void remove(int row);
3942
4043 Q_INVOKABLE QVariant data(int row, int role) const;
4144
45+ void setModelData(const QVariant& data);
46+ QVariant modelData() const { return m_modelData; }
47+
4248 /* QAbstractItemModel */
4349 QHash<int, QByteArray> roleNames() const;
4450 int columnCount(const QModelIndex &parent = QModelIndex()) const;
@@ -48,12 +54,12 @@ public:
4854
4955Q_SIGNALS:
5056 void countChanged();
57+ void modelDataChanged();
5158
5259private:
5360 int count() const;
5461
55− typedef QHash<int, QVariant> Indicator;
56− QList<Indicator*> m_indicators;
62+ QVariant m_modelData;
5763};
5864
5965#endif // FAKE_INDICATORSMODEL_H
tests/mocks/Unity/Indicators/fakeplugin.cpp+3−4
@@ -27,7 +27,7 @@
2727#include "indicators.h"
2828#include "menucontentactivator.h"
2929#include "sharedunitymenumodel.h"
30−#include "unitymenumodelcache.h"
30+#include "fakeunitymenumodelcache.h"
3131#include "unitymenumodelstack.h"
3232#include "visibleindicatorsmodel.h"
3333
@@ -36,12 +36,11 @@
3636static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
3737 Q_UNUSED(engine);
3838 Q_UNUSED(scriptEngine);
39− return UnityMenuModelCache::singleton();
39+ return FakeUnityMenuModelCache::singleton();
4040}
4141
4242void IndicatorsFakePlugin::registerTypes(const char * uri)
4343{
44− Q_INIT_RESOURCE(indicators_fake);
4544 qRegisterMetaType<UnityMenuModel*>("UnityMenuModel*");
4645
4746 // internal
@@ -53,7 +52,7 @@ void IndicatorsFakePlugin::registerTypes(const char * uri)
5352 qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel");
5453 qmlRegisterType<SharedUnityMenuModel>(uri, 0, 1, "SharedUnityMenuModel");
5554
56− qmlRegisterSingletonType<UnityMenuModelCache>(uri, 0, 1, "UnityMenuModelCache", menuModelCacheSingleton);
55+ qmlRegisterSingletonType<FakeUnityMenuModelCache>(uri, 0, 1, "UnityMenuModelCache", menuModelCacheSingleton);
5756
5857 // external uncreatables
5958 qmlRegisterUncreatableType<MenuContentState>(uri, 0, 1, "MenuContentState", "Can't create MenuContentState class");
tests/mocks/Unity/Indicators/indicators_fake.qrcdeleted−14
@@ -1,14 +0,0 @@
1−<RCC>
2− <qresource prefix="/tests/indciators">
3− <file>qml/fake_menu_widget1.qml</file>
4− <file>qml/fake_menu_widget2.qml</file>
5− <file>qml/fake_menu_widget3.qml</file>
6− <file>qml/fake_menu_widget4.qml</file>
7− <file>qml/fake_menu_widget5.qml</file>
8− <file>qml/fake_menu_page1.qml</file>
9− <file>qml/fake_menu_page2.qml</file>
10− <file>qml/fake_menu_page3.qml</file>
11− <file>qml/fake_menu_page4.qml</file>
12− <file>qml/fake_menu_page5.qml</file>
13− </qresource>
14−</RCC>
tests/mocks/Unity/Indicators/qml/fake_menu_page1.qmldeleted−35
@@ -1,35 +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 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 Unity.Indicators 0.1 as Indicators
19−
20−Indicators.FakeMenuPage {
21− id: menu_plugin1
22−
23− Rectangle {
24− id: contents
25− color: "red"
26−
27− height: 150
28− width: 150
29−
30− anchors {
31− horizontalCenter: parent.horizontalCenter
32− verticalCenter: parent.verticalCenter
33− }
34− }
35−}
tests/mocks/Unity/Indicators/qml/fake_menu_page2.qmldeleted−35
@@ -1,35 +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 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 Unity.Indicators 0.1 as Indicators
19−
20−Indicators.FakeMenuPage {
21− id: menu_plugin2
22−
23− Rectangle {
24− id: contents
25− color: "blue"
26−
27− height: 150
28− width: 150
29−
30− anchors {
31− horizontalCenter: parent.horizontalCenter
32− verticalCenter: parent.verticalCenter
33− }
34− }
35−}
tests/mocks/Unity/Indicators/qml/fake_menu_page3.qmldeleted−35
@@ -1,35 +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 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 Unity.Indicators 0.1 as Indicators
19−
20−Indicators.FakeMenuPage {
21− id: menu_plugin3
22−
23− Rectangle {
24− id: contents
25− color: "yellow"
26−
27− height: 150
28− width: 150
29−
30− anchors {
31− horizontalCenter: parent.horizontalCenter
32− verticalCenter: parent.verticalCenter
33− }
34− }
35−}
tests/mocks/Unity/Indicators/qml/fake_menu_page4.qmldeleted−35
@@ -1,35 +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 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 Unity.Indicators 0.1 as Indicators
19−
20−Indicators.FakeMenuPage {
21− id: menu_plugin4
22−
23− Rectangle {
24− id: contents
25− color: "green"
26−
27− height: 150
28− width: 150
29−
30− anchors {
31− horizontalCenter: parent.horizontalCenter
32− verticalCenter: parent.verticalCenter
33− }
34− }
35−}
tests/mocks/Unity/Indicators/qml/fake_menu_page5.qmldeleted−35
@@ -1,35 +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 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 Unity.Indicators 0.1 as Indicators
19−
20−Indicators.FakeMenuPage {
21− id: menu_plugin5
22−
23− Rectangle {
24− id: contents
25− color: "orange"
26−
27− height: 150
28− width: 150
29−
30− anchors {
31− horizontalCenter: parent.horizontalCenter
32− verticalCenter: parent.verticalCenter
33− }
34− }
35−}
tests/mocks/Unity/Indicators/qml/fake_menu_widget1.qmldeleted−23
@@ -1,23 +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 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−
19−Rectangle {
20− width: 40
21− height: 40
22− color : "red"
23−}
tests/mocks/Unity/Indicators/qml/fake_menu_widget2.qmldeleted−23
@@ -1,23 +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 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−
19−Rectangle {
20− width: 40
21− height: 40
22− color : "blue"
23−}
tests/mocks/Unity/Indicators/qml/fake_menu_widget3.qmldeleted−23
@@ -1,23 +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 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−
19−Rectangle {
20− width: 40
21− height: 40
22− color : "yellow"
23−}
tests/mocks/Unity/Indicators/qml/fake_menu_widget4.qmldeleted−23
@@ -1,23 +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 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−
19−Rectangle {
20− width: 40
21− height: 40
22− color : "green"
23−}
tests/mocks/Unity/Indicators/qml/fake_menu_widget5.qmldeleted−23
@@ -1,23 +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 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−
19−Rectangle {
20− width: 40
21− height: 40
22− color : "orange"
23−}
tests/mocks/Unity/Indicators/qmldir−1
@@ -3,5 +3,4 @@ plugin IndicatorsFakeQml
33typeinfo Indicators.qmltypes
44
55IndicatorsModel 0.1 IndicatorsModel.qml
6−FakeMenuPage 0.1 FakeMenuPage.qml
76RootActionState 0.1 RootActionState.qml
tests/qmltests/CMakeLists.txt+6−6
@@ -19,8 +19,8 @@ set(qmltest_DEFAULT_TARGETS qmluitests)
1919set(qmltest_DEFAULT_NO_ADD_TEST TRUE)
2020set(qmltest_DEFAULT_PROPERTIES ENVIRONMENT "LC_ALL=C")
2121
22−add_qml_test(. Shell ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
23−add_qml_test(. ShellWithPin ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single-pin")
22+add_qml_test(. Shell ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single:${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
23+add_qml_test(. ShellWithPin ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single-pin:${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
2424add_qml_test(Components Background)
2525add_qml_test(Components Carousel)
2626add_qml_test(Components DraggingArea)
@@ -71,10 +71,10 @@ add_qml_test(Launcher Launcher)
7171add_qml_test(Notifications Notifications)
7272add_qml_test(Notifications VisualSnapDecisionsQueue)
7373add_qml_test(Panel ActiveCallHint)
74−add_qml_test(Panel IndicatorRow)
75−add_qml_test(Panel Indicators)
76−add_qml_test(Panel MenuContent)
77−add_qml_test(Panel Panel)
74+add_qml_test(Panel IndicatorRow ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
75+add_qml_test(Panel Indicators ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
76+add_qml_test(Panel MenuContent ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
77+add_qml_test(Panel Panel ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
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")
tests/qmltests/Greeter/tst_Clock.qml+51−34
@@ -19,7 +19,7 @@ import QtTest 1.0
1919import ".."
2020import "../../../qml/Greeter"
2121import Ubuntu.Components 0.1
22−import QMenuModel 0.1
22+import Unity.Indicators 0.1 as Indicators
2323import Unity.Test 0.1 as UT
2424
2525Rectangle {
@@ -36,56 +36,73 @@ Rectangle {
3636 }
3737 }
3838
39− UnityMenuModel {
40− id: menuModel
41− modelData: [{
42− "rowData": {
43− "actionState": { "label": Qt.formatTime(new Date("October 13, 1975 11:13:00")) }
44− }
45− }]
39+ function updateDatetimeModelTime(label) {
40+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicator.datetime",
41+ "/com/canonical/indicator/datetime/phone",
42+ "/com/canonical/indicator/datetime",
43+ [{
44+ "rowData": {
45+ "actionState": { "label": label }
46+ }
47+ }]);
4648 }
4749
4850 UT.UnityTestCase {
4951 name: "Clock"
52+ when: windowShown
5053
5154 function init() {
52− var cachedModel = findChild(clock, "timeModel");
53− verify(cachedModel !== undefined);
54− cachedModel.model = menuModel;
55+ updateDatetimeModelTime(Qt.formatTime(new Date("October 13, 1975 12:14:00")));
56+ clock.visible = true;
5557 }
5658
57− function test_customDate() {
58− var dateObj = new Date("October 13, 1975 11:13:00")
59− var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
60− var timeString = Qt.formatTime(dateObj)
59+ // Test that the date portion of the clock updates with custom value.
60+ // Time portion is controlled by indicators
61+ function test_updateDate() {
62+ var dateLabel = findChild(clock, "dateLabel");
63+ var timeLabel = findChild(clock, "timeLabel");
6164
62− clock.currentDate = dateObj
63− var dateLabel = findChild(clock, "dateLabel")
64− compare(dateLabel.text, dateString, "Not the expected date")
65− var timeLabel = findChild(clock, "timeLabel")
66− compare(timeLabel.text, timeString, "Not the expected time")
65+ var timeString = Qt.formatTime(new Date("October 13, 1975 12:14:00"));
66+
67+ // initial date.
68+ var dateObj = new Date("October 13, 1975 11:13:00");
69+ var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate);
70+ clock.currentDate = dateObj;
71+
72+ compare(dateLabel.text, dateString, "Not the expected date");
73+ compare(timeLabel.text, timeString, "Time should come from indicators");
74+
75+ // update date.
76+ var dateObj2 = new Date("October 14, 1976 13:15:00");
77+ var dateString2 = Qt.formatDate(dateObj2, Qt.DefaultLocaleLongDate);
78+ clock.currentDate = dateObj2;
79+
80+ compare(dateLabel.text, dateString2, "Not the expected date");
81+ compare(timeLabel.text,timeString, "Time should come from indicators");
6782 }
6883
69− function test_dateUpdate() {
70− var dateObj = new Date("October 13, 1975 11:13:00")
71− var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
72− var timeString = Qt.formatTime(dateObj)
84+ // Test that the date portion of the clock updates with custom value.
85+ // Time portion is controlled by indicators
86+ function test_updateTime() {
87+ var timeLabel = findChild(clock, "timeLabel");
7388
74− clock.visible = false
75− var timeModel = findInvisibleChild(clock, "timeModel")
89+ var timeString1 = Qt.formatTime(new Date("October 13, 1975 11:15:00"));
90+ var timeString2 = Qt.formatTime(new Date("October 14, 1976 12:16:00"));
7691
77− compare(timeModel.menuObjectPath, "", "Clock shouldn't be connected to Indicators when not visible.")
92+ updateDatetimeModelTime(timeString1);
93+ compare(timeLabel.text, timeString1, "Time should come from indicators");
7894
79− clock.currentDate = dateObj
95+ updateDatetimeModelTime(timeString2);
96+ compare(timeLabel.text, timeString2, "Time should come from indicators");
97+ }
8098
81− var dateLabel = findChild(clock, "dateLabel")
82− compare(dateLabel.text, dateString, "Not the expected date")
83− var timeLabel = findChild(clock, "timeLabel")
84− compare(timeLabel.text, timeString, "Not the expected time")
99+ function test_indicatorDisconnect() {
100+ clock.visible = false
101+ var timeModel = findInvisibleChild(clock, "timeModel")
102+ compare(timeModel.menuObjectPath, "", "Clock shouldn't be connected to Indicators when not visible.")
85103
86104 clock.visible = true
87−
88− verify(timeModel.menuObjectPath != "", "Should be connected to Indicators.")
105+ verify(timeModel.menuObjectPath !== "", "Should be connected to Indicators.")
89106 }
90107 }
91108}
tests/qmltests/Panel/Indicators/tst_DefaultIndicatorPage.qml+77−80
@@ -17,7 +17,7 @@
1717import QtQuick 2.0
1818import QtTest 1.0
1919import Unity.Test 0.1 as UT
20−import QMenuModel 0.1
20+import Unity.Indicators 0.1 as Indicators
2121import "../../../../qml/Panel/Indicators"
2222
2323Item {
@@ -27,48 +27,31 @@ Item {
2727
2828 DefaultIndicatorPage {
2929 id: page
30−
3130 anchors.fill: parent
3231
33− menuModel: UnityMenuModel {}
34− busName: "test"
35− actionsObjectPath: "test"
36− menuObjectPath: "test"
37−
3832 identifier: "test-indicator"
39− rootMenuType: "com.canonical.indicator.root"
33+ busName: "com.caninical.indicator.test"
34+ actionsObjectPath: "/com/canonical/indicator/test"
35+ menuObjectPath: "/com/canonical/indicator/test"
4036 }
4137
42− property var fullMenuData: [{
43− "rowData": { // 1
44− "label": "root",
45− "sensitive": true,
46− "isSeparator": false,
47− "icon": "",
48− "type": "com.canonical.indicator.root",
49− "ext": {},
50− "action": "",
51− "actionState": {},
52− "isCheck": false,
53− "isRadio": false,
54− "isToggled": false,
55− },
56− "submenu": [{
57− "rowData": { // 1.1
58− "label": "menu1",
59− "sensitive": true,
60− "isSeparator": false,
61− "icon": "",
62− "type": "",
63− "ext": {},
64− "action": "",
65− "actionState": {},
66− "isCheck": false,
67− "isRadio": false,
68− "isToggled": false,
69− }}, {
70− "rowData": { // 1.2
71− "label": "menu2",
38+ property var fullMenuData: [{
39+ "rowData": { // 1
40+ "label": "root",
41+ "sensitive": true,
42+ "isSeparator": false,
43+ "icon": "",
44+ "type": "com.canonical.indicator.root",
45+ "ext": {},
46+ "action": "",
47+ "actionState": {},
48+ "isCheck": false,
49+ "isRadio": false,
50+ "isToggled": false,
51+ },
52+ "submenu": [{
53+ "rowData": { // 1.1
54+ "label": "menu1",
7255 "sensitive": true,
7356 "isSeparator": false,
7457 "icon": "",
@@ -80,62 +63,76 @@ Item {
8063 "isRadio": false,
8164 "isToggled": false,
8265 }}, {
83− "rowData": { // row 1.2
84− "label": "menu3",
85− "sensitive": true,
86− "isSeparator": false,
87− "icon": "",
88− "type": "",
89− "ext": {},
90− "action": "",
91− "actionState": {},
92− "isCheck": false,
93− "isRadio": false,
94− "isToggled": false,
95− }}
96− ]
97− }]; // end row 1
98−
99− property var emptySubMenuData: [{
100− "rowData": { // 1
101− "label": "root",
102− "sensitive": true,
103− "isSeparator": false,
104− "icon": "",
105− "type": "com.canonical.indicator.root",
106− "ext": {},
107− "action": "",
108− "actionState": {},
109− "isCheck": false,
110− "isRadio": false,
111− "isToggled": false,
112− },
113− "submenu": []
114− }]; // end row 1
66+ "rowData": { // 1.2
67+ "label": "menu2",
68+ "sensitive": true,
69+ "isSeparator": false,
70+ "icon": "",
71+ "type": "",
72+ "ext": {},
73+ "action": "",
74+ "actionState": {},
75+ "isCheck": false,
76+ "isRadio": false,
77+ "isToggled": false,
78+ }}, {
79+ "rowData": { // row 1.2
80+ "label": "menu3",
81+ "sensitive": true,
82+ "isSeparator": false,
83+ "icon": "",
84+ "type": "",
85+ "ext": {},
86+ "action": "",
87+ "actionState": {},
88+ "isCheck": false,
89+ "isRadio": false,
90+ "isToggled": false,
91+ }}
92+ ]
93+ }]; // end row 1
94+
95+ property var emptySubMenuData: [{
96+ "rowData": { // 1
97+ "label": "root",
98+ "sensitive": true,
99+ "isSeparator": false,
100+ "icon": "",
101+ "type": "com.canonical.indicator.root",
102+ "ext": {},
103+ "action": "",
104+ "actionState": {},
105+ "isCheck": false,
106+ "isRadio": false,
107+ "isToggled": false,
108+ },
109+ "submenu": []
110+ }]; // end row 1
111+
112+ function initializeMenuData(data) {
113+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicator.test",
114+ "/com/canonical/indicator/test",
115+ "/com/canonical/indicator/test",
116+ data);
117+ }
115118
116119 UT.UnityTestCase {
117120 name: "DefaultIndicatorPage"
118121
119122 function init() {
120− var mainMenu = findChild(page, "mainMenu");
121− page.menuModel.modelData = [];
122− verify(mainMenu.model !== null);
123+ initializeMenuData([]);
123124 }
124125
125126 function test_reloadData() {
126127 var mainMenu = findChild(page, "mainMenu");
127128
128− page.menuModel.modelData = [];
129129 tryCompare(mainMenu, "count", 0);
130130
131− page.menuModel.modelData = fullMenuData;
131+ initializeMenuData(fullMenuData);
132132 tryCompare(mainMenu, "count", 3);
133133
134− page.menuModel.modelData = [];
134+ initializeMenuData([]);
135135 tryCompare(mainMenu, "count", 0);
136−
137− page.menuModel.modelData = fullMenuData;
138− tryCompare(mainMenu, "count", 3);
139136 }
140137
141138 function test_traverse_rootMenuType_data() {
@@ -147,7 +144,7 @@ Item {
147144
148145 function test_traverse_rootMenuType(data) {
149146 page.rootMenuType = data.rootMenuType;
150− page.menuModel.modelData = fullMenuData;
147+ initializeMenuData(fullMenuData);
151148
152149 var mainMenu = findChild(page, "mainMenu");
153150 tryCompare(mainMenu, "count", data.expectedCount);
tests/qmltests/Panel/Indicators/tst_DefaultIndicatorWidget.qml−8
@@ -33,7 +33,6 @@ Item {
3333 top: parent.top
3434 }
3535
36− menuModel: UnityMenuModel {}
3736 busName: "test"
3837 actionsObjectPath: "test"
3938 deviceMenuObjectPath: "test"
@@ -48,13 +47,6 @@ Item {
4847 name: "DefaultIndicatorWidget"
4948 when: windowShown
5049
51− function init() {
52− widget.rootActionState.icons = [];
53− widget.rootActionState.leftLabel = "";
54− widget.rootActionState.rightLabel = "";
55− waitForRendering(widget)
56− }
57−
5850 // FIXME: add tests
5951 }
6052}
tests/qmltests/Panel/tst_IndicatorItem.qml+1−1
@@ -43,7 +43,7 @@ Rectangle {
4343
4444 function test_empty() {
4545 compare(indicatorItem.indicatorVisible, false, "IndicatorItem should not be visible.");
46− indicatorItem.widgetSource = "qrc:/tests/indciators/qml/fake_menu_widget1.qml";
46+ indicatorItem.widgetSource = "../../../qml/Panel/Indicators/DefaultIndicatorWidget.qml";
4747 tryCompare(indicatorItem, "indicatorVisible", true);
4848 }
4949 }
tests/qmltests/Panel/tst_IndicatorRow.qml+17−19
@@ -30,15 +30,6 @@ Item {
3030 width: units.gu(40)
3131 height: units.gu(60)
3232
33− function init_test()
34− {
35− indicatorModel.load("test1");
36−
37− indicatorRow.state = "initial";
38− indicatorRow.setCurrentItemIndex(-1);
39− indicatorRow.unitProgress = 0.0;
40− }
41−
4233 PanelBackground {
4334 anchors.fill: indicatorRow
4435 }
@@ -63,20 +54,33 @@ Item {
6354 name: "IndicatorRow"
6455 when: windowShown
6556
57+ function init() {
58+ indicatorModel.load("test1");
59+
60+ indicatorRow.state = "initial";
61+ indicatorRow.setCurrentItemIndex(-1);
62+ indicatorRow.unitProgress = 0.0;
63+ }
64+
6665 function get_indicator_item(index) {
6766 return findChild(indicatorRow.row, "item" + index);
6867 }
6968
7069 function test_set_current_item() {
71− init_test();
7270 indicatorRow.setCurrentItemIndex(0);
73− compare(indicatorRow.indicatorsModel.data(indicatorRow.currentItemIndex, Indicators.IndicatorsModelRole.Identifier), "indicator-fake1", "Incorrect item at position 0");
71+ compare(indicatorRow.indicatorsModel.data(indicatorRow.currentItemIndex, Indicators.IndicatorsModelRole.Identifier),
72+ "fake-indicator-1",
73+ "Incorrect item at position 0");
7474
7575 indicatorRow.setCurrentItemIndex(1);
76− compare(indicatorRow.indicatorsModel.data(indicatorRow.currentItemIndex, Indicators.IndicatorsModelRole.Identifier), "indicator-fake2", "Incorrect item at position 1");
76+ compare(indicatorRow.indicatorsModel.data(indicatorRow.currentItemIndex, Indicators.IndicatorsModelRole.Identifier),
77+ "fake-indicator-2",
78+ "Incorrect item at position 1");
7779
7880 indicatorRow.setCurrentItemIndex(2);
79− compare(indicatorRow.indicatorsModel.data(indicatorRow.currentItemIndex, Indicators.IndicatorsModelRole.Identifier), "indicator-fake3", "Incorrect item at position 2");
81+ compare(indicatorRow.indicatorsModel.data(indicatorRow.currentItemIndex, Indicators.IndicatorsModelRole.Identifier),
82+ "fake-indicator-3",
83+ "Incorrect item at position 2");
8084 }
8185
8286 function test_highlight_data() {
@@ -93,8 +97,6 @@ Item {
9397 }
9498
9599 function test_highlight(data) {
96− init_test();
97−
98100 indicatorRow.unitProgress = data.progress;
99101 indicatorRow.setCurrentItemIndex(data.index);
100102
@@ -119,8 +121,6 @@ Item {
119121 }
120122
121123 function test_opacity(data) {
122− init_test();
123−
124124 indicatorRow.unitProgress = data.progress;
125125 indicatorRow.setCurrentItemIndex(data.index);
126126
@@ -145,8 +145,6 @@ Item {
145145 }
146146
147147 function test_dimmed(data) {
148− init_test();
149−
150148 indicatorRow.unitProgress = data.progress;
151149 indicatorRow.setCurrentItemIndex(data.index);
152150
tests/qmltests/Panel/tst_Indicators.qml+9−8
@@ -158,6 +158,7 @@ Item {
158158 function init_invisible_indicator(identifier) {
159159 tryCompareFunction(function() { return findChild(indicators, identifier+"-delegate") !== undefined }, true);
160160 var item = findChild(indicators, identifier+"-delegate");
161+ verify(item !== null);
161162
162163 item.enabled = false;
163164 }
@@ -179,7 +180,7 @@ Item {
179180 var count = data.visible.length
180181 for (var i = 0; i< data.visible.length; i++) {
181182 if (data.visible[i] === false) {
182− init_invisible_indicator("indicator-fake" + (i + 1));
183+ init_invisible_indicator("fake-indicator-" + (i + 1));
183184 count--;
184185 }
185186 }
@@ -187,8 +188,8 @@ Item {
187188 tryCompare(indicatorRowItems, "count", count);
188189
189190 for (i = 0; i < data.visible.length; i++) {
190− var widgetName = "indicator-fake" + (i + 1 + "-widget");
191− var pageName = "indicator-fake" + (i + 1 + "-page");
191+ var widgetName = "fake-indicator-" + (i + 1 + "-widget");
192+ var pageName = "fake-indicator-" + (i + 1 + "-page");
192193
193194 // check for item
194195 tryCompareFunction(function() { return findChild(indicatorRowItems, widgetName) !== null }, data.visible[i]);
@@ -199,10 +200,10 @@ Item {
199200 }
200201
201202 function test_indicator_visible_correct_menu_data() { return [
202− {tag: "current-first", currentIndex: 0, visible: [false, true, true, true, true], expectedIndex: 0, expextedMenu: "indicator-fake2" },
203− {tag: "current-last", currentIndex: 4, visible: [true, true, true, true, false], expectedIndex: 3, expextedMenu: "indicator-fake4" },
204− {tag: "after", currentIndex: 0, visible: [true, false, true, true, true], expectedIndex: 0, expextedMenu: "indicator-fake1" },
205− {tag: "before", currentIndex: 1, visible: [false, true, true, true, true], expectedIndex: 1, expextedMenu: "indicator-fake2" }];
203+ {tag: "current-first", currentIndex: 0, visible: [false, true, true, true, true], expectedIndex: 0, expextedMenu: "fake-indicator-2" },
204+ {tag: "current-last", currentIndex: 4, visible: [true, true, true, true, false], expectedIndex: 3, expextedMenu: "fake-indicator-4" },
205+ {tag: "after", currentIndex: 0, visible: [true, false, true, true, true], expectedIndex: 0, expextedMenu: "fake-indicator-1" },
206+ {tag: "before", currentIndex: 1, visible: [false, true, true, true, true], expectedIndex: 1, expextedMenu: "fake-indicator-2" }];
206207 }
207208
208209 function test_indicator_visible_correct_menu(data) {
@@ -215,7 +216,7 @@ Item {
215216
216217 for (var i = 0; i< data.visible.length; i++) {
217218 if (data.visible[i] === false) {
218− init_invisible_indicator("indicator-fake" + (i + 1));
219+ init_invisible_indicator("fake-indicator-" + (i + 1));
219220 }
220221 }
221222
tests/qmltests/Panel/tst_MenuContent.qml−8
@@ -26,14 +26,6 @@ Item {
2626 width: units.gu(40)
2727 height: units.gu(70)
2828
29− property var indicator_status: {
30− 'indicator-fake1-page': { 'started': false, 'reset': 0 },
31− 'indicator-fake2-page': { 'started': false, 'reset': 0 },
32− 'indicator-fake3-page': { 'started': false, 'reset': 0 },
33− 'indicator-fake4-page': { 'started': false, 'reset': 0 },
34− 'indicator-fake5-page': { 'started': false, 'reset': 0 }
35− }
36−
3729 // Dummy objects
3830 Item { id: greeter }
3931 Item { id: handle }