[telepathy-gabble/telepathy-gabble-0.8] Check caps for contacts who sign in twice.
Will Thompson
will.thompson at collabora.co.uk
Thu Sep 10 07:48:31 PDT 2009
Gabble does get this right, but I thought it worth checking that it
doesn't get confused.
---
tests/twisted/caps/caps-cache.py | 74 +++++++++++++++++++++++++++----------
1 files changed, 54 insertions(+), 20 deletions(-)
diff --git a/tests/twisted/caps/caps-cache.py b/tests/twisted/caps/caps-cache.py
index c21f79b..bb379d5 100644
--- a/tests/twisted/caps/caps-cache.py
+++ b/tests/twisted/caps/caps-cache.py
@@ -7,7 +7,7 @@ confirmation without hash.
from twisted.words.xish import xpath
from servicetest import EventPattern, assertEquals, assertContains
-from gabbletest import exec_test, make_presence
+from gabbletest import exec_test, make_presence, sync_stream
import constants as cs
import ns
from caps_helper import (
@@ -22,8 +22,8 @@ features = [
]
def presence_and_disco(q, conn, stream, contact, disco,
- caps, dataforms={}):
- h = send_presence(q, conn, stream, contact, caps)
+ caps, dataforms={}, initial=True):
+ h = send_presence(q, conn, stream, contact, caps, initial=initial)
if disco:
stanza = expect_disco(q, contact, caps)
@@ -31,22 +31,23 @@ def presence_and_disco(q, conn, stream, contact, disco,
expect_caps(q, conn, h)
-def send_presence(q, conn, stream, contact, caps):
+def send_presence(q, conn, stream, contact, caps, initial=True):
h = conn.RequestHandles(cs.HT_CONTACT, [contact])[0]
- stream.send(make_presence(contact, status='hello'))
+ if initial:
+ stream.send(make_presence(contact, status='hello'))
- q.expect_many(
- EventPattern('dbus-signal', signal='PresenceUpdate',
- args=[{h:
- (0L, {u'available': {'message': 'hello'}})}]),
- EventPattern('dbus-signal', signal='PresencesChanged',
- args=[{h:
- (2, u'available', 'hello')}]))
+ q.expect_many(
+ EventPattern('dbus-signal', signal='PresenceUpdate',
+ args=[{h:
+ (0L, {u'available': {'message': 'hello'}})}]),
+ EventPattern('dbus-signal', signal='PresencesChanged',
+ args=[{h:
+ (2, u'available', 'hello')}]))
- # no special capabilities
- assertEquals([(h, cs.CHANNEL_TYPE_TEXT, 3, 0)],
- conn.Capabilities.GetCapabilities([h]))
+ # no special capabilities
+ assertEquals([(h, cs.CHANNEL_TYPE_TEXT, 3, 0)],
+ conn.Capabilities.GetCapabilities([h]))
# send updated presence with Jingle caps info
stream.send(make_presence(contact, status='hello', caps=caps))
@@ -60,7 +61,7 @@ def expect_disco(q, contact, caps):
return event.stanza
-def send_disco_reply(stream, stanza, dataforms):
+def send_disco_reply(stream, stanza, dataforms={}):
# send good reply
result = make_caps_disco_reply(stream, stanza, features, dataforms)
stream.send(result)
@@ -68,6 +69,9 @@ def send_disco_reply(stream, stanza, dataforms):
def expect_caps(q, conn, h):
# we can now do audio calls
event = q.expect('dbus-signal', signal='CapabilitiesChanged')
+ check_caps(conn, h)
+
+def check_caps(conn, h):
assertContains((h, cs.CHANNEL_TYPE_STREAMED_MEDIA, 3, cs.MEDIA_CAP_AUDIO),
conn.Capabilities.GetCapabilities([h]))
@@ -83,10 +87,39 @@ def test(q, bus, conn, stream):
presence_and_disco(q, conn, stream, 'bob1 at foo.com/Foo', True, caps)
presence_and_disco(q, conn, stream, 'bob2 at foo.com/Foo', True, caps)
- presence_and_disco(q, conn, stream, 'bob3 at foo.com/Foo', True, caps)
- presence_and_disco(q, conn, stream, 'bob4 at foo.com/Foo', True, caps)
+
+ # Meredith signs in from one resource.
+ presence_and_disco(q, conn, stream, 'meredith at foo.com/One', True, caps)
+ # Meredith signs in from another resource with the same client. We don't
+ # need to disco her, even though we don't trust this caps node in general
+ # yet, because she's already told us what it means.
+ meredith_two = 'meredith at foo.com/Two'
+ q.forbid_events([
+ EventPattern('stream-iq', to=meredith_two, query_ns=ns.DISCO_INFO)
+ ])
+ stream.send(make_presence(meredith_two, 'hello', caps=caps))
+ sync_stream(q, stream)
+
+ # Jens signs in from one resource, which is slow to answer the disco query.
+ jens_one = 'jens at foo.com/One'
+ j = send_presence(q, conn, stream, jens_one, caps)
+ j_stanza = expect_disco(q, jens_one, caps)
+
+ # Jens now signs in elsewhere with the same client; we disco it (maybe
+ # it'll reply sooner? Maybe his first client's network connection went away
+ # and the server hasn't noticed yet?) and it replies immediately.
+ presence_and_disco(q, conn, stream, 'jens at foo.com/Two', True, caps,
+ initial=False)
+
+ # Jens' first client replies. We don't expect any caps changes here, and
+ # this shouldn't count as a second point towards the five we need to trust
+ # this caps node.
+ send_disco_reply(stream, j_stanza)
+
presence_and_disco(q, conn, stream, 'bob5 at foo.com/Foo', True, caps)
- # we have 5 different contacts that confirm
+
+ # Now five distinct contacts have told us what this caps node means, we
+ # trust it.
presence_and_disco(q, conn, stream, 'bob6 at foo.com/Foo', False, caps)
presence_and_disco(q, conn, stream, 'bob7 at foo.com/Foo', False, caps)
@@ -98,7 +131,8 @@ def test(q, bus, conn, stream):
presence_and_disco(q, conn, stream, 'bilbo1 at foo.com/Foo', True, caps,
fake_client_dataforms)
- # 1 contact is enough with hash
+ # We can verify the reply for these caps against the hash, and thus never
+ # need to disco it again.
presence_and_disco(q, conn, stream, 'bilbo2 at foo.com/Foo', False, caps,
fake_client_dataforms)
presence_and_disco(q, conn, stream, 'bilbo3 at foo.com/Foo', False, caps,
--
1.5.6.5
More information about the telepathy-commits
mailing list