Skip to content

Instantly share code, notes, and snippets.

@arlolra arlolra/test.patch
Created Oct 24, 2014

Embed
What would you like to do?
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,63 @@
+/* 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://gre/modules/Task.jsm");
+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(aAccount) {
+ this._init(aAccount);
+}
+Conversation.prototype = {
+ __proto__: GenericConvIMPrototype,
+ prepareForSending: () => [],
+ sendMsg: function() {}
+};
+
+// 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);
+ iMsg.message = "";
+ equal(iMsg.message, "");
+};
+
+// Test message transformation path
+let test_message_transformation = function* () {
+ Services.conversations.initConversations();
+
+ let pConv = new Conversation();
+ let uiConv = new imConversations.UIConversation(pConv);
+ uiConv.sendMsg("Hello!");
+
+ Services.conversations.unInitConversations();
+};
+
+function run_test() {
+ add_task(test_null_message);
+ add_task(test_message_transformation);
+ 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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.