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
"""Regression test for the unofficial Account.Interface.Requests API when
21
a channel can be created successfully.
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,
45
client = SimulatedClient(q, bus, 'Empathy',
46
observe=[text_fixed_properties], approve=[text_fixed_properties],
47
handle=[text_fixed_properties], bypass_approval=False)
49
# No Approver should be invoked at any point during this test, because the
50
# Channel was Requested
51
def fail_on_approval(e):
52
raise AssertionError('Approver should not be invoked')
53
q.add_dbus_method_impl(fail_on_approval, path=client.object_path,
54
interface=cs.APPROVER, method='AddDispatchOperation')
56
# wait for MC to download the properties
57
expect_client_setup(q, [client])
59
user_action_time = dbus.Int64(1238582606)
61
# chat UI calls ChannelDispatcher.CreateChannel
62
# (or in this case, an equivalent non-standard method on the Account)
63
request = dbus.Dictionary({
64
cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_TEXT,
65
cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT,
66
cs.CHANNEL + '.TargetID': 'juliet',
68
account_requests = dbus.Interface(account,
69
cs.ACCOUNT_IFACE_NOKIA_REQUESTS)
70
call_async(q, account_requests, 'Create',
71
request, user_action_time, client.bus_name)
73
# chat UI connects to signals and calls ChannelRequest.Proceed() - but not
74
# in this non-standard API, which fires off the request instantly
75
ret, cm_request_call, add_request = q.expect_many(
76
EventPattern('dbus-return', method='Create'),
77
EventPattern('dbus-method-call',
78
interface=cs.CONN_IFACE_REQUESTS, method='CreateChannel',
79
path=conn.object_path, args=[request], handled=False),
80
EventPattern('dbus-method-call', handled=False,
81
interface=cs.CLIENT_IFACE_REQUESTS, method='AddRequest',
82
path=client.object_path),
85
request_path = ret.value[0]
87
cr = bus.get_object(cs.AM, request_path)
88
request_props = cr.GetAll(cs.CR, dbus_interface=cs.PROPERTIES_IFACE)
89
assert request_props['Account'] == account.object_path
90
assert request_props['Requests'] == [request]
91
assert request_props['UserActionTime'] == user_action_time
93
assert add_request.args[0] == request_path
94
q.dbus_return(add_request.message, signature='')
96
# Actually, never mind.
97
account_requests.Cancel(request_path)
99
# Time passes. A channel is returned.
101
channel_immutable = dbus.Dictionary(request)
102
channel_immutable[cs.CHANNEL + '.InitiatorID'] = conn.self_ident
103
channel_immutable[cs.CHANNEL + '.InitiatorHandle'] = conn.self_handle
104
channel_immutable[cs.CHANNEL + '.Requested'] = True
105
channel_immutable[cs.CHANNEL + '.Interfaces'] = \
106
dbus.Array([], signature='s')
107
channel_immutable[cs.CHANNEL + '.TargetHandle'] = \
108
conn.ensure_handle(cs.HT_CONTACT, 'juliet')
109
channel = SimulatedChannel(conn, channel_immutable)
111
# this order of events is guaranteed by telepathy-spec (since 0.17.14)
112
q.dbus_return(cm_request_call.message,
113
channel.object_path, channel.immutable, signature='oa{sv}')
116
# Channel is unwanted now, MC stabs it in the face
117
accsig, stdsig, _ = q.expect_many(
118
EventPattern('dbus-signal', path=account.object_path,
119
interface=cs.ACCOUNT_IFACE_NOKIA_REQUESTS, signal='Failed'),
120
EventPattern('dbus-signal', path=request_path,
121
interface=cs.CR, signal='Failed'),
122
EventPattern('dbus-method-call', path=channel.object_path,
123
interface=cs.CHANNEL, method='Close', handled=True),
126
if __name__ == '__main__':