on xenial help sign in
Add new test for this branch, and fix up GSettings mock
commit4511c9e546ae12fb52febb6a57ca3fff590bb111 authorMichael Terry <michael.terry@canonical.com> dateMon 23 Mar 2015, 14:19 (12 years ago) parentc93ed50
4 files changed+117−37
tests/mocks/GSettings.1.0/fake_gsettings.cpp+58−22 tests/mocks/GSettings.1.0/fake_gsettings.h+16−6 tests/mocks/GSettings.1.0/plugin.cpp−6 tests/qmltests/tst_Shell.qml+43−3
tests/mocks/GSettings.1.0/fake_gsettings.cpp+58−22
@@ -20,7 +20,9 @@
2020
2121GSettingsControllerQml* GSettingsControllerQml::s_controllerInstance = 0;
2222
23−GSettingsControllerQml::GSettingsControllerQml() {
23+GSettingsControllerQml::GSettingsControllerQml()
24+ : m_usageMode("Staged")
25+{
2426}
2527
2628GSettingsControllerQml::~GSettingsControllerQml() {
@@ -34,17 +36,29 @@ GSettingsControllerQml* GSettingsControllerQml::instance() {
3436 return s_controllerInstance;
3537}
3638
37−void GSettingsControllerQml::registerSettingsObject(GSettingsQml *obj) {
38− m_registeredGSettings.append(obj);
39+QString GSettingsControllerQml::pictureUri() const
40+{
41+ return m_pictureUri;
42+}
43+
44+void GSettingsControllerQml::setPictureUri(const QString &str)
45+{
46+ if (str != m_pictureUri) {
47+ m_pictureUri = str;
48+ Q_EMIT pictureUriChanged(m_pictureUri);
49+ }
3950}
4051
41−void GSettingsControllerQml::unRegisterSettingsObject(GSettingsQml *obj) {
42− m_registeredGSettings.removeOne(obj);
52+QString GSettingsControllerQml::usageMode() const
53+{
54+ return m_usageMode;
4355}
4456
45−void GSettingsControllerQml::setPictureUri(const QString &str) {
46− Q_FOREACH (GSettingsQml *obj, m_registeredGSettings) {
47− obj->setPictureUri(str);
57+void GSettingsControllerQml::setUsageMode(const QString &usageMode)
58+{
59+ if (usageMode != m_usageMode) {
60+ m_usageMode = usageMode;
61+ Q_EMIT usageModeChanged(m_usageMode);
4862 }
4963}
5064
@@ -56,7 +70,7 @@ QByteArray GSettingsSchemaQml::id() const {
5670}
5771
5872void GSettingsSchemaQml::setId(const QByteArray &id) {
59− if (m_id.isEmpty()) {
73+ if (!m_id.isEmpty()) {
6074 qWarning("GSettings.schema.id may only be set on construction");
6175 return;
6276 }
@@ -69,7 +83,7 @@ QByteArray GSettingsSchemaQml::path() const {
6983}
7084
7185void GSettingsSchemaQml::setPath(const QByteArray &path) {
72− if (m_path.isEmpty()) {
86+ if (!m_path.isEmpty()) {
7387 qWarning("GSettings.schema.path may only be set on construction");
7488 return;
7589 }
@@ -77,26 +91,48 @@ void GSettingsSchemaQml::setPath(const QByteArray &path) {
7791 m_path = path;
7892}
7993
80−GSettingsQml::GSettingsQml(QObject *parent): QObject(parent) {
94+GSettingsQml::GSettingsQml(QObject *parent)
95+ : QObject(parent)
96+{
8197 m_schema = new GSettingsSchemaQml(this);
82− GSettingsControllerQml::instance()->registerSettingsObject(this);
83−}
84−
85−GSettingsQml::~GSettingsQml() {
86− GSettingsControllerQml::instance()->unRegisterSettingsObject(this);
98+ connect(GSettingsControllerQml::instance(), SIGNAL(pictureUriChanged(const QString &)),
99+ this, SIGNAL(pictureUriChanged(const QString &)));
100+ connect(GSettingsControllerQml::instance(), SIGNAL(usageModeChanged(const QString &)),
101+ this, SIGNAL(usageModeChanged(const QString &)));
87102}
88103
89104GSettingsSchemaQml * GSettingsQml::schema() const {
90105 return m_schema;
91106}
92107
93−QString GSettingsQml::pictureUri() const {
94− return m_pictureUri;
108+QString GSettingsQml::pictureUri() const
109+{
110+ if (m_schema->id() == "org.gnome.desktop.background") {
111+ return GSettingsControllerQml::instance()->pictureUri();
112+ } else {
113+ return "";
114+ }
95115}
96116
97−void GSettingsQml::setPictureUri(const QString &str) {
98− if (str != m_pictureUri) {
99− m_pictureUri = str;
100− Q_EMIT pictureUriChanged(m_pictureUri);
117+void GSettingsQml::setPictureUri(const QString &str)
118+{
119+ if (m_schema->id() == "org.gnome.desktop.background") {
120+ GSettingsControllerQml::instance()->setPictureUri(str);
121+ }
122+}
123+
124+QString GSettingsQml::usageMode() const
125+{
126+ if (m_schema->id() == "com.canonical.Unity8") {
127+ return GSettingsControllerQml::instance()->usageMode();
128+ } else {
129+ return "";
130+ }
131+}
132+
133+void GSettingsQml::setUsageMode(const QString &usageMode)
134+{
135+ if (m_schema->id() == "com.canonical.Unity8") {
136+ GSettingsControllerQml::instance()->setUsageMode(usageMode);
101137 }
102138}
tests/mocks/GSettings.1.0/fake_gsettings.h+16−6
@@ -46,25 +46,26 @@ class GSettingsQml: public QObject
4646
4747 Q_PROPERTY(GSettingsSchemaQml* schema READ schema NOTIFY schemaChanged)
4848 Q_PROPERTY(QString pictureUri READ pictureUri WRITE setPictureUri NOTIFY pictureUriChanged)
49+ Q_PROPERTY(QString usageMode READ usageMode WRITE setUsageMode NOTIFY usageModeChanged)
4950
5051public:
5152 GSettingsQml(QObject *parent = nullptr);
52− ~GSettingsQml();
5353
5454 GSettingsSchemaQml * schema() const;
5555 QString pictureUri() const;
56+ QString usageMode() const;
5657
5758 void setPictureUri(const QString &str);
59+ void setUsageMode(const QString &usageMode);
5860
5961Q_SIGNALS:
6062 void schemaChanged();
6163 void pictureUriChanged(const QString&);
64+ void usageModeChanged(const QString&);
6265
6366private:
6467 GSettingsSchemaQml* m_schema;
6568
66− QString m_pictureUri;
67−
6869 friend class GSettingsSchemaQml;
6970};
7071
@@ -76,13 +77,22 @@ public:
7677 static GSettingsControllerQml* instance();
7778 ~GSettingsControllerQml();
7879
79− void registerSettingsObject(GSettingsQml *obj);
80− void unRegisterSettingsObject(GSettingsQml *obj);
81− Q_INVOKABLE void setPictureUri(const QString &str);
80+ QString pictureUri() const;
81+ void setPictureUri(const QString &str);
82+
83+ QString usageMode() const;
84+ void setUsageMode(const QString &usageMode);
85+
86+Q_SIGNALS:
87+ void pictureUriChanged(const QString&);
88+ void usageModeChanged(const QString&);
8289
8390private:
8491 GSettingsControllerQml();
8592
93+ QString m_pictureUri;
94+ QString m_usageMode;
95+
8696 static GSettingsControllerQml* s_controllerInstance;
8797 QList<GSettingsQml *> m_registeredGSettings;
8898};
tests/mocks/GSettings.1.0/plugin.cpp−6
@@ -19,14 +19,8 @@
1919
2020#include <QtQml/qqml.h>
2121
22−static QObject* controllerProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
23−{
24− return GSettingsControllerQml::instance();
25−}
26−
2722void FakeGSettingsQmlPlugin::registerTypes(const char *uri)
2823{
29− qmlRegisterSingletonType<GSettingsControllerQml>(uri, 1, 0, "GSettingsController", controllerProvider);
3024 qmlRegisterType<GSettingsQml>(uri, 1, 0, "GSettings");
3125 qmlRegisterUncreatableType<GSettingsSchemaQml>(uri, 1, 0, "GSettingsSchema",
3226 "GSettingsSchema can only be used inside of a GSettings component");
tests/qmltests/tst_Shell.qml+43−3
@@ -64,6 +64,11 @@ Rectangle {
6464 }
6565 }
6666
67+ GSettings {
68+ id: unity8Settings
69+ schema.id: "com.canonical.Unity8"
70+ }
71+
6772 Item {
6873 anchors.left: root.left
6974 anchors.right: controls.left
@@ -84,6 +89,10 @@ Rectangle {
8489 width: units.gu(40)
8590 height: units.gu(71)
8691 }
92+ PropertyChanges {
93+ target: unity8Settings
94+ usageMode: "Staged"
95+ }
8796 },
8897 State {
8998 name: "tablet"
@@ -92,6 +101,22 @@ Rectangle {
92101 width: units.gu(100)
93102 height: units.gu(71)
94103 }
104+ PropertyChanges {
105+ target: unity8Settings
106+ usageMode: "Staged"
107+ }
108+ },
109+ State {
110+ name: "desktop"
111+ PropertyChanges {
112+ target: shellLoader
113+ width: units.gu(100)
114+ height: units.gu(71)
115+ }
116+ PropertyChanges {
117+ target: unity8Settings
118+ usageMode: "Windowed"
119+ }
95120 }
96121 ]
97122
@@ -990,6 +1015,21 @@ Rectangle {
9901015 compare(tutorial.running, false);
9911016 }
9921017
1018+ function test_tutorialDesktopMode_data() {
1019+ return [
1020+ {tag: "phone", formFactor: "phone", usingDrag: true},
1021+ {tag: "tablet", formFactor: "tablet", usingDrag: true},
1022+ {tag: "desktop", formFactor: "desktop", usingDrag: false},
1023+ ];
1024+ }
1025+ function test_tutorialDesktopMode(data) {
1026+ AccountsService.demoEdges = true;
1027+ loadShell(data.formFactor);
1028+
1029+ var tutorial = findChild(shell, "tutorial");
1030+ compare(tutorial.useEdgeDragArea, data.usingDrag);
1031+ }
1032+
9931033 function test_tapOnRightEdgeReachesApplicationSurface() {
9941034 loadShell("phone");
9951035 swipeAwayGreeter();
@@ -1084,11 +1124,11 @@ Rectangle {
10841124 {
10851125 var buttonShowDashHome = findChild(launcher, "buttonShowDashHome");
10861126 var startPos = buttonShowDashHome.mapToItem(shell,
1087− buttonShowDashHome.width * 0.8,
1088− buttonShowDashHome.height * 0.2);
1089− var endPos = buttonShowDashHome.mapToItem(shell,
10901127 buttonShowDashHome.width * 0.2,
10911128 buttonShowDashHome.height * 0.8);
1129+ var endPos = buttonShowDashHome.mapToItem(shell,
1130+ buttonShowDashHome.width * 0.8,
1131+ buttonShowDashHome.height * 0.2);
10921132 touchFlick(shell, startPos.x, startPos.y, endPos.x, endPos.y);
10931133 }
10941134