1
Cu.import( "resource://weave/xmpp/xmppClient.js" );
4
dump("TEST_XMPP: " + aMsg + "\n");
7
var serverUrl = "http://localhost:5280/http-poll";
8
var jabberDomain = "localhost";
10
var timer = Cc["@mozilla.org/timer;1"].createInstance( Ci.nsITimer );
11
var threadManager = Cc["@mozilla.org/thread-manager;1"].getService();
14
// FIXME: this test hangs when you don't have a server, disabling for now
17
/* First, just see if we can connect: */
18
var transport = new HTTPPollingTransport(serverUrl, false, 4000);
19
var auth = new PlainAuthenticator();
20
var alice = new XmppClient("alice", jabberDomain, "iamalice",
25
alice.connect( jabberDomain );
26
alice.waitForConnection();
27
do_check_eq( alice._connectionStatus, alice.CONNECTED);
33
do_check_eq( alice._connectionStatus, alice.NOT_CONNECTED);
38
alice.connect( jabberDomain );
39
alice.waitForConnection();
41
do_check_eq( alice._connectionStatus, alice.CONNECTED);
44
// test connection failure - bad domain
45
alice.connect( "bad domain" );
46
alice.waitForConnection();
47
do_check_eq( alice._connectionStatus, alice.FAILED );
50
// re-connect and move on
51
alice.connect( jabberDomain );
52
alice.waitForConnection();
53
do_check_eq( alice._connectionStatus, alice.CONNECTED);
55
// The talking-to-myself test:
56
var testIsOver = false;
57
var sometext = "bla bla how you doin bla";
58
var transport2 = new HTTPPollingTransport( serverUrl, false, 4000 );
59
var auth2 = new PlainAuthenticator();
60
var bob = new XmppClient( "bob", jabberDomain, "iambob", transport2, auth2 );
62
// Timer that will make the test fail if message is not received after
63
// a certain amount of time
64
var timerResponder = {
65
notify: function( timer ) {
67
do_throw( "Timed out waiting for message." );
70
timer.initWithCallback( timerResponder, 20000, timer.TYPE_ONE_SHOT );
73
// Handler that listens for the incoming message:
74
var aliceMessageHandler = {
75
handle: function( msgText, from ) {
76
dump( "Alice got a message.\n" );
77
do_check_eq( msgText, sometext );
78
do_check_eq( from, "bob@" + jabberDomain );
83
alice.registerMessageHandler( aliceMessageHandler );
86
bob.connect( jabberDomain );
87
bob.waitForConnection();
88
do_check_neq( bob._connectionStatus, bob.FAILED );
89
alice.connect( jabberDomain );
90
alice.waitForConnection();
91
do_check_neq( alice._connectionStatus, alice.FAILED );
94
bob.sendMessage( "alice@" + jabberDomain, sometext );
95
// Wait until either the message is received, or the timeout expires.
96
var currentThread = threadManager.currentThread;
97
while( !testIsOver ) {
98
currentThread.processNextEvent( true );