on xenial help sign in
better mocking
682562dNick Dedekind
plugins/Unity/Indicators/plugin.cpp+1−1
@@ -43,7 +43,7 @@ static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEng
43 return UnityMenuModelCache::singleton();
43 return UnityMenuModelCache::singleton();
44}
44}
45
45
46−void Indicators2Plugin::registerTypes(const char *uri)
46+void IndicatorsPlugin::registerTypes(const char *uri)
47{
47{
48 qRegisterMetaType<UnityMenuModel*>("UnityMenuModel*");
48 qRegisterMetaType<UnityMenuModel*>("UnityMenuModel*");
49
49
plugins/Unity/Indicators/plugin.h+1−1
@@ -22,7 +22,7 @@
22
22
23#include <QtQml/QQmlExtensionPlugin>
23#include <QtQml/QQmlExtensionPlugin>
24
24
25−class Indicators2Plugin : public QQmlExtensionPlugin
25+class IndicatorsPlugin : public QQmlExtensionPlugin
26{
26{
27 Q_OBJECT
27 Q_OBJECT
28 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
28 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
plugins/Unity/Indicators/unitymenumodelcache.cpp−1
@@ -24,7 +24,6 @@
24
24
25UnityMenuModelCache* UnityMenuModelCache::theCache = nullptr;
25UnityMenuModelCache* UnityMenuModelCache::theCache = nullptr;
26
26
27−
28UnityMenuModelCache* UnityMenuModelCache::singleton()
27UnityMenuModelCache* UnityMenuModelCache::singleton()
29{
28{
30 if (!theCache) {
29 if (!theCache) {
plugins/Unity/Indicators/unitymenumodelcache.h+3−3
@@ -36,14 +36,14 @@ public:
36
36
37 static UnityMenuModelCache* singleton();
37 static UnityMenuModelCache* singleton();
38
38
39− QSharedPointer<UnityMenuModel> model(const QByteArray& bus,
39+ virtual QSharedPointer<UnityMenuModel> model(const QByteArray& bus,
40 const QByteArray& path,
40 const QByteArray& path,
41 const QVariantMap& actions);
41 const QVariantMap& actions);
42
42
43 // for tests use
43 // for tests use
44− Q_INVOKABLE bool contains(const QByteArray& path);
44+ Q_INVOKABLE virtual bool contains(const QByteArray& path);
45
45
46−private:
46+protected:
47 QHash<QByteArray, QWeakPointer<UnityMenuModel>> m_registry;
47 QHash<QByteArray, QWeakPointer<UnityMenuModel>> m_registry;
48 static UnityMenuModelCache* theCache;
48 static UnityMenuModelCache* theCache;
49};
49};
qml/Greeter/Clock.qml+1−1
@@ -47,7 +47,7 @@ Item {
47 menu: timeModel.model
47 menu: timeModel.model
48 onUpdated: {
48 onUpdated: {
49 if (timeLabel.text != rightLabel) {
49 if (timeLabel.text != rightLabel) {
50− timeLabel.text = rightLabel;
50+ if (rightLabel != "") timeLabel.text = rightLabel;
51 clock.currentDate = new Date();
51 clock.currentDate = new Date();
52 }
52 }
53 }
53 }
tests/mocks/QMenuModel/unitymenumodel.cpp+1−2
@@ -50,13 +50,12 @@ void UnityMenuModel::setModelData(const QVariant& data)
50{
50{
51 beginResetModel();
51 beginResetModel();
52
52
53− m_modelData.clear();
54 m_modelData = data.toList();
53 m_modelData = data.toList();
54+ Q_EMIT modelDataChanged();
55
55
56 endResetModel();
56 endResetModel();
57}
57}
58
58
59−
60void UnityMenuModel::insertRow(int row, const QVariant& data)
59void UnityMenuModel::insertRow(int row, const QVariant& data)
61{
60{
62 row = qMin(row, rowCount());
61 row = qMin(row, rowCount());
tests/mocks/QMenuModel/unitymenumodel.h+6−2
@@ -27,13 +27,15 @@ class ActionStateParser;
27class Q_DECL_EXPORT UnityMenuModel : public QAbstractListModel
27class Q_DECL_EXPORT UnityMenuModel : public QAbstractListModel
28{
28{
29 Q_OBJECT
29 Q_OBJECT
30− Q_PROPERTY(QVariant modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
31 Q_PROPERTY(QByteArray busName READ busName WRITE setBusName NOTIFY busNameChanged)
30 Q_PROPERTY(QByteArray busName READ busName WRITE setBusName NOTIFY busNameChanged)
32 Q_PROPERTY(QVariantMap actions READ actions WRITE setActions NOTIFY actionsChanged)
31 Q_PROPERTY(QVariantMap actions READ actions WRITE setActions NOTIFY actionsChanged)
33 Q_PROPERTY(QByteArray menuObjectPath READ menuObjectPath WRITE setMenuObjectPath NOTIFY menuObjectPathChanged)
32 Q_PROPERTY(QByteArray menuObjectPath READ menuObjectPath WRITE setMenuObjectPath NOTIFY menuObjectPathChanged)
34 Q_PROPERTY(ActionStateParser* actionStateParser READ actionStateParser WRITE setActionStateParser NOTIFY actionStateParserChanged)
33 Q_PROPERTY(ActionStateParser* actionStateParser READ actionStateParser WRITE setActionStateParser NOTIFY actionStateParserChanged)
35 Q_PROPERTY(QString nameOwner READ nameOwner NOTIFY nameOwnerChanged)
34 Q_PROPERTY(QString nameOwner READ nameOwner NOTIFY nameOwnerChanged)
36
35
36+ // internal mock properties
37+ Q_PROPERTY(QVariant modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
38+
37public:
39public:
38 UnityMenuModel(QObject *parent = nullptr);
40 UnityMenuModel(QObject *parent = nullptr);
39 virtual ~UnityMenuModel();
41 virtual ~UnityMenuModel();
@@ -81,9 +83,11 @@ Q_SIGNALS:
81 void actionsChanged();
83 void actionsChanged();
82 void menuObjectPathChanged();
84 void menuObjectPathChanged();
83 void actionStateParserChanged();
85 void actionStateParserChanged();
84− void modelDataChanged();
85 void nameOwnerChanged();
86 void nameOwnerChanged();
86
87
88+ // Internal mock usage
89+ void modelDataChanged();
90+
87private:
91private:
88 QVariantMap rowData(int row) const;
92 QVariantMap rowData(int row) const;
89 QVariant subMenuData(int row) const;
93 QVariant subMenuData(int row) const;
tests/mocks/Unity/Indicators/CMakeLists.txt+2−10
@@ -12,25 +12,17 @@ include_directories(
12
12
13set(IndicatorsFakeQml_SOURCES
13set(IndicatorsFakeQml_SOURCES
14 fakeplugin.cpp
14 fakeplugin.cpp
15+ fakeindicatorsmodel.cpp
16+ fakeunitymenumodelcache.cpp
15 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/indicators.h
17 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/indicators.h
16 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/menucontentactivator.cpp
18 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/menucontentactivator.cpp
17 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/sharedunitymenumodel.cpp
19 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/sharedunitymenumodel.cpp
18 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelcache.cpp
20 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelcache.cpp
19 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelstack.cpp
21 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/unitymenumodelstack.cpp
20 ${CMAKE_SOURCE_DIR}/plugins/Unity/Indicators/visibleindicatorsmodel.cpp
22 ${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}
30)
23)
31
24
32add_library(IndicatorsFakeQml SHARED
25add_library(IndicatorsFakeQml SHARED
33− ${IndicatorsFakeQml_RESOURCES_RCC}
34 ${IndicatorsFakeQml_SOURCES}
26 ${IndicatorsFakeQml_SOURCES}
35)
27)
36add_definitions(-DUNITYINDICATORS_LIBRARY)
28add_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
18import Unity.Indicators 0.1 as Indicators
18import Unity.Indicators 0.1 as Indicators
19
19
20Indicators.FakeIndicatorsModel {
20Indicators.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+ ]
21
163
22 function load(profile) {
164 function load(profile) {
23 unload();
165 unload();
24−
166+ root.modelData = originalModelData;
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− });
59 }
167 }
60}
168}
tests/mocks/Unity/Indicators/RootActionState.qml+17−9
@@ -19,15 +19,23 @@
19
19
20import QtQuick 2.0
20import QtQuick 2.0
21
21
22−QtObject {
22+Item {
23− property var menu
23+ property var menu: null
24− property bool valid: false
24+ property bool valid: cachedState !== undefined
25− property string title
25+ property string title: cachedState && cachedState.hasOwnProperty("title") ? cachedState["title"] : ""
26− property string leftLabel
26+ property string leftLabel: cachedState && cachedState.hasOwnProperty("pre-label") ? cachedState["pre-label"] : ""
27− property string rightLabel
27+ property string rightLabel: cachedState && cachedState.hasOwnProperty("label") ? cachedState["label"] : ""
28− property var icons
28+ property var icons: cachedState && cachedState.hasOwnProperty("icons") ? cachedState["icons"] : []
29− property string accessibleName
29+ property string accessibleName: cachedState && cachedState.hasOwnProperty("accessible-desc") ? cachedState["accessible-desc"] : ""
30− property bool visible: true
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+ }
31
39
32 signal updated
40 signal updated
33
41
tests/mocks/Unity/Indicators/fakeindicatorsmodel.cpp+50−19
@@ -31,7 +31,6 @@ FakeIndicatorsModel::FakeIndicatorsModel(QObject *parent)
31/*! \internal */
31/*! \internal */
32FakeIndicatorsModel::~FakeIndicatorsModel()
32FakeIndicatorsModel::~FakeIndicatorsModel()
33{
33{
34− qDeleteAll(m_indicators);
35}
34}
36
35
37int FakeIndicatorsModel::count() const
36int FakeIndicatorsModel::count() const
@@ -47,31 +46,63 @@ void FakeIndicatorsModel::unload()
47{
46{
48 beginResetModel();
47 beginResetModel();
49
48
50− qDeleteAll(m_indicators);
49+ m_modelData.clear();
51− m_indicators.clear();
50+ Q_EMIT modelDataChanged();
52
51
53 endResetModel();
52 endResetModel();
54}
53}
55
54
56
55
57−void FakeIndicatorsModel::append(const QVariantMap& row)
56+void FakeIndicatorsModel::append(const QVariantMap& data)
58{
57{
59− Indicator* new_row = new QHash<int, QVariant>();
58+ QList<QVariant> allData = m_modelData.toList();
60− for (auto iter = row.begin(); iter != row.end(); ++iter )
59+ beginInsertRows(QModelIndex(), allData.count(), allData.count());
61− {
60+
62− int key = roleNames().key(iter.key().toUtf8(), -1);
61+ allData.append(data);
63− if (key != -1) {
62+ m_modelData = allData;
64− new_row->insert(key, iter.value());
63+ Q_EMIT modelDataChanged();
65− }
66− }
67
64
68− beginInsertRows(QModelIndex(), m_indicators.count(), m_indicators.count());
65+ endInsertRows();
66+}
69
67
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();
71
78
72 endInsertRows();
79 endInsertRows();
73}
80}
74
81
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+
75QHash<int, QByteArray> FakeIndicatorsModel::roleNames() const
106QHash<int, QByteArray> FakeIndicatorsModel::roleNames() const
76{
107{
77 static QHash<int, QByteArray> roles;
108 static QHash<int, QByteArray> roles;
@@ -91,18 +122,18 @@ int FakeIndicatorsModel::columnCount(const QModelIndex &) const
91 return 1;
122 return 1;
92}
123}
93
124
94−Q_INVOKABLE QVariant FakeIndicatorsModel::data(int row, int role) const
125+QVariant FakeIndicatorsModel::data(int row, int role) const
95{
126{
96 return data(index(row, 0), role);
127 return data(index(row, 0), role);
97}
128}
98
129
99QVariant FakeIndicatorsModel::data(const QModelIndex &index, int role) const
130QVariant FakeIndicatorsModel::data(const QModelIndex &index, int role) const
100{
131{
132+ QList<QVariant> dataList = m_modelData.toList();
101− if (!index.isValid() || index.row() >= m_indicators.size())
133+ if (!index.isValid() || index.row() >= dataList.size())
102 return QVariant();
134 return QVariant();
103
135
104− Indicator* indicator = m_indicators[index.row()];
136+ return dataList[index.row()].toMap()[roleNames()[role]];
105− return indicator->value(role, QVariant());
106}
137}
107
138
108QModelIndex FakeIndicatorsModel::parent(const QModelIndex&) const
139QModelIndex FakeIndicatorsModel::parent(const QModelIndex&) const
@@ -112,5 +143,5 @@ QModelIndex FakeIndicatorsModel::parent(const QModelIndex&) const
112
143
113int FakeIndicatorsModel::rowCount(const QModelIndex&) const
144int FakeIndicatorsModel::rowCount(const QModelIndex&) const
114{
145{
115− return m_indicators.count();
146+ return m_modelData.toList().count();
116}
147}
tests/mocks/Unity/Indicators/fakeindicatorsmodel.h+8−2
@@ -27,6 +27,7 @@ class FakeIndicatorsModel : public QAbstractListModel
27 Q_OBJECT
27 Q_OBJECT
28 Q_ENUMS(Roles)
28 Q_ENUMS(Roles)
29 Q_PROPERTY(int count READ count NOTIFY countChanged)
29 Q_PROPERTY(int count READ count NOTIFY countChanged)
30+ Q_PROPERTY(QVariant modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
30public:
31public:
31
32
32 FakeIndicatorsModel(QObject *parent=0);
33 FakeIndicatorsModel(QObject *parent=0);
@@ -36,9 +37,14 @@ public:
36 Q_INVOKABLE void unload();
37 Q_INVOKABLE void unload();
37
38
38 Q_INVOKABLE void append(const QVariantMap& row);
39 Q_INVOKABLE void append(const QVariantMap& row);
40+ Q_INVOKABLE void insert(int row, const QVariantMap& data);
41+ Q_INVOKABLE void remove(int row);
39
42
40 Q_INVOKABLE QVariant data(int row, int role) const;
43 Q_INVOKABLE QVariant data(int row, int role) const;
41
44
45+ void setModelData(const QVariant& data);
46+ QVariant modelData() const { return m_modelData; }
47+
42 /* QAbstractItemModel */
48 /* QAbstractItemModel */
43 QHash<int, QByteArray> roleNames() const;
49 QHash<int, QByteArray> roleNames() const;
44 int columnCount(const QModelIndex &parent = QModelIndex()) const;
50 int columnCount(const QModelIndex &parent = QModelIndex()) const;
@@ -48,12 +54,12 @@ public:
48
54
49Q_SIGNALS:
55Q_SIGNALS:
50 void countChanged();
56 void countChanged();
57+ void modelDataChanged();
51
58
52private:
59private:
53 int count() const;
60 int count() const;
54
61
55− typedef QHash<int, QVariant> Indicator;
62+ QVariant m_modelData;
56− QList<Indicator*> m_indicators;
57};
63};
58
64
59#endif // FAKE_INDICATORSMODEL_H
65#endif // FAKE_INDICATORSMODEL_H
tests/mocks/Unity/Indicators/fakeplugin.cpp+3−4
@@ -27,7 +27,7 @@
27#include "indicators.h"
27#include "indicators.h"
28#include "menucontentactivator.h"
28#include "menucontentactivator.h"
29#include "sharedunitymenumodel.h"
29#include "sharedunitymenumodel.h"
30−#include "unitymenumodelcache.h"
30+#include "fakeunitymenumodelcache.h"
31#include "unitymenumodelstack.h"
31#include "unitymenumodelstack.h"
32#include "visibleindicatorsmodel.h"
32#include "visibleindicatorsmodel.h"
33
33
@@ -36,12 +36,11 @@
36static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
36static QObject* menuModelCacheSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
37 Q_UNUSED(engine);
37 Q_UNUSED(engine);
38 Q_UNUSED(scriptEngine);
38 Q_UNUSED(scriptEngine);
39− return UnityMenuModelCache::singleton();
39+ return FakeUnityMenuModelCache::singleton();
40}
40}
41
41
42void IndicatorsFakePlugin::registerTypes(const char * uri)
42void IndicatorsFakePlugin::registerTypes(const char * uri)
43{
43{
44− Q_INIT_RESOURCE(indicators_fake);
45 qRegisterMetaType<UnityMenuModel*>("UnityMenuModel*");
44 qRegisterMetaType<UnityMenuModel*>("UnityMenuModel*");
46
45
47 // internal
46 // internal
@@ -53,7 +52,7 @@ void IndicatorsFakePlugin::registerTypes(const char * uri)
53 qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel");
52 qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel");
54 qmlRegisterType<SharedUnityMenuModel>(uri, 0, 1, "SharedUnityMenuModel");
53 qmlRegisterType<SharedUnityMenuModel>(uri, 0, 1, "SharedUnityMenuModel");
55
54
56− qmlRegisterSingletonType<UnityMenuModelCache>(uri, 0, 1, "UnityMenuModelCache", menuModelCacheSingleton);
55+ qmlRegisterSingletonType<FakeUnityMenuModelCache>(uri, 0, 1, "UnityMenuModelCache", menuModelCacheSingleton);
57
56
58 // external uncreatables
57 // external uncreatables
59 qmlRegisterUncreatableType<MenuContentState>(uri, 0, 1, "MenuContentState", "Can't create MenuContentState class");
58 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
3typeinfo Indicators.qmltypes
3typeinfo Indicators.qmltypes
4
4
5IndicatorsModel 0.1 IndicatorsModel.qml
5IndicatorsModel 0.1 IndicatorsModel.qml
6−FakeMenuPage 0.1 FakeMenuPage.qml
7RootActionState 0.1 RootActionState.qml
6RootActionState 0.1 RootActionState.qml
tests/qmltests/CMakeLists.txt+6−6
@@ -19,8 +19,8 @@ set(qmltest_DEFAULT_TARGETS qmluitests)
19set(qmltest_DEFAULT_NO_ADD_TEST TRUE)
19set(qmltest_DEFAULT_NO_ADD_TEST TRUE)
20set(qmltest_DEFAULT_PROPERTIES ENVIRONMENT "LC_ALL=C")
20set(qmltest_DEFAULT_PROPERTIES ENVIRONMENT "LC_ALL=C")
21
21
22−add_qml_test(. Shell ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
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")
23+add_qml_test(. ShellWithPin ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single-pin:${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
24add_qml_test(Components Background)
24add_qml_test(Components Background)
25add_qml_test(Components Carousel)
25add_qml_test(Components Carousel)
26add_qml_test(Components DraggingArea)
26add_qml_test(Components DraggingArea)
@@ -71,10 +71,10 @@ add_qml_test(Launcher Launcher)
71add_qml_test(Notifications Notifications)
71add_qml_test(Notifications Notifications)
72add_qml_test(Notifications VisualSnapDecisionsQueue)
72add_qml_test(Notifications VisualSnapDecisionsQueue)
73add_qml_test(Panel ActiveCallHint)
73add_qml_test(Panel ActiveCallHint)
74−add_qml_test(Panel IndicatorRow)
74+add_qml_test(Panel IndicatorRow ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
75−add_qml_test(Panel Indicators)
75+add_qml_test(Panel Indicators ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
76−add_qml_test(Panel MenuContent)
76+add_qml_test(Panel MenuContent ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
77−add_qml_test(Panel Panel)
77+add_qml_test(Panel Panel ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
78add_qml_test(Panel SearchIndicator)
78add_qml_test(Panel SearchIndicator)
79add_qml_test(Panel/Indicators DefaultIndicatorWidget ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
79add_qml_test(Panel/Indicators DefaultIndicatorWidget ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
80add_qml_test(Panel/Indicators DefaultIndicatorPage ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
80add_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
19import ".."
19import ".."
20import "../../../qml/Greeter"
20import "../../../qml/Greeter"
21import Ubuntu.Components 0.1
21import Ubuntu.Components 0.1
22−import QMenuModel 0.1
22+import Unity.Indicators 0.1 as Indicators
23import Unity.Test 0.1 as UT
23import Unity.Test 0.1 as UT
24
24
25Rectangle {
25Rectangle {
@@ -36,56 +36,73 @@ Rectangle {
36 }
36 }
37 }
37 }
38
38
39− UnityMenuModel {
39+ function updateDatetimeModelTime(label) {
40− id: menuModel
40+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicator.datetime",
41− modelData: [{
41+ "/com/canonical/indicator/datetime/phone",
42+ "/com/canonical/indicator/datetime",
43+ [{
42− "rowData": {
44+ "rowData": {
43− "actionState": { "label": Qt.formatTime(new Date("October 13, 1975 11:13:00")) }
45+ "actionState": { "label": label }
44− }
46+ }
45− }]
47+ }]);
46 }
48 }
47
49
48 UT.UnityTestCase {
50 UT.UnityTestCase {
49 name: "Clock"
51 name: "Clock"
52+ when: windowShown
50
53
51 function init() {
54 function init() {
52− var cachedModel = findChild(clock, "timeModel");
55+ updateDatetimeModelTime(Qt.formatTime(new Date("October 13, 1975 12:14:00")));
53− verify(cachedModel !== undefined);
56+ clock.visible = true;
54− cachedModel.model = menuModel;
55 }
57 }
56
58
57− function test_customDate() {
59+ // Test that the date portion of the clock updates with custom value.
58− var dateObj = new Date("October 13, 1975 11:13:00")
60+ // Time portion is controlled by indicators
59− var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
61+ function test_updateDate() {
60− var timeString = Qt.formatTime(dateObj)
62+ var dateLabel = findChild(clock, "dateLabel");
63+ var timeLabel = findChild(clock, "timeLabel");
61
64
62− clock.currentDate = dateObj
65+ var timeString = Qt.formatTime(new Date("October 13, 1975 12:14:00"));
63− var dateLabel = findChild(clock, "dateLabel")
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+
64− compare(dateLabel.text, dateString, "Not the expected date")
72+ compare(dateLabel.text, dateString, "Not the expected date");
65− var timeLabel = findChild(clock, "timeLabel")
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+
66− compare(timeLabel.text, timeString, "Not the expected time")
80+ compare(dateLabel.text, dateString2, "Not the expected date");
81+ compare(timeLabel.text,timeString, "Time should come from indicators");
67 }
82 }
68
83
69− function test_dateUpdate() {
84+ // Test that the date portion of the clock updates with custom value.
70− var dateObj = new Date("October 13, 1975 11:13:00")
85+ // Time portion is controlled by indicators
71− var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
86+ function test_updateTime() {
72− var timeString = Qt.formatTime(dateObj)
87+ var timeLabel = findChild(clock, "timeLabel");
73
88
74− clock.visible = false
89+ var timeString1 = Qt.formatTime(new Date("October 13, 1975 11:15:00"));
75− var timeModel = findInvisibleChild(clock, "timeModel")
90+ var timeString2 = Qt.formatTime(new Date("October 14, 1976 12:16:00"));
76
91
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");
78
94
79− clock.currentDate = dateObj
95+ updateDatetimeModelTime(timeString2);
96+ compare(timeLabel.text, timeString2, "Time should come from indicators");
97+ }
80
98
81− var dateLabel = findChild(clock, "dateLabel")
99+ function test_indicatorDisconnect() {
82− compare(dateLabel.text, dateString, "Not the expected date")
100+ clock.visible = false
83− var timeLabel = findChild(clock, "timeLabel")
101+ var timeModel = findInvisibleChild(clock, "timeModel")
84− compare(timeLabel.text, timeString, "Not the expected time")
102+ compare(timeModel.menuObjectPath, "", "Clock shouldn't be connected to Indicators when not visible.")
85
103
86 clock.visible = true
104 clock.visible = true
87−
88− verify(timeModel.menuObjectPath != "", "Should be connected to Indicators.")
105+ verify(timeModel.menuObjectPath !== "", "Should be connected to Indicators.")
89 }
106 }
90 }
107 }
91}
108}
tests/qmltests/Panel/Indicators/tst_DefaultIndicatorPage.qml+77−80
@@ -17,7 +17,7 @@
17import QtQuick 2.0
17import QtQuick 2.0
18import QtTest 1.0
18import QtTest 1.0
19import Unity.Test 0.1 as UT
19import Unity.Test 0.1 as UT
20−import QMenuModel 0.1
20+import Unity.Indicators 0.1 as Indicators
21import "../../../../qml/Panel/Indicators"
21import "../../../../qml/Panel/Indicators"
22
22
23Item {
23Item {
@@ -27,48 +27,31 @@ Item {
27
27
28 DefaultIndicatorPage {
28 DefaultIndicatorPage {
29 id: page
29 id: page
30−
31 anchors.fill: parent
30 anchors.fill: parent
32
31
33− menuModel: UnityMenuModel {}
34− busName: "test"
35− actionsObjectPath: "test"
36− menuObjectPath: "test"
37−
38 identifier: "test-indicator"
32 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"
40 }
36 }
41
37
42− property var fullMenuData: [{
38+ property var fullMenuData: [{
43− "rowData": { // 1
39+ "rowData": { // 1
44− "label": "root",
40+ "label": "root",
45− "sensitive": true,
41+ "sensitive": true,
46− "isSeparator": false,
42+ "isSeparator": false,
47− "icon": "",
43+ "icon": "",
48− "type": "com.canonical.indicator.root",
44+ "type": "com.canonical.indicator.root",
49− "ext": {},
45+ "ext": {},
50− "action": "",
46+ "action": "",
51− "actionState": {},
47+ "actionState": {},
52− "isCheck": false,
48+ "isCheck": false,
53− "isRadio": false,
49+ "isRadio": false,
54− "isToggled": false,
50+ "isToggled": false,
55− },
51+ },
56− "submenu": [{
52+ "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
53+ "rowData": { // 1.1
71− "label": "menu2",
54+ "label": "menu1",
72 "sensitive": true,
55 "sensitive": true,
73 "isSeparator": false,
56 "isSeparator": false,
74 "icon": "",
57 "icon": "",
@@ -80,62 +63,76 @@ Item {
80 "isRadio": false,
63 "isRadio": false,
81 "isToggled": false,
64 "isToggled": false,
82 }}, {
65 }}, {
83− "rowData": { // row 1.2
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
84− "label": "menu3",
80+ "label": "menu3",
85− "sensitive": true,
81+ "sensitive": true,
86− "isSeparator": false,
82+ "isSeparator": false,
87− "icon": "",
83+ "icon": "",
88− "type": "",
84+ "type": "",
89− "ext": {},
85+ "ext": {},
90− "action": "",
86+ "action": "",
91− "actionState": {},
87+ "actionState": {},
92− "isCheck": false,
88+ "isCheck": false,
93− "isRadio": false,
89+ "isRadio": false,
94− "isToggled": false,
90+ "isToggled": false,
95− }}
91+ }}
96− ]
92+ ]
97− }]; // end row 1
93+ }]; // end row 1
98−
94+
99− property var emptySubMenuData: [{
95+ property var emptySubMenuData: [{
100− "rowData": { // 1
96+ "rowData": { // 1
101− "label": "root",
97+ "label": "root",
102− "sensitive": true,
98+ "sensitive": true,
103− "isSeparator": false,
99+ "isSeparator": false,
104− "icon": "",
100+ "icon": "",
105− "type": "com.canonical.indicator.root",
101+ "type": "com.canonical.indicator.root",
106− "ext": {},
102+ "ext": {},
107− "action": "",
103+ "action": "",
108− "actionState": {},
104+ "actionState": {},
109− "isCheck": false,
105+ "isCheck": false,
110− "isRadio": false,
106+ "isRadio": false,
111− "isToggled": false,
107+ "isToggled": false,
112− },
108+ },
113− "submenu": []
109+ "submenu": []
114− }]; // end row 1
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+ }
115
118
116 UT.UnityTestCase {
119 UT.UnityTestCase {
117 name: "DefaultIndicatorPage"
120 name: "DefaultIndicatorPage"
118
121
119 function init() {
122 function init() {
120− var mainMenu = findChild(page, "mainMenu");
123+ initializeMenuData([]);
121− page.menuModel.modelData = [];
122− verify(mainMenu.model !== null);
123 }
124 }
124
125
125 function test_reloadData() {
126 function test_reloadData() {
126 var mainMenu = findChild(page, "mainMenu");
127 var mainMenu = findChild(page, "mainMenu");
127
128
128− page.menuModel.modelData = [];
129 tryCompare(mainMenu, "count", 0);
129 tryCompare(mainMenu, "count", 0);
130
130
131− page.menuModel.modelData = fullMenuData;
131+ initializeMenuData(fullMenuData);
132 tryCompare(mainMenu, "count", 3);
132 tryCompare(mainMenu, "count", 3);
133
133
134− page.menuModel.modelData = [];
134+ initializeMenuData([]);
135 tryCompare(mainMenu, "count", 0);
135 tryCompare(mainMenu, "count", 0);
136−
137− page.menuModel.modelData = fullMenuData;
138− tryCompare(mainMenu, "count", 3);
139 }
136 }
140
137
141 function test_traverse_rootMenuType_data() {
138 function test_traverse_rootMenuType_data() {
@@ -147,7 +144,7 @@ Item {
147
144
148 function test_traverse_rootMenuType(data) {
145 function test_traverse_rootMenuType(data) {
149 page.rootMenuType = data.rootMenuType;
146 page.rootMenuType = data.rootMenuType;
150− page.menuModel.modelData = fullMenuData;
147+ initializeMenuData(fullMenuData);
151
148
152 var mainMenu = findChild(page, "mainMenu");
149 var mainMenu = findChild(page, "mainMenu");
153 tryCompare(mainMenu, "count", data.expectedCount);
150 tryCompare(mainMenu, "count", data.expectedCount);
tests/qmltests/Panel/Indicators/tst_DefaultIndicatorWidget.qml−8
@@ -33,7 +33,6 @@ Item {
33 top: parent.top
33 top: parent.top
34 }
34 }
35
35
36− menuModel: UnityMenuModel {}
37 busName: "test"
36 busName: "test"
38 actionsObjectPath: "test"
37 actionsObjectPath: "test"
39 deviceMenuObjectPath: "test"
38 deviceMenuObjectPath: "test"
@@ -48,13 +47,6 @@ Item {
48 name: "DefaultIndicatorWidget"
47 name: "DefaultIndicatorWidget"
49 when: windowShown
48 when: windowShown
50
49
51− function init() {
52− widget.rootActionState.icons = [];
53− widget.rootActionState.leftLabel = "";
54− widget.rootActionState.rightLabel = "";
55− waitForRendering(widget)
56− }
57−
58 // FIXME: add tests
50 // FIXME: add tests
59 }
51 }
60}
52}
tests/qmltests/Panel/tst_IndicatorItem.qml+1−1
@@ -43,7 +43,7 @@ Rectangle {
43
43
44 function test_empty() {
44 function test_empty() {
45 compare(indicatorItem.indicatorVisible, false, "IndicatorItem should not be visible.");
45 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";
47 tryCompare(indicatorItem, "indicatorVisible", true);
47 tryCompare(indicatorItem, "indicatorVisible", true);
48 }
48 }
49 }
49 }
tests/qmltests/Panel/tst_IndicatorRow.qml+17−19
@@ -30,15 +30,6 @@ Item {
30 width: units.gu(40)
30 width: units.gu(40)
31 height: units.gu(60)
31 height: units.gu(60)
32
32
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−
42 PanelBackground {
33 PanelBackground {
43 anchors.fill: indicatorRow
34 anchors.fill: indicatorRow
44 }
35 }
@@ -63,20 +54,33 @@ Item {
63 name: "IndicatorRow"
54 name: "IndicatorRow"
64 when: windowShown
55 when: windowShown
65
56
57+ function init() {
58+ indicatorModel.load("test1");
59+
60+ indicatorRow.state = "initial";
61+ indicatorRow.setCurrentItemIndex(-1);
62+ indicatorRow.unitProgress = 0.0;
63+ }
64+
66 function get_indicator_item(index) {
65 function get_indicator_item(index) {
67 return findChild(indicatorRow.row, "item" + index);
66 return findChild(indicatorRow.row, "item" + index);
68 }
67 }
69
68
70 function test_set_current_item() {
69 function test_set_current_item() {
71− init_test();
72 indicatorRow.setCurrentItemIndex(0);
70 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");
74
74
75 indicatorRow.setCurrentItemIndex(1);
75 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");
77
79
78 indicatorRow.setCurrentItemIndex(2);
80 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");
80 }
84 }
81
85
82 function test_highlight_data() {
86 function test_highlight_data() {
@@ -93,8 +97,6 @@ Item {
93 }
97 }
94
98
95 function test_highlight(data) {
99 function test_highlight(data) {
96− init_test();
97−
98 indicatorRow.unitProgress = data.progress;
100 indicatorRow.unitProgress = data.progress;
99 indicatorRow.setCurrentItemIndex(data.index);
101 indicatorRow.setCurrentItemIndex(data.index);
100
102
@@ -119,8 +121,6 @@ Item {
119 }
121 }
120
122
121 function test_opacity(data) {
123 function test_opacity(data) {
122− init_test();
123−
124 indicatorRow.unitProgress = data.progress;
124 indicatorRow.unitProgress = data.progress;
125 indicatorRow.setCurrentItemIndex(data.index);
125 indicatorRow.setCurrentItemIndex(data.index);
126
126
@@ -145,8 +145,6 @@ Item {
145 }
145 }
146
146
147 function test_dimmed(data) {
147 function test_dimmed(data) {
148− init_test();
149−
150 indicatorRow.unitProgress = data.progress;
148 indicatorRow.unitProgress = data.progress;
151 indicatorRow.setCurrentItemIndex(data.index);
149 indicatorRow.setCurrentItemIndex(data.index);
152
150
tests/qmltests/Panel/tst_Indicators.qml+9−8
@@ -158,6 +158,7 @@ Item {
158 function init_invisible_indicator(identifier) {
158 function init_invisible_indicator(identifier) {
159 tryCompareFunction(function() { return findChild(indicators, identifier+"-delegate") !== undefined }, true);
159 tryCompareFunction(function() { return findChild(indicators, identifier+"-delegate") !== undefined }, true);
160 var item = findChild(indicators, identifier+"-delegate");
160 var item = findChild(indicators, identifier+"-delegate");
161+ verify(item !== null);
161
162
162 item.enabled = false;
163 item.enabled = false;
163 }
164 }
@@ -179,7 +180,7 @@ Item {
179 var count = data.visible.length
180 var count = data.visible.length
180 for (var i = 0; i< data.visible.length; i++) {
181 for (var i = 0; i< data.visible.length; i++) {
181 if (data.visible[i] === false) {
182 if (data.visible[i] === false) {
182− init_invisible_indicator("indicator-fake" + (i + 1));
183+ init_invisible_indicator("fake-indicator-" + (i + 1));
183 count--;
184 count--;
184 }
185 }
185 }
186 }
@@ -187,8 +188,8 @@ Item {
187 tryCompare(indicatorRowItems, "count", count);
188 tryCompare(indicatorRowItems, "count", count);
188
189
189 for (i = 0; i < data.visible.length; i++) {
190 for (i = 0; i < data.visible.length; i++) {
190− var widgetName = "indicator-fake" + (i + 1 + "-widget");
191+ var widgetName = "fake-indicator-" + (i + 1 + "-widget");
191− var pageName = "indicator-fake" + (i + 1 + "-page");
192+ var pageName = "fake-indicator-" + (i + 1 + "-page");
192
193
193 // check for item
194 // check for item
194 tryCompareFunction(function() { return findChild(indicatorRowItems, widgetName) !== null }, data.visible[i]);
195 tryCompareFunction(function() { return findChild(indicatorRowItems, widgetName) !== null }, data.visible[i]);
@@ -199,10 +200,10 @@ Item {
199 }
200 }
200
201
201 function test_indicator_visible_correct_menu_data() { return [
202 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-first", currentIndex: 0, visible: [false, true, true, true, true], expectedIndex: 0, expextedMenu: "fake-indicator-2" },
203− {tag: "current-last", currentIndex: 4, visible: [true, true, true, true, false], expectedIndex: 3, expextedMenu: "indicator-fake4" },
204+ {tag: "current-last", currentIndex: 4, visible: [true, true, true, true, false], expectedIndex: 3, expextedMenu: "fake-indicator-4" },
204− {tag: "after", currentIndex: 0, visible: [true, false, true, true, true], expectedIndex: 0, expextedMenu: "indicator-fake1" },
205+ {tag: "after", currentIndex: 0, visible: [true, false, true, true, true], expectedIndex: 0, expextedMenu: "fake-indicator-1" },
205− {tag: "before", currentIndex: 1, visible: [false, true, true, true, true], expectedIndex: 1, expextedMenu: "indicator-fake2" }];
206+ {tag: "before", currentIndex: 1, visible: [false, true, true, true, true], expectedIndex: 1, expextedMenu: "fake-indicator-2" }];
206 }
207 }
207
208
208 function test_indicator_visible_correct_menu(data) {
209 function test_indicator_visible_correct_menu(data) {
@@ -215,7 +216,7 @@ Item {
215
216
216 for (var i = 0; i< data.visible.length; i++) {
217 for (var i = 0; i< data.visible.length; i++) {
217 if (data.visible[i] === false) {
218 if (data.visible[i] === false) {
218− init_invisible_indicator("indicator-fake" + (i + 1));
219+ init_invisible_indicator("fake-indicator-" + (i + 1));
219 }
220 }
220 }
221 }
221
222
tests/qmltests/Panel/tst_MenuContent.qml−8
@@ -26,14 +26,6 @@ Item {
26 width: units.gu(40)
26 width: units.gu(40)
27 height: units.gu(70)
27 height: units.gu(70)
28
28
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−
37 // Dummy objects
29 // Dummy objects
38 Item { id: greeter }
30 Item { id: greeter }
39 Item { id: handle }
31 Item { id: handle }