on xenial help sign in
Add new test for this branch, and fix up GSettings mock
4511c9eMichael Terry
tests/mocks/GSettings.1.0/fake_gsettings.cpp+58−22
@@ -20,7 +20,9 @@
20
20
21GSettingsControllerQml* GSettingsControllerQml::s_controllerInstance = 0;
21GSettingsControllerQml* GSettingsControllerQml::s_controllerInstance = 0;
22
22
23−GSettingsControllerQml::GSettingsControllerQml() {
23+GSettingsControllerQml::GSettingsControllerQml()
24+ : m_usageMode("Staged")
25+{
24}
26}
25
27
26GSettingsControllerQml::~GSettingsControllerQml() {
28GSettingsControllerQml::~GSettingsControllerQml() {
@@ -34,17 +36,29 @@ GSettingsControllerQml* GSettingsControllerQml::instance() {
34 return s_controllerInstance;
36 return s_controllerInstance;
35}
37}
36
38
39+QString GSettingsControllerQml::pictureUri() const
40+{
41+ return m_pictureUri;
42+}
43+
37−void GSettingsControllerQml::registerSettingsObject(GSettingsQml *obj) {
44+void GSettingsControllerQml::setPictureUri(const QString &str)
38− m_registeredGSettings.append(obj);
45+{
46+ if (str != m_pictureUri) {
47+ m_pictureUri = str;
48+ Q_EMIT pictureUriChanged(m_pictureUri);
49+ }
39}
50}
40
51
41−void GSettingsControllerQml::unRegisterSettingsObject(GSettingsQml *obj) {
52+QString GSettingsControllerQml::usageMode() const
42− m_registeredGSettings.removeOne(obj);
53+{
54+ return m_usageMode;
43}
55}
44
56
45−void GSettingsControllerQml::setPictureUri(const QString &str) {
57+void GSettingsControllerQml::setUsageMode(const QString &usageMode)
46− Q_FOREACH (GSettingsQml *obj, m_registeredGSettings) {
58+{
47− obj->setPictureUri(str);
59+ if (usageMode != m_usageMode) {
60+ m_usageMode = usageMode;
61+ Q_EMIT usageModeChanged(m_usageMode);
48 }
62 }
49}
63}
50
64
@@ -56,7 +70,7 @@ QByteArray GSettingsSchemaQml::id() const {
56}
70}
57
71
58void GSettingsSchemaQml::setId(const QByteArray &id) {
72void GSettingsSchemaQml::setId(const QByteArray &id) {
59− if (m_id.isEmpty()) {
73+ if (!m_id.isEmpty()) {
60 qWarning("GSettings.schema.id may only be set on construction");
74 qWarning("GSettings.schema.id may only be set on construction");
61 return;
75 return;
62 }
76 }
@@ -69,7 +83,7 @@ QByteArray GSettingsSchemaQml::path() const {
69}
83}
70
84
71void GSettingsSchemaQml::setPath(const QByteArray &path) {
85void GSettingsSchemaQml::setPath(const QByteArray &path) {
72− if (m_path.isEmpty()) {
86+ if (!m_path.isEmpty()) {
73 qWarning("GSettings.schema.path may only be set on construction");
87 qWarning("GSettings.schema.path may only be set on construction");
74 return;
88 return;
75 }
89 }
@@ -77,26 +91,48 @@ void GSettingsSchemaQml::setPath(const QByteArray &path) {
77 m_path = path;
91 m_path = path;
78}
92}
79
93
80−GSettingsQml::GSettingsQml(QObject *parent): QObject(parent) {
94+GSettingsQml::GSettingsQml(QObject *parent)
95+ : QObject(parent)
96+{
81 m_schema = new GSettingsSchemaQml(this);
97 m_schema = new GSettingsSchemaQml(this);
82− GSettingsControllerQml::instance()->registerSettingsObject(this);
98+ connect(GSettingsControllerQml::instance(), SIGNAL(pictureUriChanged(const QString &)),
83−}
99+ this, SIGNAL(pictureUriChanged(const QString &)));
84−
85−GSettingsQml::~GSettingsQml() {
86− GSettingsControllerQml::instance()->unRegisterSettingsObject(this);
100+ connect(GSettingsControllerQml::instance(), SIGNAL(usageModeChanged(const QString &)),
101+ this, SIGNAL(usageModeChanged(const QString &)));
87}
102}
88
103
89GSettingsSchemaQml * GSettingsQml::schema() const {
104GSettingsSchemaQml * GSettingsQml::schema() const {
90 return m_schema;
105 return m_schema;
91}
106}
92
107
93−QString GSettingsQml::pictureUri() const {
108+QString GSettingsQml::pictureUri() const
109+{
110+ if (m_schema->id() == "org.gnome.desktop.background") {
111+ return GSettingsControllerQml::instance()->pictureUri();
112+ } else {
94− return m_pictureUri;
113+ return "";
114+ }
95}
115}
96
116
97−void GSettingsQml::setPictureUri(const QString &str) {
117+void GSettingsQml::setPictureUri(const QString &str)
98− if (str != m_pictureUri) {
118+{
99− m_pictureUri = str;
119+ if (m_schema->id() == "org.gnome.desktop.background") {
100− Q_EMIT pictureUriChanged(m_pictureUri);
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);
101 }
137 }
102}
138}
tests/mocks/GSettings.1.0/fake_gsettings.h+16−6
@@ -46,25 +46,26 @@ class GSettingsQml: public QObject
46
46
47 Q_PROPERTY(GSettingsSchemaQml* schema READ schema NOTIFY schemaChanged)
47 Q_PROPERTY(GSettingsSchemaQml* schema READ schema NOTIFY schemaChanged)
48 Q_PROPERTY(QString pictureUri READ pictureUri WRITE setPictureUri NOTIFY pictureUriChanged)
48 Q_PROPERTY(QString pictureUri READ pictureUri WRITE setPictureUri NOTIFY pictureUriChanged)
49+ Q_PROPERTY(QString usageMode READ usageMode WRITE setUsageMode NOTIFY usageModeChanged)
49
50
50public:
51public:
51 GSettingsQml(QObject *parent = nullptr);
52 GSettingsQml(QObject *parent = nullptr);
52− ~GSettingsQml();
53
53
54 GSettingsSchemaQml * schema() const;
54 GSettingsSchemaQml * schema() const;
55 QString pictureUri() const;
55 QString pictureUri() const;
56+ QString usageMode() const;
56
57
57 void setPictureUri(const QString &str);
58 void setPictureUri(const QString &str);
59+ void setUsageMode(const QString &usageMode);
58
60
59Q_SIGNALS:
61Q_SIGNALS:
60 void schemaChanged();
62 void schemaChanged();
61 void pictureUriChanged(const QString&);
63 void pictureUriChanged(const QString&);
64+ void usageModeChanged(const QString&);
62
65
63private:
66private:
64 GSettingsSchemaQml* m_schema;
67 GSettingsSchemaQml* m_schema;
65
68
66− QString m_pictureUri;
67−
68 friend class GSettingsSchemaQml;
69 friend class GSettingsSchemaQml;
69};
70};
70
71
@@ -76,13 +77,22 @@ public:
76 static GSettingsControllerQml* instance();
77 static GSettingsControllerQml* instance();
77 ~GSettingsControllerQml();
78 ~GSettingsControllerQml();
78
79
79− void registerSettingsObject(GSettingsQml *obj);
80+ QString pictureUri() const;
80− void unRegisterSettingsObject(GSettingsQml *obj);
81− Q_INVOKABLE void setPictureUri(const QString &str);
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&);
82
89
83private:
90private:
84 GSettingsControllerQml();
91 GSettingsControllerQml();
85
92
93+ QString m_pictureUri;
94+ QString m_usageMode;
95+
86 static GSettingsControllerQml* s_controllerInstance;
96 static GSettingsControllerQml* s_controllerInstance;
87 QList<GSettingsQml *> m_registeredGSettings;
97 QList<GSettingsQml *> m_registeredGSettings;
88};
98};
tests/mocks/GSettings.1.0/plugin.cpp−6
@@ -19,14 +19,8 @@
19
19
20#include <QtQml/qqml.h>
20#include <QtQml/qqml.h>
21
21
22−static QObject* controllerProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
23−{
24− return GSettingsControllerQml::instance();
25−}
26−
27void FakeGSettingsQmlPlugin::registerTypes(const char *uri)
22void FakeGSettingsQmlPlugin::registerTypes(const char *uri)
28{
23{
29− qmlRegisterSingletonType<GSettingsControllerQml>(uri, 1, 0, "GSettingsController", controllerProvider);
30 qmlRegisterType<GSettingsQml>(uri, 1, 0, "GSettings");
24 qmlRegisterType<GSettingsQml>(uri, 1, 0, "GSettings");
31 qmlRegisterUncreatableType<GSettingsSchemaQml>(uri, 1, 0, "GSettingsSchema",
25 qmlRegisterUncreatableType<GSettingsSchemaQml>(uri, 1, 0, "GSettingsSchema",
32 "GSettingsSchema can only be used inside of a GSettings component");
26 "GSettingsSchema can only be used inside of a GSettings component");
tests/qmltests/tst_Shell.qml+43−3
@@ -64,6 +64,11 @@ Rectangle {
64 }
64 }
65 }
65 }
66
66
67+ GSettings {
68+ id: unity8Settings
69+ schema.id: "com.canonical.Unity8"
70+ }
71+
67 Item {
72 Item {
68 anchors.left: root.left
73 anchors.left: root.left
69 anchors.right: controls.left
74 anchors.right: controls.left
@@ -84,6 +89,10 @@ Rectangle {
84 width: units.gu(40)
89 width: units.gu(40)
85 height: units.gu(71)
90 height: units.gu(71)
86 }
91 }
92+ PropertyChanges {
93+ target: unity8Settings
94+ usageMode: "Staged"
95+ }
87 },
96 },
88 State {
97 State {
89 name: "tablet"
98 name: "tablet"
@@ -92,6 +101,22 @@ Rectangle {
92 width: units.gu(100)
101 width: units.gu(100)
93 height: units.gu(71)
102 height: units.gu(71)
94 }
103 }
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+ }
95 }
120 }
96 ]
121 ]
97
122
@@ -990,6 +1015,21 @@ Rectangle {
990 compare(tutorial.running, false);
1015 compare(tutorial.running, false);
991 }
1016 }
992
1017
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+
993 function test_tapOnRightEdgeReachesApplicationSurface() {
1033 function test_tapOnRightEdgeReachesApplicationSurface() {
994 loadShell("phone");
1034 loadShell("phone");
995 swipeAwayGreeter();
1035 swipeAwayGreeter();
@@ -1084,11 +1124,11 @@ Rectangle {
1084 {
1124 {
1085 var buttonShowDashHome = findChild(launcher, "buttonShowDashHome");
1125 var buttonShowDashHome = findChild(launcher, "buttonShowDashHome");
1086 var startPos = buttonShowDashHome.mapToItem(shell,
1126 var startPos = buttonShowDashHome.mapToItem(shell,
1087− buttonShowDashHome.width * 0.8,
1088− buttonShowDashHome.height * 0.2);
1089− var endPos = buttonShowDashHome.mapToItem(shell,
1090 buttonShowDashHome.width * 0.2,
1127 buttonShowDashHome.width * 0.2,
1091 buttonShowDashHome.height * 0.8);
1128 buttonShowDashHome.height * 0.8);
1129+ var endPos = buttonShowDashHome.mapToItem(shell,
1130+ buttonShowDashHome.width * 0.8,
1131+ buttonShowDashHome.height * 0.2);
1092 touchFlick(shell, startPos.x, startPos.y, endPos.x, endPos.y);
1132 touchFlick(shell, startPos.x, startPos.y, endPos.x, endPos.y);
1093 }
1133 }
1094
1134