|
6 | 6 |
|
7 | 7 | from gabbletest import exec_test, GoogleXmlStream, make_result_iq, \ |
8 | 8 | send_error_reply, disconnect_conn, make_presence, sync_stream, elem, \ |
9 | | - acknowledge_iq |
| 9 | + acknowledge_iq, XmppAuthenticator, StreamEvent |
10 | 10 | from servicetest import call_async, assertEquals, EventPattern, \ |
11 | 11 | assertContains, sync_dbus |
12 | 12 | import ns |
@@ -208,8 +208,52 @@ def test_disconnect(q, bus, conn, stream): |
208 | 208 |
|
209 | 209 | disconnect_conn(q, conn, stream) |
210 | 210 |
|
| 211 | +NS_CSI="urn:xmpp:csi:0" |
| 212 | +class CsiAuthenticator(XmppAuthenticator): |
| 213 | + def __init__(self): |
| 214 | + super().__init__('test', 'pass') |
| 215 | + |
| 216 | + def streamIQ(self): |
| 217 | + super().streamIQ() |
| 218 | + self.xmlstream.addObserver(f"/active[@xmlns='{NS_CSI}']", |
| 219 | + lambda x: self.xmlstream.event_func(StreamEvent('stream-active', x, self.xmlstream))) |
| 220 | + self.xmlstream.addObserver(f"/inactive[@xmlns='{NS_CSI}']", |
| 221 | + lambda x: self.xmlstream.event_func(StreamEvent('stream-inactive', x, self.xmlstream))) |
| 222 | + |
| 223 | + |
| 224 | +def test_csi(q, bus, conn, stream): |
| 225 | + assertContains(cs.CONN_IFACE_POWER_SAVING, |
| 226 | + conn.Get(cs.CONN, "Interfaces", |
| 227 | + dbus_interface=cs.PROPERTIES_IFACE)) |
| 228 | + |
| 229 | + assertEquals (False, conn.Get(cs.CONN_IFACE_POWER_SAVING, |
| 230 | + "PowerSavingActive", |
| 231 | + dbus_interface=cs.PROPERTIES_IFACE)) |
| 232 | + |
| 233 | + call_async(q, conn.PowerSaving, 'SetPowerSaving', True) |
| 234 | + |
| 235 | + q.expect('stream-inactive') |
| 236 | + |
| 237 | + q.expect_many(EventPattern('dbus-return', method='SetPowerSaving'), |
| 238 | + EventPattern('dbus-signal', signal='PowerSavingChanged', |
| 239 | + args=[True])) |
| 240 | + call_async(q, conn.PowerSaving, 'SetPowerSaving', False) |
| 241 | + |
| 242 | + q.expect('stream-active') |
| 243 | + |
| 244 | + q.expect_many( |
| 245 | + EventPattern('dbus-return', method='SetPowerSaving'), |
| 246 | + EventPattern('dbus-signal', signal='PowerSavingChanged', |
| 247 | + args=[False])) |
| 248 | + |
| 249 | + |
211 | 250 | if __name__ == '__main__': |
212 | 251 | exec_test(test, protocol=GoogleXmlStream) |
213 | 252 | exec_test(test_local_queueing) |
214 | 253 | exec_test(test_error, protocol=GoogleXmlStream) |
215 | 254 | exec_test(test_disconnect, protocol=GoogleXmlStream) |
| 255 | + |
| 256 | + # The same powersave engine is used hence only checking |
| 257 | + # CSI signaling |
| 258 | + XmppAuthenticator.features[NS_CSI] = 'csi' |
| 259 | + exec_test(test_csi, authenticator=CsiAuthenticator()) |
0 commit comments