on xenial help sign in
Drop mock property points for cleanliness
commitf0d81d5557979ec6f5b22bf4dd897dcb2b1f60d7 authorMichael Terry <michael.terry@canonical.com> dateWed 6 Apr 2016, 10:22 (11 years ago) parent0093b89
4 files changed+73−28
qml/OrientedShell.qml+18−10 tests/mocks/GSettings.1.0/fake_gsettings.cpp+36−1 tests/mocks/GSettings.1.0/fake_gsettings.h+10−1 tests/qmltests/tst_OrientedShell.qml+9−16
qml/OrientedShell.qml+18−10
@@ -57,9 +57,17 @@ Rectangle {
5757 invertedPortrait: deviceConfiguration.invertedPortraitOrientation
5858 }
5959 }
60− // to be overwritten by tests
61− property var unity8Settings: GSettings { schema.id: "com.canonical.Unity8" }
62− property var oskSettings: GSettings { schema.id: "com.canonical.keyboard.maliit" }
60+
61+ GSettings {
62+ id: unity8Settings
63+ schema.id: "com.canonical.Unity8"
64+ }
65+
66+ GSettings {
67+ id: oskSettings
68+ objectName: "oskSettings"
69+ schema.id: "com.canonical.keyboard.maliit"
70+ }
6371
6472 property int physicalOrientation: Screen.orientation
6573 property bool orientationLocked: OrientationLock.enabled
@@ -93,24 +101,24 @@ Rectangle {
93101 onPointerInputDevicesChanged: calculateUsageMode()
94102
95103 function calculateUsageMode() {
96− if (root.unity8Settings.usageMode === undefined)
104+ if (unity8Settings.usageMode === undefined)
97105 return; // gsettings isn't loaded yet, we'll try again in Component.onCompleted
98106
99− console.log("Pointer input devices changed:", pointerInputDevices, "current mode:", root.unity8Settings.usageMode, "old device count", miceModel.oldCount + touchPadModel.oldCount)
100− if (root.unity8Settings.usageMode === "Windowed") {
107+ console.log("Pointer input devices changed:", pointerInputDevices, "current mode:", unity8Settings.usageMode, "old device count", miceModel.oldCount + touchPadModel.oldCount)
108+ if (unity8Settings.usageMode === "Windowed") {
101109 if (pointerInputDevices === 0) {
102110 // All pointer devices have been unplugged. Move to staged.
103− root.unity8Settings.usageMode = "Staged";
111+ unity8Settings.usageMode = "Staged";
104112 }
105113 } else {
106114 var longEdgeWidth = Math.max(root.width, root.height)
107115 if (longEdgeWidth > units.gu(90)){
108116 if (pointerInputDevices > 0 && pointerInputDevices > miceModel.oldCount + touchPadModel.oldCount) {
109− root.unity8Settings.usageMode = "Windowed";
117+ unity8Settings.usageMode = "Windowed";
110118 }
111119 } else {
112120 // Make sure we initialize to something sane
113− root.unity8Settings.usageMode = "Staged";
121+ unity8Settings.usageMode = "Staged";
114122 }
115123 }
116124 miceModel.oldCount = miceModel.count;
@@ -256,7 +264,7 @@ Rectangle {
256264 forceOSKEnabled
257265
258266 usageScenario: {
259− if (root.unity8Settings.usageMode === "Windowed") {
267+ if (unity8Settings.usageMode === "Windowed") {
260268 return "desktop";
261269 } else {
262270 if (deviceConfiguration.category === "phone") {
tests/mocks/GSettings.1.0/fake_gsettings.cpp+36−1
@@ -21,7 +21,8 @@
2121GSettingsControllerQml* GSettingsControllerQml::s_controllerInstance = 0;
2222
2323GSettingsControllerQml::GSettingsControllerQml()
24− : m_usageMode("Staged")
24+ : m_disableHeight(false)
25+ , m_usageMode("Staged")
2526 , m_autohideLauncher(false)
2627 , m_launcherWidth(8)
2728{
@@ -38,6 +39,19 @@ GSettingsControllerQml* GSettingsControllerQml::instance() {
3839 return s_controllerInstance;
3940}
4041
42+bool GSettingsControllerQml::disableHeight() const
43+{
44+ return m_disableHeight;
45+}
46+
47+void GSettingsControllerQml::setDisableHeight(bool val)
48+{
49+ if (val != m_disableHeight) {
50+ m_disableHeight = val;
51+ Q_EMIT disableHeightChanged();
52+ }
53+}
54+
4155QString GSettingsControllerQml::pictureUri() const
4256{
4357 return m_pictureUri;
@@ -162,6 +176,10 @@ void GSettingsQml::componentComplete()
162176 // values until we are completed loading.
163177 m_valid = true;
164178
179+ // FIXME: We should make this dynamic, instead of hard-coding all possible
180+ // properties in one object. We should create properties based on the schema.
181+ connect(GSettingsControllerQml::instance(), &GSettingsControllerQml::disableHeightChanged,
182+ this, &GSettingsQml::disableHeightChanged);
165183 connect(GSettingsControllerQml::instance(), &GSettingsControllerQml::pictureUriChanged,
166184 this, &GSettingsQml::pictureUriChanged);
167185 connect(GSettingsControllerQml::instance(), &GSettingsControllerQml::usageModeChanged,
@@ -175,6 +193,7 @@ void GSettingsQml::componentComplete()
175193 connect(GSettingsControllerQml::instance(), &GSettingsControllerQml::launcherWidthChanged,
176194 this, &GSettingsQml::launcherWidthChanged);
177195
196+ Q_EMIT disableHeightChanged();
178197 Q_EMIT pictureUriChanged();
179198 Q_EMIT usageModeChanged();
180199 Q_EMIT lockedOutTimeChanged();
@@ -187,6 +206,22 @@ GSettingsSchemaQml * GSettingsQml::schema() const {
187206 return m_schema;
188207}
189208
209+QVariant GSettingsQml::disableHeight() const
210+{
211+ if (m_valid && m_schema->id() == "com.canonical.keyboard.maliit") {
212+ return GSettingsControllerQml::instance()->disableHeight();
213+ } else {
214+ return QVariant();
215+ }
216+}
217+
218+void GSettingsQml::setDisableHeight(const QVariant &val)
219+{
220+ if (m_valid && m_schema->id() == "com.canonical.keyboard.maliit") {
221+ GSettingsControllerQml::instance()->setDisableHeight(val.toBool());
222+ }
223+}
224+
190225QVariant GSettingsQml::pictureUri() const
191226{
192227 if (m_valid && m_schema->id() == "org.gnome.desktop.background") {
tests/mocks/GSettings.1.0/fake_gsettings.h+10−1
@@ -49,6 +49,7 @@ class GSettingsQml: public QObject, public QQmlParserStatus
4949 Q_INTERFACES(QQmlParserStatus)
5050
5151 Q_PROPERTY(GSettingsSchemaQml* schema READ schema NOTIFY schemaChanged)
52+ Q_PROPERTY(QVariant disableHeight READ disableHeight WRITE setDisableHeight NOTIFY disableHeightChanged)
5253 Q_PROPERTY(QVariant pictureUri READ pictureUri WRITE setPictureUri NOTIFY pictureUriChanged)
5354 Q_PROPERTY(QVariant usageMode READ usageMode WRITE setUsageMode NOTIFY usageModeChanged)
5455 Q_PROPERTY(QVariant lockedOutTime READ lockedOutTime WRITE setLockedOutTime NOTIFY lockedOutTimeChanged)
@@ -63,6 +64,7 @@ public:
6364 void componentComplete();
6465
6566 GSettingsSchemaQml * schema() const;
67+ QVariant disableHeight() const;
6668 QVariant pictureUri() const;
6769 QVariant usageMode() const;
6870 QVariant lockedOutTime() const;
@@ -70,6 +72,7 @@ public:
7072 QVariant autohideLauncher() const;
7173 QVariant launcherWidth() const;
7274
75+ void setDisableHeight(const QVariant &val);
7376 void setPictureUri(const QVariant &str);
7477 void setUsageMode(const QVariant &usageMode);
7578 void setLockedOutTime(const QVariant &timestamp);
@@ -78,6 +81,7 @@ public:
7881 void setLauncherWidth(const QVariant &launcherWidth);
7982
8083Q_SIGNALS:
84+ void disableHeightChanged();
8185 void schemaChanged();
8286 void pictureUriChanged();
8387 void usageModeChanged();
@@ -101,6 +105,9 @@ public:
101105 static GSettingsControllerQml* instance();
102106 ~GSettingsControllerQml();
103107
108+ bool disableHeight() const;
109+ Q_INVOKABLE void setDisableHeight(bool val);
110+
104111 QString pictureUri() const;
105112 Q_INVOKABLE void setPictureUri(const QString &str);
106113
@@ -120,8 +127,9 @@ public:
120127 Q_INVOKABLE void setLauncherWidth(int launcherWidth);
121128
122129Q_SIGNALS:
130+ void disableHeightChanged();
123131 void pictureUriChanged(const QString&);
124− void usageModeChanged(const QString &usageMode);
132+ void usageModeChanged(const QString&);
125133 void lockedOutTimeChanged(qint64 timestamp);
126134 void lifecycleExemptAppidsChanged(const QStringList&);
127135 void autohideLauncherChanged(bool autohideLauncher);
@@ -130,6 +138,7 @@ Q_SIGNALS:
130138private:
131139 GSettingsControllerQml();
132140
141+ bool m_disableHeight;
133142 QString m_pictureUri;
134143 QString m_usageMode;
135144 qint64 m_lockedOutTime;
tests/qmltests/tst_OrientedShell.qml+9−16
@@ -45,17 +45,17 @@ Rectangle {
4545 property int savedOrientation
4646 }
4747
48− Connections {
49− target: GSettingsController
48+ GSettings {
49+ id: unity8Settings
50+ schema.id: "com.canonical.Unity8"
5051 onUsageModeChanged: {
5152 usageModeSelector.selectedIndex = usageModeSelector.model.indexOf(usageMode)
5253 }
5354 }
5455
55− QtObject{
56− id: mockOskSettings
57− property bool stayHidden: false
58− property bool disableHeight: false
56+ GSettings {
57+ id: oskSettings
58+ schema.id: "com.canonical.keyboard.maliit"
5959 }
6060
6161 InputDeviceModel {
@@ -157,7 +157,6 @@ Rectangle {
157157 sourceComponent: Component {
158158 OrientedShell {
159159 anchors.fill: parent
160− oskSettings: mockOskSettings
161160 physicalOrientation: root.physicalOrientation0
162161 orientationLocked: orientationLockedCheckBox.checked
163162 orientationLock: mockOrientationLock
@@ -1087,7 +1086,7 @@ Rectangle {
10871086
10881087 tryCompare(shell, "usageScenario", "phone");
10891088 tryCompare(inputMethod, "enabled", true);
1090− tryCompare(mockOskSettings, "disableHeight", false);
1089+ tryCompare(oskSettings, "disableHeight", false);
10911090
10921091 if (data.kbd) {
10931092 MockInputDeviceBackend.addMockDevice("/kbd0", InputInfo.Keyboard);
@@ -1098,14 +1097,7 @@ Rectangle {
10981097
10991098 tryCompare(shell, "usageScenario", data.expectedMode);
11001099 tryCompare(inputMethod, "enabled", data.oskExpected);
1101− tryCompare(mockOskSettings, "disableHeight", data.expectedMode == "desktop" || data.kbd);
1102−
1103− if (data.kbd) {
1104− MockInputDeviceBackend.removeDevice("/kbd0");
1105− }
1106− if (data.mouse) {
1107− MockInputDeviceBackend.removeDevice("/mouse0");
1108− }
1100+ tryCompare(oskSettings, "disableHeight", data.expectedMode == "desktop" || data.kbd);
11091101
11101102 // Restore width
11111103 orientedShellLoader.width = oldWidth;
@@ -1154,6 +1146,7 @@ Rectangle {
11541146 // Load shell, and have it pick desktop
11551147 loadShell("desktop");
11561148 compare(shell.usageScenario, "desktop");
1149+ compare(unity8Settings.usageMode, "Windowed");
11571150 }
11581151
11591152 function test_overrideWindowed() {