1
# Copyright (C) 2009 Nokia Corporation
2
# Copyright (C) 2009 Collabora Ltd.
4
# This library is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU Lesser General Public
6
# License as published by the Free Software Foundation; either
7
# version 2.1 of the License, or (at your option) any later version.
9
# This library is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public
15
# License along with this library; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
"""Feature test for a VoIP UI stealing closely-related Text channels as
21
described in the telepathy-spec rationale.
27
from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \
29
from mctest import exec_test, SimulatedConnection, SimulatedClient, \
30
create_fakecm_account, enable_fakecm_account, SimulatedChannel, \
32
import constants as cs
35
params = dbus.Dictionary({"account": "someguy@example.com",
36
"password": "secrecy"}, signature='sv')
37
cm_name_ref, account = create_fakecm_account(q, bus, mc, params)
38
conn = enable_fakecm_account(q, bus, mc, account, params)
40
text_fixed_properties = dbus.Dictionary({
41
cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT,
42
cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_TEXT,
44
voip_fixed_properties = dbus.Dictionary({
45
cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT,
46
cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_STREAMED_MEDIA,
49
# Two clients want to observe, approve and handle text and VoIP channels.
50
empathy = SimulatedClient(q, bus, 'Empathy',
51
observe=[text_fixed_properties, voip_fixed_properties],
52
approve=[text_fixed_properties, voip_fixed_properties],
53
handle=[text_fixed_properties, voip_fixed_properties],
54
bypass_approval=False)
55
kopete = SimulatedClient(q, bus, 'Kopete',
56
observe=[text_fixed_properties, voip_fixed_properties],
57
approve=[text_fixed_properties, voip_fixed_properties],
58
handle=[text_fixed_properties, voip_fixed_properties],
59
bypass_approval=False)
61
# wait for MC to download the properties
62
expect_client_setup(q, [empathy, kopete])
64
# subscribe to the OperationList interface (MC assumes that until this
65
# property has been retrieved once, nobody cares)
67
cd = bus.get_object(cs.CD, cs.CD_PATH)
68
cd_props = dbus.Interface(cd, cs.PROPERTIES_IFACE)
69
assert cd_props.Get(cs.CD_IFACE_OP_LIST, 'DispatchOperations') == []
71
# First, a VoIP channel is created
73
BUNDLE = '/8de0d29d-83e1-40f5-b24f-748c0aa86c82'
75
channel_properties = dbus.Dictionary(voip_fixed_properties,
77
channel_properties[cs.CHANNEL + '.TargetID'] = 'juliet'
78
channel_properties[cs.CHANNEL + '.TargetHandle'] = \
79
conn.ensure_handle(cs.HT_CONTACT, 'juliet')
80
channel_properties[cs.CHANNEL + '.InitiatorID'] = 'juliet'
81
channel_properties[cs.CHANNEL + '.InitiatorHandle'] = \
82
conn.ensure_handle(cs.HT_CONTACT, 'juliet')
83
channel_properties[cs.CHANNEL + '.Requested'] = False
84
channel_properties[cs.CHANNEL + '.Interfaces'] = dbus.Array(signature='s')
85
channel_properties[cs.CHANNEL + '.FUTURE.Bundle'] = BUNDLE
87
chan = SimulatedChannel(conn, channel_properties)
90
# A channel dispatch operation is created
92
e = q.expect('dbus-signal',
94
interface=cs.CD_IFACE_OP_LIST,
95
signal='NewDispatchOperation')
98
cdo_properties = e.args[1]
100
assert cdo_properties[cs.CDO + '.Account'] == account.object_path
101
assert cdo_properties[cs.CDO + '.Connection'] == conn.object_path
102
assert cs.CDO + '.Interfaces' in cdo_properties
104
handlers = cdo_properties[cs.CDO + '.PossibleHandlers'][:]
106
assert handlers == [cs.tp_name_prefix + '.Client.Empathy',
107
cs.tp_name_prefix + '.Client.Kopete'], handlers
109
assert cs.CD_IFACE_OP_LIST in cd_props.Get(cs.CD, 'Interfaces')
110
assert cd_props.Get(cs.CD_IFACE_OP_LIST, 'DispatchOperations') ==\
111
[(cdo_path, cdo_properties)]
113
cdo = bus.get_object(cs.CD, cdo_path)
114
cdo_iface = dbus.Interface(cdo, cs.CDO)
116
# Both Observers are told about the new channel
118
e, k = q.expect_many(
119
EventPattern('dbus-method-call',
120
path=empathy.object_path,
121
interface=cs.OBSERVER, method='ObserveChannels',
123
EventPattern('dbus-method-call',
124
path=kopete.object_path,
125
interface=cs.OBSERVER, method='ObserveChannels',
128
assert e.args[0] == account.object_path, e.args
129
assert e.args[1] == conn.object_path, e.args
130
assert e.args[3] == cdo_path, e.args
131
assert e.args[4] == [], e.args # no requests satisfied
133
assert len(channels) == 1, channels
134
assert channels[0][0] == chan.object_path, channels
135
assert channels[0][1] == channel_properties, channels
137
assert k.args == e.args
139
# Both Observers indicate that they are ready to proceed
140
q.dbus_return(k.message, signature='')
141
q.dbus_return(e.message, signature='')
143
# The Approvers are next
145
e, k = q.expect_many(
146
EventPattern('dbus-method-call',
147
path=empathy.object_path,
148
interface=cs.APPROVER, method='AddDispatchOperation',
150
EventPattern('dbus-method-call',
151
path=kopete.object_path,
152
interface=cs.APPROVER, method='AddDispatchOperation',
156
assert e.args == [[(chan.object_path, channel_properties)],
157
cdo_path, cdo_properties]
158
assert k.args == e.args
160
q.dbus_return(e.message, signature='')
161
q.dbus_return(k.message, signature='')
163
# Both Approvers now have a flashing icon or something, trying to get the
166
# The user responds to Empathy first
167
call_async(q, cdo_iface, 'HandleWith',
168
cs.tp_name_prefix + '.Client.Empathy')
170
# Empathy is asked to handle the channels
171
e = q.expect('dbus-method-call',
172
path=empathy.object_path,
173
interface=cs.HANDLER, method='HandleChannels',
176
# Empathy accepts the channels
177
q.dbus_return(e.message, signature='')
180
EventPattern('dbus-return', method='HandleWith'),
181
EventPattern('dbus-signal', interface=cs.CDO, signal='Finished'),
182
EventPattern('dbus-signal', interface=cs.CD_IFACE_OP_LIST,
183
signal='DispatchOperationFinished'),
186
# Now there are no more active channel dispatch operations
187
assert cd_props.Get(cs.CD_IFACE_OP_LIST, 'DispatchOperations') == []
189
# Now that Empathy has the VoIP channel, it wants to steal incoming Text
190
# channels from the same bundle
192
same_bundle_properties = dbus.Dictionary(text_fixed_properties,
194
same_bundle_properties[cs.CHANNEL + '.FUTURE.Bundle'] = BUNDLE
196
bypass = SimulatedClient(q, bus, 'Empathy._1_42.Window2',
199
handle=[same_bundle_properties],
200
bypass_approval=True)
202
# wait for MC to download the properties
203
expect_client_setup(q, [bypass])
205
# From now on, this test must fail if we're asked to approve anything
207
EventPattern('dbus-method-call', method='AddDispatchOperation'),
209
q.forbid_events(approval)
211
channel_properties = dbus.Dictionary(text_fixed_properties,
213
channel_properties[cs.CHANNEL + '.TargetHandleType'] = cs.HT_CONTACT
214
channel_properties[cs.CHANNEL + '.TargetID'] = 'juliet'
215
channel_properties[cs.CHANNEL + '.TargetHandle'] = \
216
conn.ensure_handle(cs.HT_CONTACT, 'juliet')
217
channel_properties[cs.CHANNEL + '.InitiatorID'] = 'juliet'
218
channel_properties[cs.CHANNEL + '.InitiatorHandle'] = \
219
conn.ensure_handle(cs.HT_CONTACT, 'juliet')
220
channel_properties[cs.CHANNEL + '.Requested'] = False
221
channel_properties[cs.CHANNEL + '.FUTURE.Bundle'] = BUNDLE
222
channel_properties[cs.CHANNEL + '.Interfaces'] = dbus.Array(signature='s')
224
chan = SimulatedChannel(conn, channel_properties)
227
# Again, there's a CDO
229
e = q.expect('dbus-signal',
231
interface=cs.CD_IFACE_OP_LIST,
232
signal='NewDispatchOperation')
235
cdo_properties = e.args[1]
237
assert cdo_properties[cs.CDO + '.Account'] == account.object_path
238
assert cdo_properties[cs.CDO + '.Connection'] == conn.object_path
239
assert cs.CDO + '.Interfaces' in cdo_properties
241
handlers = cdo_properties[cs.CDO + '.PossibleHandlers'][:]
242
# The handler with BypassApproval is first
243
assert handlers[0] == bypass.bus_name
244
# The other two handlers are still possibilities
245
assert len(handlers) == 3
247
# Observers are invoked as usual
249
e, k = q.expect_many(
250
EventPattern('dbus-method-call',
251
path=empathy.object_path,
252
interface=cs.OBSERVER, method='ObserveChannels',
254
EventPattern('dbus-method-call',
255
path=kopete.object_path,
256
interface=cs.OBSERVER, method='ObserveChannels',
259
assert e.args[0] == account.object_path, e.args
260
assert e.args[1] == conn.object_path, e.args
261
assert e.args[3] == cdo_path, e.args
262
assert e.args[4] == [], e.args # no requests satisfied
264
assert len(channels) == 1, channels
265
assert channels[0][0] == chan.object_path, channels
266
assert channels[0][1] == channel_properties, channels
268
assert k.args == e.args
270
# Both Observers indicate that they are ready to proceed
271
q.dbus_return(k.message, signature='')
272
q.dbus_return(e.message, signature='')
274
# Empathy's BypassApproval part is asked to handle the channels
275
e = q.expect('dbus-method-call',
276
path=bypass.object_path,
277
interface=cs.HANDLER, method='HandleChannels',
279
# Empathy accepts the channels
280
q.dbus_return(e.message, signature='')
282
if __name__ == '__main__':