Merge lp:~mconley/messagingmenu-extension/init_tests into lp:messagingmenu-extension

Proposed by Mike Conley
Status: Needs review
Proposed branch: lp:~mconley/messagingmenu-extension/init_tests
Merge into: lp:messagingmenu-extension
Diff against target: 248 lines (+79/-103)
3 files modified
modules/MessagingMenu.jsm (+4/-0)
tests/README (+13/-0)
tests/test-messaging-menu.js (+62/-103)
To merge this branch: bzr merge lp:~mconley/messagingmenu-extension/init_tests
Reviewer Review Type Date Requested Status
Chris Coulson Pending
Review via email: mp+76243@code.launchpad.net

Description of the change

Just a simple set of tests to get the ball rolling here.

To post a comment you must log in.

Unmerged revisions

87. By Mike Conley

Adding testing README.

86. By Mike Conley

Merging with 0.9

85. By Mike Conley

Added some hooks for testing and some really, really basic tests.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/MessagingMenu.jsm'
2--- modules/MessagingMenu.jsm 2011-09-15 00:01:36 +0000
3+++ modules/MessagingMenu.jsm 2011-09-20 15:36:23 +0000
4@@ -345,6 +345,7 @@
5 if (!shouldRequestAtt) {
6 let recipients = aItemHeader.recipients.split(",");
7 let re = /.*<([^>]*)>/; // Convert "Foo <bar>" in to "bar"
8+
9 for (let i in recipients) {
10 let recipient = recipients[i].replace(re, "$1");
11 if (shouldRequestAtt) {
12@@ -435,6 +436,8 @@
13 indicate.indicate_indicator_set_property(this.indicator,
14 indicate.INDICATOR_MESSAGES_PROP_ATTENTION,
15 "true");
16+ Services.obs.notifyObservers(this, "messagingmenu-request-attention", this.newCount);
17+ LOG("All done.");
18 },
19
20 cancelAttention: function MMIE_cancelAttention() {
21@@ -447,6 +450,7 @@
22 indicate.indicate_indicator_set_property(this.indicator,
23 indicate.INDICATOR_MESSAGES_PROP_ATTENTION,
24 "false");
25+ Services.obs.notifyObservers(this, "messagingmenu-cancel-attention", null);
26 },
27
28 set label(aName) {
29
30=== added file 'tests/README'
31--- tests/README 1970-01-01 00:00:00 +0000
32+++ tests/README 2011-09-20 15:36:23 +0000
33@@ -0,0 +1,13 @@
34+= How to run the Messaging Menu / Unity Launcher tests =
35+
36+1. Symbolically link the folder with this README in it, to [Thunderbird source dir]/mail/test/mozmill/messagingmenu@mozilla.com
37+
38+2. Build this add-on, using:
39+
40+ sh build.sh
41+
42+3. Build Thunderbird, and then switch into your objdir directory.
43+
44+4. From the Thunderbird objdir directory, run the tests via:
45+
46+ SOLO_TEST=messagingmenu@mozilla.com MOZMILL_EXTRA="--addons=[absolute path to edsintegration.xpi]" make mozmill-one
47
48=== modified file 'tests/test-messaging-menu.js'
49--- tests/test-messaging-menu.js 2011-06-06 14:48:46 +0000
50+++ tests/test-messaging-menu.js 2011-09-20 15:36:23 +0000
51@@ -15,11 +15,11 @@
52 *
53 * The Initial Developer of the Original Code is
54 * the Mozilla Foundation.
55- * Portions created by the Initial Developer are Copyright (C) 2010
56+ * Portions created by the Initial Developer are Copyright (C) 2011
57 * the Initial Developer. All Rights Reserved.
58 *
59 * Contributor(s):
60- * Mike Conley <mconley@mozillamessaging.com>
61+ * Mike Conley <mconley@mozilla.com>
62 *
63 * Alternatively, the contents of this file may be used under the terms of
64 * either the GNU General Public License Version 2 or later (the "GPL"), or
65@@ -35,123 +35,82 @@
66 *
67 * ***** END LICENSE BLOCK ***** */
68
69-/*
70- * Test that message reloads happen properly when the message pane is hidden,
71- * and then made visible again.
72- */
73 var MODULE_NAME = "test-messaging-menu";
74
75 var RELATIVE_ROOT = "../shared-modules";
76 var MODULE_REQUIRES = ["folder-display-helpers"];
77
78-var Indicator = null;
79-var msg = null;
80-var folder = null;
81-var msgSets = [];
82-
83-var IndicatorMock = function()
84-{
85- this.doIndications = [];
86- this.stopIndications = [];
87-};
88-
89-var doIndication = function(folderURL, label, messageURL, count,
90- dateInSeconds)
91-{
92- Indicator.doIndications.push({folderURL: folderURL,
93- label: label,
94- count: count,
95- messageURL: messageURL,
96- dateInSeconds: dateInSeconds});
97-};
98-
99-var stopIndication = function(folderURL)
100-{
101- Indicator.stopIndications.push({folderURL: folderURL});
102-}
103+var Cc = Components.classes;
104+var Ci = Components.interfaces;
105+var Cu = Components.utils;
106+
107+var gFolder;
108+
109+var IndicatorHelper = {
110+ _sawIndicatorAttention: false,
111+ _seenIndicator: null,
112+
113+ plan_for_indicator_attention: function(aController) {
114+ this._sawIndicatorAttention = false;
115+ this._seenIndicator = null;
116+ Services.obs.addObserver(this, "messagingmenu-request-attention", false);
117+ },
118+
119+ wait_for_indicator_attention: function(aController) {
120+ aController.waitFor(function() this._sawIndicatorAttention,
121+ "Timed out waiting for indicator attention",
122+ 5000, 100, this);
123+ Services.obs.removeObserver(this, "messagingmenu-request-attention");
124+ assert_not_equals(this._seenIndicator, null,
125+ "Indication was observed, but could not get Indicator.");
126+ return this._seenIndicator;
127+ },
128+
129+ check_for_no_indicator_attention: function(aController) {
130+ Services.obs.removeObserver(this, "messagingmenu-request-attention");
131+ assert_equals(null, this._seenIndicator,
132+ "Indicator attention was observed.");
133+ },
134+
135+ observe: function IH_observe(aSubject, aTopic, aData) {
136+ if (aTopic == "messagingmenu-request-attention") {
137+ this._seenIndicator = aSubject;
138+ this._sawIndicatorAttention = true;
139+ }
140+ },
141+
142+};
143
144
145 function setupModule(module)
146 {
147 let fdh = collector.getModule('folder-display-helpers');
148 fdh.installInto(module);
149- folder = create_folder("Test folder");
150-}
151-
152-function setupTest(test)
153-{
154- if(Indicator)
155- delete Indicator;
156- Indicator = new IndicatorMock();
157- mc.window.uMessagingMenu._doIndicationHook = doIndication;
158- mc.window.uMessagingMenu._stopIndicationHook = stopIndication;
159- be_in_folder(inboxFolder);
160-}
161-
162-function teardownTest(test)
163-{
164- for each (let msgSet in msgSets) {
165- delete_message_set(msgSet);
166- }
167- msgSets = [];
168-}
169-
170-function add_message_set_to_folder(aFolder, aNumToAdd)
171-{
172- let [msgSet] = make_new_sets_in_folder(aFolder, [{count:aNumToAdd}]);
173- msgSets.push(msgSet);
174- return msgSet;
175-}
176-
177-function test_new_inbox_mail_causes_indicate()
178-{
179- add_message_set_to_folder(inboxFolder, 1);
180- assert_equals(1, Indicator.doIndications.length);
181-}
182-
183-function test_uninteresting_folders_do_not_indicate()
184+ gFolder = create_folder("Test folder");
185+}
186+
187+function test_new_inbox_mail_causes_indication_and_attention()
188+{
189+ IndicatorHelper.plan_for_indicator_attention(mc);
190+ make_new_sets_in_folder(gFolder, [{count: 1,
191+ to: [["Tinderbox", "tinderbox@invalid.com"]]}]);
192+ IndicatorHelper.wait_for_indicator_attention(mc);
193+}
194+
195+
196+function test_uninteresting_folders_do_not_get_attention()
197 {
198 let uninteresting = [Ci.nsMsgFolderFlags.Trash, Ci.nsMsgFolderFlags.Junk,
199 Ci.nsMsgFolderFlags.SentMail, Ci.nsMsgFolderFlags.Drafts,
200- Ci.nsMsgFolderFlags.Templates, Ci.nsMsgFolderFlags.Queue];
201+ Ci.nsMsgFolderFlags.Templates, Ci.nsMsgFolderFlags.Queue,
202+ Ci.nsMsgFolderFlags.Archive];
203
204 for each (let folder_type in uninteresting) {
205- folder.setFlag(folder_type);
206- add_message_set_to_folder(folder, 1);
207- assert_equals(0, Indicator.doIndications.length);
208- folder.clearFlag(folder_type);
209+ gFolder.setFlag(folder_type);
210+ IndicatorHelper.plan_for_indicator_attention(mc);
211+ make_new_sets_in_folder(gFolder, [{count: 1}]);
212+ IndicatorHelper.check_for_no_indicator_attention(mc);
213+ gFolder.clearFlag(folder_type);
214 }
215
216 }
217-
218-function test_clicking_new_message_hides_indicator()
219-{
220- add_message_set_to_folder(inboxFolder, 1);
221- let msgHdr = select_click_row(0);
222- open_selected_message();
223- wait_for_message_display_completion(mc);
224- assert_equals(1, Indicator.stopIndications.length);
225-}
226-
227-function test_show_oldest_new_unread_message()
228-{
229- let firstMsgSet = add_message_set_to_folder(inboxFolder, 1);
230- let firstMsgURL = firstMsgSet.getMsgURI(0);
231- add_message_set_to_folder(inboxFolder, 2);
232- assert_equals(3, Indicator.doIndications.length);
233- assert_equals(firstMsgURL, Indicator.doIndications[2].messageURL);
234-}
235-
236-function test_indicates_new_unread_after_previous_indication()
237-{
238- add_message_set_to_folder(inboxFolder, 1);
239- select_click_row(0);
240- let secondMsgSet = add_message_set_to_folder(inboxFolder, 1);
241- let secondMsgURL = secondMsgSet.getMsgURI(0);
242-
243- assert_equals(2, Indicator.doIndications.length);
244- assert_equals(1, Indicator.stopIndications.length);
245- assert_equals(secondMsgURL, Indicator.doIndications[1].messageURL);
246-}
247-
248-

Subscribers

People subscribed via source and target branches

to all changes: