Initial work on adding profiling tests.
This commit is contained in:
parent
7e42783c62
commit
5e4d6bd3b2
1
main.js
1
main.js
|
@ -139,6 +139,7 @@ config = {
|
||||||
'crypto.sha1': { deps: ['crypto.core'] },
|
'crypto.sha1': { deps: ['crypto.core'] },
|
||||||
'crypto.sha256': { deps: ['crypto.core'] },
|
'crypto.sha256': { deps: ['crypto.core'] },
|
||||||
'bigint': { deps: ['crypto'] },
|
'bigint': { deps: ['crypto'] },
|
||||||
|
'strophe': { exports: 'Strophe' },
|
||||||
'strophe.disco': { deps: ['strophe'] },
|
'strophe.disco': { deps: ['strophe'] },
|
||||||
'strophe.muc': { deps: ['strophe'] },
|
'strophe.muc': { deps: ['strophe'] },
|
||||||
'strophe.roster': { deps: ['strophe'] },
|
'strophe.roster': { deps: ['strophe'] },
|
||||||
|
|
|
@ -385,6 +385,11 @@
|
||||||
}, converse));
|
}, converse));
|
||||||
|
|
||||||
it("can be removed by the user", $.proxy(function () {
|
it("can be removed by the user", $.proxy(function () {
|
||||||
|
// XXX
|
||||||
|
// This tests fails because "remove" function in strophe.roster
|
||||||
|
// (line 292) gets called and it then tries to actually remove
|
||||||
|
// the user which is not in the roster...
|
||||||
|
// We'll perhaps have to first add the user again...
|
||||||
_addContacts();
|
_addContacts();
|
||||||
var name = mock.pend_names[0];
|
var name = mock.pend_names[0];
|
||||||
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
||||||
|
@ -764,6 +769,48 @@
|
||||||
// There should now be one less contact
|
// There should now be one less contact
|
||||||
expect(this.roster.length).toEqual(mock.req_names.length-1);
|
expect(this.roster.length).toEqual(mock.req_names.length-1);
|
||||||
}, converse));
|
}, converse));
|
||||||
|
|
||||||
|
it("are persisted even if other contacts' change their presence ", $.proxy(function() {
|
||||||
|
/* This is a regression test.
|
||||||
|
* https://github.com/jcbrand/converse.js/issues/262
|
||||||
|
*/
|
||||||
|
this.rosterview.model.reset();
|
||||||
|
spyOn(this.roster, 'clearCache').andCallThrough();
|
||||||
|
expect(this.roster.pluck('jid').length).toBe(0);
|
||||||
|
|
||||||
|
var stanza = $pres({from: 'data@enterprise/resource', type: 'subscribe'});
|
||||||
|
this.connection._dataRecv(test_utils.createRequest(stanza));
|
||||||
|
expect(this.roster.pluck('jid').length).toBe(1);
|
||||||
|
expect(_.contains(this.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
|
||||||
|
|
||||||
|
// Taken from the spec
|
||||||
|
// http://xmpp.org/rfcs/rfc3921.html#rfc.section.7.3
|
||||||
|
stanza = $iq({
|
||||||
|
to: this.connection.jid,
|
||||||
|
type: 'result',
|
||||||
|
id: 'roster_1'
|
||||||
|
}).c('query', {
|
||||||
|
xmlns: 'jabber:iq:roster',
|
||||||
|
}).c('item', {
|
||||||
|
jid: 'romeo@example.net',
|
||||||
|
name: 'Romeo',
|
||||||
|
subscription:'both'
|
||||||
|
}).c('group').t('Friends').up().up()
|
||||||
|
.c('item', {
|
||||||
|
jid: 'mercutio@example.org',
|
||||||
|
name: 'Mercutio',
|
||||||
|
subscription:'from'
|
||||||
|
}).c('group').t('Friends').up().up()
|
||||||
|
.c('item', {
|
||||||
|
jid: 'benvolio@example.org',
|
||||||
|
name: 'Benvolio',
|
||||||
|
subscription:'both'
|
||||||
|
}).c('group').t('Friends');
|
||||||
|
this.connection.roster._onReceiveRosterSuccess(null, stanza.tree());
|
||||||
|
expect(this.roster.clearCache).toHaveBeenCalled();
|
||||||
|
expect(_.contains(this.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
|
||||||
|
}, converse));
|
||||||
|
|
||||||
}, converse));
|
}, converse));
|
||||||
|
|
||||||
describe("All Contacts", $.proxy(function () {
|
describe("All Contacts", $.proxy(function () {
|
||||||
|
|
58
spec/profiling.js
Normal file
58
spec/profiling.js
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
(function (root, factory) {
|
||||||
|
define([
|
||||||
|
"jquery",
|
||||||
|
"mock",
|
||||||
|
"test_utils"
|
||||||
|
], function ($, mock, test_utils) {
|
||||||
|
return factory($, mock, test_utils);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} (this, function ($, mock, test_utils) {
|
||||||
|
describe("Profiling", function() {
|
||||||
|
var roster;
|
||||||
|
beforeEach(function() {
|
||||||
|
roster = converse.connection.roster;
|
||||||
|
converse.connection._changeConnectStatus(Strophe.Status.CONNECTED);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds contacts on presence stanza", $.proxy(function() {
|
||||||
|
spyOn(this.roster, 'clearCache').andCallThrough();
|
||||||
|
expect(this.roster.pluck('jid').length).toBe(0);
|
||||||
|
|
||||||
|
var stanza = $pres({from: 'data@enterprise/resource', type: 'subscribe'});
|
||||||
|
this.connection._dataRecv(test_utils.createRequest(stanza));
|
||||||
|
expect(this.roster.pluck('jid').length).toBe(1);
|
||||||
|
expect(_.contains(this.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
|
||||||
|
|
||||||
|
// Taken from the spec
|
||||||
|
// http://xmpp.org/rfcs/rfc3921.html#rfc.section.7.3
|
||||||
|
stanza = $iq({
|
||||||
|
to: this.connection.jid,
|
||||||
|
type: 'result',
|
||||||
|
id: 'roster_1'
|
||||||
|
}).c('query', {
|
||||||
|
xmlns: 'jabber:iq:roster',
|
||||||
|
}).c('item', {
|
||||||
|
jid: 'romeo@example.net',
|
||||||
|
name: 'Romeo',
|
||||||
|
subscription:'both'
|
||||||
|
}).c('group').t('Friends').up().up()
|
||||||
|
.c('item', {
|
||||||
|
jid: 'mercutio@example.org',
|
||||||
|
name: 'Mercutio',
|
||||||
|
subscription:'from'
|
||||||
|
}).c('group').t('Friends').up().up()
|
||||||
|
.c('item', {
|
||||||
|
jid: 'benvolio@example.org',
|
||||||
|
name: 'Benvolio',
|
||||||
|
subscription:'both'
|
||||||
|
}).c('group').t('Friends');
|
||||||
|
this.connection.roster._onReceiveRosterSuccess(null, stanza.tree());
|
||||||
|
expect(this.roster.clearCache).toHaveBeenCalled();
|
||||||
|
|
||||||
|
expect(_.contains(this.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
|
||||||
|
}, converse));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}));
|
|
@ -40,8 +40,6 @@ require([
|
||||||
window.converse_api = converse;
|
window.converse_api = converse;
|
||||||
window.localStorage.clear();
|
window.localStorage.clear();
|
||||||
window.sessionStorage.clear();
|
window.sessionStorage.clear();
|
||||||
// XXX: call this to initialize Strophe plugins
|
|
||||||
new Strophe.Connection('localhost');
|
|
||||||
|
|
||||||
converse.initialize({
|
converse.initialize({
|
||||||
prebind: false,
|
prebind: false,
|
||||||
|
@ -49,7 +47,8 @@ require([
|
||||||
auto_subscribe: false,
|
auto_subscribe: false,
|
||||||
animate: false,
|
animate: false,
|
||||||
connection: mock.mock_connection,
|
connection: mock.mock_connection,
|
||||||
no_trimming: true
|
no_trimming: true,
|
||||||
|
debug: true
|
||||||
}, function (converse) {
|
}, function (converse) {
|
||||||
window.converse = converse;
|
window.converse = converse;
|
||||||
window.crypto = {
|
window.crypto = {
|
||||||
|
@ -68,7 +67,8 @@ require([
|
||||||
"spec/controlbox",
|
"spec/controlbox",
|
||||||
"spec/chatbox",
|
"spec/chatbox",
|
||||||
"spec/chatroom",
|
"spec/chatroom",
|
||||||
"spec/minchats"
|
"spec/minchats",
|
||||||
|
"spec/profiling"
|
||||||
], function () {
|
], function () {
|
||||||
// Make sure this callback is only called once.
|
// Make sure this callback is only called once.
|
||||||
delete converse.callback;
|
delete converse.callback;
|
||||||
|
|
|
@ -36,11 +36,37 @@
|
||||||
'preventDefault': function () {}
|
'preventDefault': function () {}
|
||||||
};
|
};
|
||||||
|
|
||||||
mock.mock_connection = {
|
mock.mock_connection = function () {
|
||||||
'_proto': {},
|
Strophe.Bosh.prototype._processRequest = function () {}; // Don't attempt to send out stanzas
|
||||||
'connected': true,
|
var c = new Strophe.Connection('jasmine tests');
|
||||||
'authenticated': true,
|
c.authenticated = true;
|
||||||
'mock': true,
|
c.connected = true;
|
||||||
|
c.mock = true;
|
||||||
|
c.jid = 'dummy@localhost/resource';
|
||||||
|
c.vcard = {
|
||||||
|
'get': function (callback, jid) {
|
||||||
|
var fullname;
|
||||||
|
if (!jid) {
|
||||||
|
jid = 'dummy@localhost';
|
||||||
|
fullname = 'Max Mustermann' ;
|
||||||
|
} else {
|
||||||
|
var name = jid.split('@')[0].replace(/\./g, ' ').split(' ');
|
||||||
|
var last = name.length-1;
|
||||||
|
name[0] = name[0].charAt(0).toUpperCase()+name[0].slice(1);
|
||||||
|
name[last] = name[last].charAt(0).toUpperCase()+name[last].slice(1);
|
||||||
|
fullname = name.join(' ');
|
||||||
|
}
|
||||||
|
var vcard = $iq().c('vCard').c('FN').t(fullname);
|
||||||
|
callback(vcard.tree());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
c._changeConnectStatus(Strophe.Status.CONNECTED);
|
||||||
|
c.attach(c.jid);
|
||||||
|
return c;
|
||||||
|
}();
|
||||||
|
|
||||||
|
/*
|
||||||
|
{
|
||||||
'muc': {
|
'muc': {
|
||||||
'listRooms': function () {},
|
'listRooms': function () {},
|
||||||
'join': function () {},
|
'join': function () {},
|
||||||
|
@ -49,7 +75,6 @@
|
||||||
'groupchat': function () {return String((new Date()).getTime()); }
|
'groupchat': function () {return String((new Date()).getTime()); }
|
||||||
},
|
},
|
||||||
'service': 'jasmine tests',
|
'service': 'jasmine tests',
|
||||||
'jid': 'dummy@localhost',
|
|
||||||
'addHandler': function (handler, ns, name, type, id, from, options) {
|
'addHandler': function (handler, ns, name, type, id, from, options) {
|
||||||
return function () {};
|
return function () {};
|
||||||
},
|
},
|
||||||
|
@ -87,5 +112,6 @@
|
||||||
'items': function () {}
|
'items': function () {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
return mock;
|
return mock;
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -9,6 +9,17 @@
|
||||||
}(this, function ($, mock) {
|
}(this, function ($, mock) {
|
||||||
var utils = {};
|
var utils = {};
|
||||||
|
|
||||||
|
utils.createRequest = function (iq) {
|
||||||
|
iq = typeof iq.tree == "function" ? iq.tree() : iq;
|
||||||
|
var req = new Strophe.Request(iq, function() {});
|
||||||
|
req.getResponse = function() {
|
||||||
|
var env = new Strophe.Builder('env', {type: 'mock'}).tree();
|
||||||
|
env.appendChild(iq);
|
||||||
|
return env;
|
||||||
|
};
|
||||||
|
return req;
|
||||||
|
};
|
||||||
|
|
||||||
utils.closeAllChatBoxes = function () {
|
utils.closeAllChatBoxes = function () {
|
||||||
var i, chatbox;
|
var i, chatbox;
|
||||||
for (i=converse.chatboxes.models.length-1; i>-1; i--) {
|
for (i=converse.chatboxes.models.length-1; i>-1; i--) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user