Created
October 30, 2014 00:48
-
-
Save arlolra/e4cbb929f64467c4383b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HG changeset patch | |
# User Arlo Breault <arlolra@gmail.com> | |
# Date 1414370632 25200 | |
# Sun Oct 26 17:43:52 2014 -0700 | |
# Node ID dc8fd5bdcfede981cef6289203626f9bd83bf9b9 | |
# Parent 030063bcb41284997f862b9b2d12e93bfc0b121a | |
Test | |
diff --git a/chat/components/src/imConversations.js b/chat/components/src/imConversations.js | |
--- a/chat/components/src/imConversations.js | |
+++ b/chat/components/src/imConversations.js | |
@@ -59,16 +59,17 @@ imMessage.prototype = { | |
get containsNick() this.prplMessage.containsNick, | |
get noLog() this.prplMessage.noLog, | |
get error() this.prplMessage.error, | |
get delayed() this.prplMessage.delayed, | |
get noFormat() this.prplMessage.noFormat, | |
get containsImages() this.prplMessage.containsImages, | |
get notification() this.prplMessage.notification, | |
get noLinkification() this.prplMessage.noLinkification, | |
+ get originalMessage() this.prplMessage.originalMessage, | |
getActions: function(aCount) this.prplMessage.getActions(aCount || {}) | |
}; | |
function UIConversation(aPrplConversation) | |
{ | |
this._prplConv = {}; | |
this.id = ++gLastUIConvId; | |
this._observers = []; | |
@@ -120,17 +121,19 @@ UIConversation.prototype = { | |
_currentTargetId: 0, | |
changeTargetTo: function(aPrplConversation) { | |
let id = aPrplConversation.id; | |
if (this._currentTargetId == id) | |
return; | |
if (!(id in this._prplConv)) { | |
this._prplConv[id] = aPrplConversation; | |
- aPrplConversation.addObserver(this.observeConv.bind(this, id)); | |
+ aPrplConversation.addObserver({ | |
+ observe: this.observeConv.bind(this, id) | |
+ }); | |
} | |
let shouldNotify = this._currentTargetId; | |
this._currentTargetId = id; | |
if (!this.isChat) { | |
let buddy = this.buddy; | |
if (buddy) | |
({statusType: this.statusType, statusText: this.statusText}) = buddy; | |
diff --git a/chat/components/src/test/test_conversations.js b/chat/components/src/test/test_conversations.js | |
new file mode 100644 | |
--- /dev/null | |
+++ b/chat/components/src/test/test_conversations.js | |
@@ -0,0 +1,118 @@ | |
+/* This Source Code Form is subject to the terms of the Mozilla Public | |
+ * License, v. 2.0. If a copy of the MPL was not distributed with this | |
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
+ | |
+const { interfaces: Ci, utils: Cu } = Components; | |
+ | |
+let jsProtoHelper = {}, imConversations = {}; | |
+ | |
+Cu.import("resource:///modules/imServices.jsm"); | |
+Cu.import("resource:///modules/jsProtoHelper.jsm", jsProtoHelper); | |
+ | |
+Services.scriptloader.loadSubScript( | |
+ "resource:///components/imConversations.js", imConversations | |
+); | |
+ | |
+// Fake prplMessage | |
+function Message(aWho, aMessage, aObject) { | |
+ this._init(aWho, aMessage, aObject); | |
+} | |
+Message.prototype = { | |
+ __proto__: jsProtoHelper.GenericMessagePrototype | |
+}; | |
+ | |
+// Fake prplConversation | |
+function Conversation(aName) { | |
+ this._name = aName; | |
+ this._observers = []; | |
+ this._date = new Date() * 1000; | |
+} | |
+Conversation.prototype = { | |
+ __proto__: jsProtoHelper.GenericConvIMPrototype, | |
+ _account: { | |
+ imAccount: { | |
+ protocol: { name: "Fake Protocol" }, | |
+ alias: "", | |
+ name: "Fake Account" | |
+ }, | |
+ ERROR: function(e) { throw e } | |
+ } | |
+}; | |
+ | |
+// Ensure blank messages don't return original message. | |
+let test_null_message = function() { | |
+ let originalMessage = "Hi!"; | |
+ let pMsg = new Message("buddy", originalMessage, { | |
+ outgoing: true, _alias: "buddy", time: Date.now() | |
+ }); | |
+ let iMsg = new imConversations.imMessage(pMsg); | |
+ equal(iMsg.message, originalMessage); | |
+ // Setting the message should prevent a fallback to the original. | |
+ iMsg.message = ""; | |
+ equal(iMsg.message, ""); | |
+ equal(iMsg.originalMessage, originalMessage); | |
+}; | |
+ | |
+// Example transformation | |
+function rot13(aString) | |
+ aString.replace(/[a-zA-Z]/g, function(c) | |
+ String.fromCharCode(c.charCodeAt(0) + (c.toLowerCase() < "n" ? 1 : -1) * 13)) | |
+ | |
+// Test message transformation path | |
+let test_message_transformation = function() { | |
+ let pConv = new Conversation(); | |
+ pConv.sendMsg = function(aMsg) { | |
+ this.writeMessage("user2", aMsg, { outgoing: true }); | |
+ }; | |
+ pConv.id = 1; | |
+ | |
+ let uiConv = new imConversations.UIConversation(pConv); | |
+ let message = "Hello!"; | |
+ let receivedMsg = false, newTxt = false; | |
+ | |
+ let observer = { | |
+ observe: function(aObject, aTopic, aMsg) { | |
+ switch(aTopic) { | |
+ case "sending-message": | |
+ ok(!newTxt); | |
+ ok(!receivedMsg); | |
+ ok(aObject instanceof imConversations.OutgoingMessage); | |
+ aObject.message = rot13(aObject.message); | |
+ break; | |
+ case "received-message": | |
+ ok(!newTxt); | |
+ ok(!receivedMsg); | |
+ ok(aObject.outgoing); | |
+ ok(aObject instanceof imConversations.imMessage); | |
+ equal(aObject.displayMessage, rot13(message)); | |
+ aObject.displayMessage = rot13(aObject.displayMessage); | |
+ receivedMsg = true; | |
+ break; | |
+ case "new-text": | |
+ ok(!newTxt); | |
+ ok(receivedMsg); | |
+ ok(aObject.outgoing); | |
+ ok(aObject instanceof imConversations.imMessage); | |
+ equal(aObject.displayMessage, message); | |
+ newTxt = true; | |
+ break; | |
+ } | |
+ } | |
+ }; | |
+ uiConv.addObserver(observer); | |
+ uiConv.sendMsg(message); | |
+ | |
+ ok(newTxt); | |
+}; | |
+ | |
+// Test cancelling a message | |
+let test_cancel_message = function() { | |
+ | |
+}; | |
+ | |
+function run_test() { | |
+ test_null_message(); | |
+ test_message_transformation(); | |
+ test_cancel_message(); | |
+ run_next_test(); | |
+} | |
diff --git a/chat/components/src/test/xpcshell.ini b/chat/components/src/test/xpcshell.ini | |
--- a/chat/components/src/test/xpcshell.ini | |
+++ b/chat/components/src/test/xpcshell.ini | |
@@ -3,9 +3,10 @@ | |
; file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
[DEFAULT] | |
head = | |
tail = | |
[test_accounts.js] | |
[test_commands.js] | |
+[test_conversations.js] | |
[test_logger.js] | |
diff --git a/chat/modules/jsProtoHelper.jsm b/chat/modules/jsProtoHelper.jsm | |
--- a/chat/modules/jsProtoHelper.jsm | |
+++ b/chat/modules/jsProtoHelper.jsm | |
@@ -476,17 +476,17 @@ const GenericConversationPrototype = { | |
try { | |
observer.observe(aSubject, aTopic, aData); | |
} catch(e) { | |
this.ERROR(e); | |
} | |
} | |
}, | |
- prepareForSending: function(aOutgoingMessage, aCount) null, | |
+ prepareForSending: function(aOutgoingMessage, aCount) [], | |
prepareForDisplaying: function(aImMessage) {}, | |
sendMsg: function(aMsg) { | |
throw Cr.NS_ERROR_NOT_IMPLEMENTED; | |
}, | |
sendTyping: function(aString) Ci.prplIConversation.NO_TYPING_LIMIT, | |
close: function() { | |
Services.obs.notifyObservers(this, "closing-conversation", null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment