~ubuntu-branches/ubuntu/oneiric/weave/oneiric

« back to all changes in this revision

Viewing changes to tests/unit/attic/test_xmpp.js

  • Committer: Bazaar Package Importer
  • Author(s): Micah Gersten
  • Date: 2010-08-11 00:35:15 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100811003515-o3jbh826bnd1syjv
Tags: 1.4.3-1ubuntu1
* Add -fshort-wchar to CXXFLAGS to fix FTBFS in Ubuntu
  - update debian/rules 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Cu.import( "resource://weave/xmpp/xmppClient.js" );
2
 
 
3
 
function LOG(aMsg) {
4
 
  dump("TEST_XMPP: " + aMsg + "\n");
5
 
}
6
 
 
7
 
var serverUrl = "http://localhost:5280/http-poll";
8
 
var jabberDomain = "localhost";
9
 
 
10
 
var timer = Cc["@mozilla.org/timer;1"].createInstance( Ci.nsITimer );
11
 
var threadManager = Cc["@mozilla.org/thread-manager;1"].getService();
12
 
 
13
 
function run_test() {
14
 
  // FIXME: this test hangs when you don't have a server, disabling for now
15
 
  return;
16
 
 
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",
21
 
                             transport, auth);
22
 
 
23
 
  // test connection
24
 
  LOG("connecting");
25
 
  alice.connect( jabberDomain );
26
 
  alice.waitForConnection();
27
 
  do_check_eq( alice._connectionStatus, alice.CONNECTED);
28
 
  LOG("connected");
29
 
 
30
 
  // test disconnection
31
 
  LOG("disconnecting");
32
 
  alice.disconnect();
33
 
  do_check_eq( alice._connectionStatus, alice.NOT_CONNECTED);
34
 
  LOG("disconnected");
35
 
 
36
 
  // test re-connection
37
 
  LOG("reconnecting");
38
 
  alice.connect( jabberDomain );
39
 
  alice.waitForConnection();
40
 
  LOG("reconnected");
41
 
  do_check_eq( alice._connectionStatus, alice.CONNECTED);
42
 
  alice.disconnect();
43
 
 
44
 
  // test connection failure - bad domain
45
 
  alice.connect( "bad domain" );
46
 
  alice.waitForConnection();
47
 
  do_check_eq( alice._connectionStatus, alice.FAILED );
48
 
 
49
 
  /*
50
 
  // re-connect and move on
51
 
  alice.connect( jabberDomain );
52
 
  alice.waitForConnection();
53
 
  do_check_eq( alice._connectionStatus, alice.CONNECTED);
54
 
 
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 );
61
 
 
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 ) {
66
 
      testIsOver = true;
67
 
      do_throw( "Timed out waiting for message." );
68
 
    }
69
 
  };
70
 
  timer.initWithCallback( timerResponder, 20000, timer.TYPE_ONE_SHOT );
71
 
 
72
 
 
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 );
79
 
      timer.cancel();
80
 
      testIsOver = true;
81
 
    }
82
 
  };
83
 
  alice.registerMessageHandler( aliceMessageHandler );
84
 
 
85
 
  // Start both clients
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 );
92
 
 
93
 
  // Send the message
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 );
99
 
  }
100
 
 
101
 
  alice.disconnect();
102
 
  bob.disconnect();
103
 
  */
104
 
};