~ubuntu-branches/ubuntu/precise/telepathy-mission-control-5/precise

« back to all changes in this revision

Viewing changes to tests/twisted/dispatcher/capture-bundle.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonny Lamb
  • Date: 2011-01-27 17:54:12 UTC
  • mto: (0.12.1 upstream) (7.1.4 maverick)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20110127175412-cijhp5z0763s11cy
Tags: upstream-5.7.2
ImportĀ upstreamĀ versionĀ 5.7.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 Nokia Corporation
 
2
# Copyright (C) 2009 Collabora Ltd.
 
3
#
 
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.
 
8
#
 
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.
 
13
#
 
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
 
17
# 02110-1301 USA
 
18
 
 
19
import dbus
 
20
"""Feature test for a VoIP UI stealing closely-related Text channels as
 
21
described in the telepathy-spec rationale.
 
22
"""
 
23
 
 
24
import dbus
 
25
import dbus.service
 
26
 
 
27
from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \
 
28
        call_async
 
29
from mctest import exec_test, SimulatedConnection, SimulatedClient, \
 
30
        create_fakecm_account, enable_fakecm_account, SimulatedChannel, \
 
31
        expect_client_setup
 
32
import constants as cs
 
33
 
 
34
def test(q, bus, mc):
 
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)
 
39
 
 
40
    text_fixed_properties = dbus.Dictionary({
 
41
        cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT,
 
42
        cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_TEXT,
 
43
        }, signature='sv')
 
44
    voip_fixed_properties = dbus.Dictionary({
 
45
        cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT,
 
46
        cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_STREAMED_MEDIA,
 
47
        }, signature='sv')
 
48
 
 
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)
 
60
 
 
61
    # wait for MC to download the properties
 
62
    expect_client_setup(q, [empathy, kopete])
 
63
 
 
64
    # subscribe to the OperationList interface (MC assumes that until this
 
65
    # property has been retrieved once, nobody cares)
 
66
 
 
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') == []
 
70
 
 
71
    # First, a VoIP channel is created
 
72
 
 
73
    BUNDLE = '/8de0d29d-83e1-40f5-b24f-748c0aa86c82'
 
74
 
 
75
    channel_properties = dbus.Dictionary(voip_fixed_properties,
 
76
            signature='sv')
 
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
 
86
 
 
87
    chan = SimulatedChannel(conn, channel_properties)
 
88
    chan.announce()
 
89
 
 
90
    # A channel dispatch operation is created
 
91
 
 
92
    e = q.expect('dbus-signal',
 
93
            path=cs.CD_PATH,
 
94
            interface=cs.CD_IFACE_OP_LIST,
 
95
            signal='NewDispatchOperation')
 
96
 
 
97
    cdo_path = e.args[0]
 
98
    cdo_properties = e.args[1]
 
99
 
 
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
 
103
 
 
104
    handlers = cdo_properties[cs.CDO + '.PossibleHandlers'][:]
 
105
    handlers.sort()
 
106
    assert handlers == [cs.tp_name_prefix + '.Client.Empathy',
 
107
            cs.tp_name_prefix + '.Client.Kopete'], handlers
 
108
 
 
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)]
 
112
 
 
113
    cdo = bus.get_object(cs.CD, cdo_path)
 
114
    cdo_iface = dbus.Interface(cdo, cs.CDO)
 
115
 
 
116
    # Both Observers are told about the new channel
 
117
 
 
118
    e, k = q.expect_many(
 
119
            EventPattern('dbus-method-call',
 
120
                path=empathy.object_path,
 
121
                interface=cs.OBSERVER, method='ObserveChannels',
 
122
                handled=False),
 
123
            EventPattern('dbus-method-call',
 
124
                path=kopete.object_path,
 
125
                interface=cs.OBSERVER, method='ObserveChannels',
 
126
                handled=False),
 
127
            )
 
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
 
132
    channels = e.args[2]
 
133
    assert len(channels) == 1, channels
 
134
    assert channels[0][0] == chan.object_path, channels
 
135
    assert channels[0][1] == channel_properties, channels
 
136
 
 
137
    assert k.args == e.args
 
138
 
 
139
    # Both Observers indicate that they are ready to proceed
 
140
    q.dbus_return(k.message, signature='')
 
141
    q.dbus_return(e.message, signature='')
 
142
 
 
143
    # The Approvers are next
 
