Merge lp:~jonas-drange/ubuntu-system-settings/1211804-allow-technology-preference into lp:ubuntu-system-settings
- 1211804-allow-technology-preference
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Ken VanDine |
Approved revision: | 761 |
Merged at revision: | 791 |
Proposed branch: | lp:~jonas-drange/ubuntu-system-settings/1211804-allow-technology-preference |
Merge into: | lp:ubuntu-system-settings |
Prerequisite: | lp:~ken-vandine/ubuntu-system-settings/libqofono |
Diff against target: |
570 lines (+365/-51) 7 files modified
plugins/about/PageComponent.qml (+1/-1) plugins/cellular/CMakeLists.txt (+1/-0) plugins/cellular/PageComponent.qml (+48/-32) plugins/cellular/rdosettings-helpers.js (+90/-0) tests/autopilot/ubuntu_system_settings/__init__.py (+3/-2) tests/autopilot/ubuntu_system_settings/tests/__init__.py (+70/-14) tests/autopilot/ubuntu_system_settings/tests/test_cellular.py (+152/-2) |
To merge this branch: | bzr merge lp:~jonas-drange/ubuntu-system-settings/1211804-allow-technology-preference |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Needs Fixing | |
Ken VanDine | Approve | ||
Review via email: mp+226125@code.launchpad.net |
This proposal supersedes a proposal from 2014-06-04.
Commit message
use libqofono bindings to allow for technology preference changes
Description of the change
Hi,
this uses new libqofono bindings to allow a user to change 1) modem online/offline and 2) the Radio Technology Preference.
These two settings is combined in one ListItems.
Tests are also added for happy paths, but also for some edge cases that could potentially break the UX.
Thanks.
Brendan Donegan (brendan-donegan) wrote : Posted in a previous version of this proposal | # |
- 755. By Jonas G. Drange
-
cleanup
- 756. By Jonas G. Drange
-
removing unused gsettings key
- 757. By Jonas G. Drange
-
merge prereq
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:756
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
http://
Executed test runs:
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:757
http://
Executed test runs:
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Ken VanDine (ken-vandine) wrote : | # |
See comments inline
- 758. By Jonas G. Drange
-
log -> warn
- 759. By Jonas G. Drange
-
more logging
- 760. By Jonas G. Drange
-
merge prereq
- 761. By Jonas G. Drange
-
uncommenting tests
Jonas G. Drange (jonas-drange) wrote : | # |
Addressed inline comments.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:761
http://
Executed test runs:
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:761
http://
Executed test runs:
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Ken VanDine (ken-vandine) wrote : | # |
Looks good, the CI failure is an unrelated networking error.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:761
http://
Executed test runs:
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:761
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:761
http://
Executed test runs:
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'plugins/about/PageComponent.qml' |
2 | --- plugins/about/PageComponent.qml 2014-07-10 14:01:58 +0000 |
3 | +++ plugins/about/PageComponent.qml 2014-07-10 14:01:58 +0000 |
4 | @@ -54,7 +54,7 @@ |
5 | id: sim |
6 | modemPath: manager.modems[0] |
7 | } |
8 | - |
9 | + |
10 | Flickable { |
11 | id: scrollWidget |
12 | anchors.fill: parent |
13 | |
14 | === modified file 'plugins/cellular/CMakeLists.txt' |
15 | --- plugins/cellular/CMakeLists.txt 2014-07-08 16:17:02 +0000 |
16 | +++ plugins/cellular/CMakeLists.txt 2014-07-10 14:01:58 +0000 |
17 | @@ -6,6 +6,7 @@ |
18 | Hotspot.qml |
19 | HotspotSetup.qml |
20 | PageComponent.qml |
21 | + rdosettings-helpers.js |
22 | ) |
23 | |
24 | |
25 | |
26 | === modified file 'plugins/cellular/PageComponent.qml' |
27 | --- plugins/cellular/PageComponent.qml 2014-07-10 14:01:58 +0000 |
28 | +++ plugins/cellular/PageComponent.qml 2014-07-10 14:01:58 +0000 |
29 | @@ -24,12 +24,19 @@ |
30 | import Ubuntu.Components.ListItems 0.1 as ListItem |
31 | import MeeGo.QOfono 0.2 |
32 | import QMenuModel 0.1 |
33 | +import "rdosettings-helpers.js" as RSHelpers |
34 | |
35 | ItemPage { |
36 | id: root |
37 | title: i18n.tr("Cellular") |
38 | objectName: "cellularPage" |
39 | |
40 | + OfonoRadioSettings { |
41 | + id: rdoSettings |
42 | + modemPath: manager.modems[0] |
43 | + onTechnologyPreferenceChanged: RSHelpers.preferenceChanged(preference); |
44 | + } |
45 | + |
46 | QDBusActionGroup { |
47 | id: actionGroup |
48 | busType: 1 |
49 | @@ -49,7 +56,7 @@ |
50 | |
51 | OfonoSimManager { |
52 | id: sim |
53 | - modemPath: manager.modems[0] |
54 | + modemPath: manager.modems[0] |
55 | } |
56 | |
57 | OfonoNetworkRegistration { |
58 | @@ -70,6 +77,13 @@ |
59 | OfonoConnMan { |
60 | id: connMan |
61 | modemPath: manager.modems[0] |
62 | + powered: techPrefSelector.selectedIndex !== 0 |
63 | + onPoweredChanged: RSHelpers.poweredChanged(powered); |
64 | + } |
65 | + |
66 | + OfonoModem { |
67 | + id: modem |
68 | + modemPath: manager.modems[0] |
69 | } |
70 | |
71 | Flickable { |
72 | @@ -82,51 +96,53 @@ |
73 | anchors.left: parent.left |
74 | anchors.right: parent.right |
75 | |
76 | - /* TODO: use selector once ofono supports those options (bug #1211804) */ |
77 | + ListModel { |
78 | + id: techPrefModel |
79 | + ListElement { name: "Off"; key: "off" } |
80 | + ListElement { name: "2G only (saves battery)"; key: "gsm"; } |
81 | + ListElement { name: "2G/3G/4G (faster)"; key: "any"; } |
82 | + } |
83 | + |
84 | + Component { |
85 | + id: techPrefDelegate |
86 | + OptionSelectorDelegate { text: i18n.tr(name); } |
87 | + } |
88 | + |
89 | ListItem.ItemSelector { |
90 | - id: dataTypeSelector |
91 | + id: techPrefSelector |
92 | + objectName: "technologyPreferenceSelector" |
93 | expanded: true |
94 | - visible: showAllUI |
95 | + delegate: techPrefDelegate |
96 | + model: techPrefModel |
97 | text: i18n.tr("Cellular data:") |
98 | - model: [i18n.tr("Off"), |
99 | - i18n.tr("2G only (saves battery)"), |
100 | - i18n.tr("2G/3G/4G (faster)")] |
101 | - selectedIndex: !connMan.powered ? 0 : 2 |
102 | - onSelectedIndexChanged: { |
103 | - if (selectedIndex == 0) |
104 | - connMan.powered = false; |
105 | - else |
106 | - connMan.powered = true; |
107 | + |
108 | + // technologyPreference "" is not valid, assume sim locked or data unavailable |
109 | + enabled: rdoSettings.technologyPreference !== "" |
110 | + selectedIndex: { |
111 | + var pref = rdoSettings.technologyPreference; |
112 | + // make nothing selected if the string from OfonoRadioSettings is empty |
113 | + if (pref === "") { |
114 | + console.warn("Disabling TechnologyPreference item selector due to empty TechnologyPreference"); |
115 | + return -1; |
116 | + } else { |
117 | + // normalizeKey turns "lte" and "umts" into "any" |
118 | + return RSHelpers.keyToIndex(RSHelpers.normalizeKey(pref)); |
119 | + } |
120 | } |
121 | + onDelegateClicked: RSHelpers.delegateClicked(index) |
122 | } |
123 | |
124 | ListItem.Standard { |
125 | - text: i18n.tr("Cellular data") |
126 | - visible: !showAllUI |
127 | - control: Switch { |
128 | - id: dataSwitch |
129 | - checked: connMan.powered |
130 | - onClicked: connMan.powered = checked |
131 | - } |
132 | - } |
133 | - |
134 | - ListItem.Standard { |
135 | id: dataRoamingItem |
136 | + objectName: "dataRoamingSwitch" |
137 | text: i18n.tr("Data roaming") |
138 | - enabled: dataSwitch.checked |
139 | + // sensitive to data type, and disabled if "Off" is selected |
140 | + enabled: techPrefSelector.selectedIndex !== 0 |
141 | control: Switch { |
142 | id: dataRoamingControl |
143 | checked: connMan.roamingAllowed |
144 | onClicked: connMan.roamingAllowed = checked |
145 | } |
146 | - onEnabledChanged: { |
147 | - if (!enabled) |
148 | - dataRoamingControl.checked = false |
149 | - else |
150 | - dataRoamingControl.checked = Qt.binding(function() { |
151 | - return connMan.roamingAllowed |
152 | - }) |
153 | - } |
154 | } |
155 | |
156 | ListItem.SingleValue { |
157 | |
158 | === added file 'plugins/cellular/rdosettings-helpers.js' |
159 | --- plugins/cellular/rdosettings-helpers.js 1970-01-01 00:00:00 +0000 |
160 | +++ plugins/cellular/rdosettings-helpers.js 2014-07-10 14:01:58 +0000 |
161 | @@ -0,0 +1,90 @@ |
162 | + |
163 | +/* return index of key k using data in techPrefModel */ |
164 | +function keyToIndex (k) { |
165 | + console.warn('keyToIndex key:', k) |
166 | + for (var i=0; i < techPrefModel.count; i++) { |
167 | + if (indexToKey(i) === k) { |
168 | + return i; |
169 | + } |
170 | + } |
171 | + // we did not find a suitable ui item |
172 | + console.warn('keyToIndex did not find matching index for key', k); |
173 | + return -1; |
174 | +} |
175 | + |
176 | +/* return key of index i using data in techPrefModel */ |
177 | +function indexToKey (i) { |
178 | + return techPrefModel.get(i).key; |
179 | +} |
180 | + |
181 | +/* return currently selected key or null if none selected */ |
182 | +function getSelectedKey () { |
183 | + var i = techPrefSelector.selectedIndex; |
184 | + var model = techPrefModel.get(i); |
185 | + return model ? model.key : null; |
186 | +} |
187 | + |
188 | +/* return key or 'any' if key matches 'lte' or 'umts' |
189 | +The UI currently does not support umts/lte only |
190 | +*/ |
191 | +function normalizeKey (k) { |
192 | + if (k === 'lte' || k === 'umts') { |
193 | + console.warn("normalizeKey saw", k); |
194 | + return 'any'; |
195 | + } else { |
196 | + return k; |
197 | + } |
198 | +} |
199 | + |
200 | +/* handler for when RadioSettings TechnologyPreference changes */ |
201 | +function preferenceChanged (preference) { |
202 | + var i = techPrefSelector.selectedIndex; |
203 | + var rdoKey = rdoSettings.technologyPreference; |
204 | + var selKey = getSelectedKey(); |
205 | + |
206 | + // if preference changes, but the user has chosen one already, |
207 | + // make sure the user's setting is respected |
208 | + if (i > 0) { |
209 | + console.warn('Overriding RadioSettings TechnologyPreference signal', preference, 'with user selection', selKey); |
210 | + rdoSettings.technologyPreference = selKey; |
211 | + return; |
212 | + } |
213 | + |
214 | + // if the pref changes and the modem is on, |
215 | + // normlize and update the UI |
216 | + if (connMan.powered) { |
217 | + techPrefSelector.selectedIndex = keyToIndex(normalizeKey(rdoKey)); |
218 | + } else { |
219 | + // if the modem is off, |
220 | + // just normalize |
221 | + rdoSettings.technologyPreference = normalizeKey(rdoKey); |
222 | + } |
223 | + console.warn('Modem', connMan.powered ? 'online' : 'offline', 'TechnologyPreference', rdoKey); |
224 | +} |
225 | + |
226 | +/* handler for when ConnectionManager powered changes */ |
227 | +function poweredChanged (powered) { |
228 | + var rdoKey = rdoSettings.technologyPreference; |
229 | + if (powered) { |
230 | + if (rdoKey === '') { |
231 | + console.warn('Modem came online but TechnologyPreference is empty'); |
232 | + return; |
233 | + } else { |
234 | + console.warn('Modem came online, TechnologyPreference', rdoKey); |
235 | + techPrefSelector.selectedIndex = keyToIndex(normalizeKey(rdoKey)); |
236 | + } |
237 | + } else { |
238 | + console.warn('Modem went offline'); |
239 | + techPrefSelector.selectedIndex = 0; |
240 | + } |
241 | +} |
242 | + |
243 | +/* handler for when user clicks the TechnologyPreference item selector */ |
244 | +function delegateClicked (index) { |
245 | + console.warn('delegateClicked', index); |
246 | + // if the user selects a TechnologyPreference, update RadioSettings |
247 | + if (index > 0) { |
248 | + rdoSettings.technologyPreference = indexToKey(index); |
249 | + console.warn('delegateClicked setting TechnologyPreference to', indexToKey(index)); |
250 | + } |
251 | +} |
252 | |
253 | === modified file 'tests/autopilot/ubuntu_system_settings/__init__.py' |
254 | --- tests/autopilot/ubuntu_system_settings/__init__.py 2014-06-11 09:36:44 +0000 |
255 | +++ tests/autopilot/ubuntu_system_settings/__init__.py 2014-07-10 14:01:58 +0000 |
256 | @@ -65,7 +65,8 @@ |
257 | app = testobj.launch_test_application( |
258 | *params, |
259 | app_type='qt', |
260 | - emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase) |
261 | + emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase, |
262 | + capture_output=True) |
263 | |
264 | return app |
265 | |
266 | @@ -110,7 +111,7 @@ |
267 | |
268 | @property |
269 | def cellular_page(self): |
270 | - """ Return 'About' page """ |
271 | + """ Return 'Cellular' page """ |
272 | return self.select_single(objectName='cellularPage') |
273 | |
274 | @property |
275 | |
276 | === modified file 'tests/autopilot/ubuntu_system_settings/tests/__init__.py' |
277 | --- tests/autopilot/ubuntu_system_settings/tests/__init__.py 2014-06-11 09:36:44 +0000 |
278 | +++ tests/autopilot/ubuntu_system_settings/tests/__init__.py 2014-07-10 14:01:58 +0000 |
279 | @@ -22,6 +22,9 @@ |
280 | import dbusmock |
281 | import subprocess |
282 | |
283 | +CONNMAN_IFACE = 'org.ofono.ConnectionManager' |
284 | +RDO_IFACE = 'org.ofono.RadioSettings' |
285 | + |
286 | |
287 | class UbuntuSystemSettingsTestCase(UbuntuUIToolkitAppTestCase): |
288 | """ Base class for Ubuntu System Settings """ |
289 | @@ -79,18 +82,28 @@ |
290 | dbusmock.DBusTestCase): |
291 | """ Class for cellular tests which sets up an Ofono mock """ |
292 | |
293 | - @classmethod |
294 | - def setUpClass(klass): |
295 | - klass.start_system_bus() |
296 | - klass.dbus_con = klass.get_dbus(True) |
297 | - # Add a mock Ofono environment so we get consistent results |
298 | - (klass.p_mock, klass.obj_ofono) = klass.spawn_server_template( |
299 | - 'ofono', stdout=subprocess.PIPE) |
300 | - klass.dbusmock = dbus.Interface(klass.obj_ofono, dbusmock.MOCK_IFACE) |
301 | - |
302 | - def setUp(self, panel=None): |
303 | - self.obj_ofono.Reset() |
304 | - # Add an available carrier |
305 | + modem_powered = True |
306 | + technology_preference = 'gsm' |
307 | + |
308 | + def mock_connection_manager(self): |
309 | + self.modem_0.AddProperty(CONNMAN_IFACE, 'Powered', |
310 | + self.modem_powered) |
311 | + |
312 | + self.modem_0.AddMethods( |
313 | + CONNMAN_IFACE, |
314 | + [ |
315 | + ( |
316 | + 'GetProperties', '', 'a{sv}', |
317 | + 'ret = self.GetAll("%s")' % CONNMAN_IFACE), |
318 | + ( |
319 | + 'SetProperty', 'sv', '', |
320 | + 'self.Set("IFACE", args[0], args[1]); ' |
321 | + 'self.EmitSignal("IFACE", "PropertyChanged", "sv",\ |
322 | + [args[0], args[1]])'.replace( |
323 | + "IFACE", CONNMAN_IFACE)), |
324 | + ]) |
325 | + |
326 | + def mock_carriers(self): |
327 | self.dbusmock.AddObject( |
328 | '/ril_0/operator/op2', |
329 | 'org.ofono.NetworkOperator', |
330 | @@ -124,6 +137,50 @@ |
331 | ('Register', '', '', ''), |
332 | ] |
333 | ) |
334 | + |
335 | + def mock_radio_settings(self): |
336 | + modem_interfaces = self.modem_0.GetProperties()['Interfaces'] |
337 | + modem_interfaces.append(RDO_IFACE) |
338 | + self.modem_0.AddProperty( |
339 | + RDO_IFACE, 'TechnologyPreference', self.technology_preference) |
340 | + self.modem_0.SetProperty('Interfaces', modem_interfaces) |
341 | + self.modem_0.AddMethods( |
342 | + RDO_IFACE, |
343 | + [ |
344 | + ( |
345 | + 'GetProperties', '', 'a{sv}', |
346 | + 'ret = self.GetAll("%s")' |
347 | + % RDO_IFACE), |
348 | + ( |
349 | + 'SetProperty', 'sv', '', |
350 | + 'self.Set("IFACE", args[0], args[1]); ' |
351 | + 'self.EmitSignal("IFACE",\ |
352 | + "PropertyChanged", "sv", [args[0], args[1]])'.replace( |
353 | + 'IFACE', RDO_IFACE)), |
354 | + ]) |
355 | + |
356 | + @classmethod |
357 | + def setUpClass(klass): |
358 | + klass.start_system_bus() |
359 | + klass.dbus_con = klass.get_dbus(True) |
360 | + # Add a mock Ofono environment so we get consistent results |
361 | + (klass.p_mock, klass.obj_ofono) = klass.spawn_server_template( |
362 | + 'ofono', stdout=subprocess.PIPE) |
363 | + klass.dbusmock = dbus.Interface(klass.obj_ofono, dbusmock.MOCK_IFACE) |
364 | + |
365 | + def setUp(self, panel=None): |
366 | + self.obj_ofono.Reset() |
367 | + |
368 | + # create modem_0 proxy |
369 | + self.modem_0 = self.dbus_con.get_object('org.ofono', '/ril_0') |
370 | + |
371 | + # Add an available carrier |
372 | + self.mock_carriers() |
373 | + |
374 | + self.mock_radio_settings() |
375 | + |
376 | + self.mock_connection_manager() |
377 | + |
378 | super(UbuntuSystemSettingsOfonoTestCase, self).setUp('cellular') |
379 | |
380 | |
381 | @@ -168,8 +225,7 @@ |
382 | |
383 | def get_storage_space_used_by_category(self, objectName): |
384 | return self.main_view.wait_select_single( |
385 | - 'StorageItem', objectName=objectName |
386 | - ).value |
387 | + 'StorageItem', objectName=objectName).value |
388 | |
389 | @property |
390 | def storage_page(self): |
391 | |
392 | === modified file 'tests/autopilot/ubuntu_system_settings/tests/test_cellular.py' |
393 | --- tests/autopilot/ubuntu_system_settings/tests/test_cellular.py 2014-04-04 15:31:49 +0000 |
394 | +++ tests/autopilot/ubuntu_system_settings/tests/test_cellular.py 2014-07-10 14:01:58 +0000 |
395 | @@ -4,19 +4,52 @@ |
396 | # This program is free software: you can redistribute it and/or modify it |
397 | # under the terms of the GNU General Public License version 3, as published |
398 | # by the Free Software Foundation. |
399 | - |
400 | +import dbus |
401 | +from time import sleep |
402 | from autopilot.introspection.dbus import StateNotFoundError |
403 | +from gi.repository import Gio |
404 | from testtools.matchers import Equals, NotEquals, raises |
405 | |
406 | -from ubuntu_system_settings.tests import UbuntuSystemSettingsOfonoTestCase |
407 | +from ubuntu_system_settings.tests import ( |
408 | + UbuntuSystemSettingsOfonoTestCase, CONNMAN_IFACE, RDO_IFACE) |
409 | from ubuntu_system_settings.utils.i18n import ugettext as _ |
410 | |
411 | from ubuntuuitoolkit import emulators as toolkit_emulators |
412 | |
413 | |
414 | +PREFERENCE_2G = '2G only (saves battery)' |
415 | +PREFERENCE_ANY = '2G/3G/4G (faster)' |
416 | +PREFERENCE_OFF = 'Off' |
417 | + |
418 | + |
419 | class CellularTestCase(UbuntuSystemSettingsOfonoTestCase): |
420 | """ Tests for cellular Page """ |
421 | |
422 | + """Caches the technology preference selector""" |
423 | + _pref_selector = None |
424 | + |
425 | + @property |
426 | + def data_preference_selector(self): |
427 | + """Return data_preference_selector""" |
428 | + try: |
429 | + self._pref_selector.get_properties() |
430 | + except: |
431 | + self._pref_selector = self.system_settings.main_view.cellular_page.select_single( |
432 | + toolkit_emulators.ItemSelector, |
433 | + objectName="technologyPreferenceSelector" |
434 | + ) |
435 | + return self._pref_selector |
436 | + |
437 | + def select_preference(self, label): |
438 | + """Helper method that clicks a preference that matches provided label""" |
439 | + pref = self.data_preference_selector.select_single('Label', text=label) |
440 | + self.system_settings.main_view.pointer.click_object(pref) |
441 | + |
442 | + def assert_selected_preference(self, index): |
443 | + """Helper method asserting that the selected data technology preference |
444 | + is that of index""" |
445 | + self.assertThat(self.data_preference_selector.selectedIndex, Equals(index)) |
446 | + |
447 | def navigate_to_manual(self): |
448 | selector = self.system_settings.main_view.cellular_page.select_single( |
449 | toolkit_emulators.ItemSelector, |
450 | @@ -77,3 +110,120 @@ |
451 | lambda: carriers.select_single('Label', text="my.bad.telco"), |
452 | raises(StateNotFoundError) |
453 | ) |
454 | + |
455 | + def test_set_modem_offline(self): |
456 | + self.select_preference(PREFERENCE_OFF) |
457 | + |
458 | + sleep(1) |
459 | + |
460 | + self.assertEqual(False, self.modem_0.Get(CONNMAN_IFACE, 'Powered')) |
461 | + |
462 | + def test_set_modem_online(self): |
463 | + self.select_preference(PREFERENCE_OFF) |
464 | + sleep(1) |
465 | + self.assertEqual(False, self.modem_0.Get(CONNMAN_IFACE, 'Powered')) |
466 | + |
467 | + self.select_preference(PREFERENCE_ANY) |
468 | + sleep(1) |
469 | + self.assertEqual(True, self.modem_0.Get(CONNMAN_IFACE, 'Powered')) |
470 | + |
471 | + def test_modem_online_status_toggles_data_roaming_switch(self): |
472 | + """Test that switching off cellular data disables roaming switch""" |
473 | + roaming_switch = self.system_settings.main_view.select_single( |
474 | + '*', objectName="dataRoamingSwitch" |
475 | + ) |
476 | + |
477 | + # select 2G only |
478 | + self.select_preference(PREFERENCE_2G) |
479 | + # assert that roaming_switch is enabled |
480 | + self.assertTrue(roaming_switch.get_properties()['enabled']) |
481 | + |
482 | + # click off |
483 | + self.select_preference(PREFERENCE_OFF) |
484 | + # assert roaming_switch is disabled |
485 | + self.assertFalse(roaming_switch.get_properties()['enabled']) |
486 | + |
487 | + def test_data_preference_change_is_reflected_by_dbus(self): |
488 | + self.select_preference(PREFERENCE_2G) |
489 | + |
490 | + sleep(1) |
491 | + self.assertEqual('gsm', self.modem_0.Get(RDO_IFACE, 'TechnologyPreference')) |
492 | + |
493 | + self.select_preference(PREFERENCE_ANY) |
494 | + |
495 | + sleep(1) |
496 | + |
497 | + self.assertEqual('any', self.modem_0.Get(RDO_IFACE, 'TechnologyPreference')) |
498 | + |
499 | + def test_modem_online_status_insensitive_to_radio_preference(self): |
500 | + # turn off cellular data |
501 | + self.select_preference(PREFERENCE_OFF) |
502 | + |
503 | + # fake dbus signal, changing to any |
504 | + self.modem_0.EmitSignal( |
505 | + 'org.ofono.RadioSettings', |
506 | + 'PropertyChanged', |
507 | + 'sv', |
508 | + ['TechnologyPreference', dbus.String('any', variant_level=1)]) |
509 | + |
510 | + # TODO: use 'eventually' instead |
511 | + sleep(1) |
512 | + |
513 | + # assert that "Off" has not changed |
514 | + self.assert_selected_preference(0) |
515 | + |
516 | + def test_ui_reacts_to_modem_set_coming_online(self): |
517 | + self.select_preference(PREFERENCE_2G) |
518 | + self.select_preference(PREFERENCE_OFF) |
519 | + |
520 | + sleep(1) |
521 | + |
522 | + self.modem_0.EmitSignal( |
523 | + CONNMAN_IFACE, |
524 | + 'PropertyChanged', |
525 | + 'sv', |
526 | + ['Powered', 'true']) |
527 | + |
528 | + sleep(1) |
529 | + |
530 | + # assert that 2G is selected |
531 | + self.assert_selected_preference(1) |
532 | + |
533 | + def test_radio_preference_change_does_not_override_user_selection(self): |
534 | + self.select_preference(PREFERENCE_2G) |
535 | + |
536 | + self.modem_0.EmitSignal( |
537 | + 'org.ofono.RadioSettings', |
538 | + 'PropertyChanged', |
539 | + 'sv', |
540 | + ['TechnologyPreference', dbus.String('lte', variant_level=1)]) |
541 | + |
542 | + sleep(1) |
543 | + |
544 | + self.assertEqual('gsm', self.modem_0.Get(RDO_IFACE, 'TechnologyPreference')) |
545 | + |
546 | + # assert that the preference is any |
547 | + self.assert_selected_preference(1) |
548 | + |
549 | + def test_ui_if_sim_was_unlocked_on_opening(self): |
550 | + '''Like it would if the sim was locked, e.g.''' |
551 | + self.modem_0.Set(RDO_IFACE, 'TechnologyPreference', dbus.String('', variant_level=1)) |
552 | + |
553 | + self.system_settings.main_view.go_back() |
554 | + |
555 | + self.system_settings.main_view.pointer.click_object( |
556 | + self.system_settings.main_view.select_single( |
557 | + objectName='entryComponent-cellular')) |
558 | + |
559 | + self.assert_selected_preference(-1) |
560 | + self.assertFalse(self.data_preference_selector.enabled) |
561 | + |
562 | + self.modem_0.EmitSignal( |
563 | + 'org.ofono.RadioSettings', |
564 | + 'PropertyChanged', |
565 | + 'sv', |
566 | + ['TechnologyPreference', dbus.String('lte', variant_level=1)]) |
567 | + |
568 | + sleep(1) |
569 | + |
570 | + self.assert_selected_preference(2) |
I know this is work in progress, but let's have all the Cellular test cases in one place, so rather than adding a new TechnologyPrefe rencesTestCases , just add your new tests in CellularTestCase.