144
 
 
145
    e, k = q.expect_many(
 
146
            EventPattern('dbus-method-call',
 
147
                path=empathy.object_path,
 
148
                interface=cs.APPROVER, method='AddDispatchOperation',
 
149
                handled=False),
 
150
            EventPattern('dbus-method-call',
 
151
                path=kopete.object_path,
 
152
                interface=cs.APPROVER, method='AddDispatchOperation',
 
153
                handled=False),
 
154
            )
 
155
 
 
156
    assert e.args == [[(chan.object_path, channel_properties)],
 
157
            cdo_path, cdo_properties]
 
158
    assert k.args == e.args
 
159
 
 
160
    q.dbus_return(e.message, signature='')
 
161
    q.dbus_return(k.message, signature='')
 
162
 
 
163
    # Both Approvers now have a flashing icon or something, trying to get the
 
164
    # user's attention
 
165
 
 
166
    # The user responds to Empathy first
 
167
    call_async(q, cdo_iface, 'HandleWith',
 
168
            cs.tp_name_prefix + '.Client.Empathy')
 
169
 
 
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',
 
174
            handled=False)
 
175
 
 
176
    # Empathy accepts the channels
 
177
    q.dbus_return(e.message, signature='')
 
178
 
 
179
    q.expect_many(
 
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'),
 
184
            )
 
185
 
 
186
    # Now there are no more active channel dispatch operations
 
187
    assert cd_props.Get(cs.CD_IFACE_OP_LIST, 'DispatchOperations') == []
 
188
 
 
189
    # Now that Empathy has the VoIP channel, it wants to steal incoming Text
 
190
    # channels from the same bundle
 
191
 
 
192
    same_bundle_properties = dbus.Dictionary(text_fixed_properties,
 
193
            signature='sv')
 
194
    same_bundle_properties[cs.CHANNEL + '.FUTURE.Bundle'] = BUNDLE
 
195
 
 
196
    bypass = SimulatedClient(q, bus, 'Empathy._1_42.Window2',
 
197
            observe=[],
 
198
            approve=[],
 
199
            handle=[same_bundle_properties],
 
200
            bypass_approval=True)
 
201
 
 
202
    # wait for MC to download the properties
 
203
    expect_client_setup(q, [bypass])
 
204
 
 
205
    # From now on, this test must fail if we're asked to approve anything
 
206
    approval = [
 
207
            EventPattern('dbus-method-call', method='AddDispatchOperation'),
 
208
            ]
 
209
    q.forbid_events(approval)
 
210
 
 
211
    channel_properties = dbus.Dictionary(text_fixed_properties,
 
212
            signature='sv')
 
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')
 
223
 
 
224
    chan = SimulatedChannel(conn, channel_properties)
 
225
    chan.announce()
 
226
 
 
227
    # Again, there's a CDO
 
228
 
 
229
    e = q.expect('dbus-signal',
 
230
            path=cs.CD_PATH,
 
231
            interface=cs.CD_IFACE_OP_LIST,
 
232
            signal='NewDispatchOperation')
 
233
 
 
234
    cdo_path = e.args[0]
 
235
    cdo_properties = e.args[1]
 
236
 
 
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
 
240
 
 
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
 
246
 
 
247
    # Observers are invoked as usual
 
248
 
 
249
    e, k = q.expect_many(
 
250
            EventPattern('dbus-method-call',
 
251
                path=empathy.object_path,
 
252
                interface=cs.OBSERVER, method='ObserveChannels',
 
253
                handled=False),
 
254
            EventPattern('dbus-method-call',
 
255
                path=kopete.object_path,
 
256
                interface=cs.OBSERVER, method='ObserveChannels',
 
257
                handled=False),
 
258
            )
 
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
 
263
    channels = e.args[2]
 
264
    assert len(channels) == 1, channels
 
265
    assert channels[0][0] == chan.object_path, channels
 
266
    assert channels[0][1] == channel_properties, channels
 
267
 
 
268
    assert k.args == e.args
 
269
 
 
270
    # Both Observers indicate that they are ready to proceed
 
271
    q.dbus_return(k.message, signature='')
 
272
    q.dbus_return(e.message, signature='')
 
273
 
 
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',
 
278
            handled=False)
 
279
    # Empathy accepts the channels
 
280
    q.dbus_return(e.message, signature='')
 
281
 
 
282
if __name__ == '__main__':
 
283
    exec_test(test, {})
 
284