!import
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla MailNews test code.
16 *
17 * The Initial Developer of the Original Code is
18 * Mozilla Messaging.
19 * Portions created by the Initial Developer are Copyright (C) 2008
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38 const kStatePref = "testing.mailnewsTestHarness.state";
39
40 // Various delays to allow items to fully start/run
41 const kMailStartup = 5000;
42 const kABStartup = 2000;
43 const kComposeStartup = 5000;
44 const kMailRecheck = 2500;
45 const kABRecheck = 1000;
46 const kComposeRecheck = 1000;
47
48 var btPrefs = Components.classes["@mozilla.org/preferences-service;1"]
49 .getService(Components.interfaces.nsIPrefBranch);
50
51 var gCurrentTimeout;
52
53 // startBloatTest is the main function that hooks the state machines in. It is
54 // called via the "load" event listener for the window.
55 //
56 // We use the kStatePref to determine which state the tests are in.
57 //
58 // If kStatePref is not set, then we're the main mail window and are driving
59 // all the tests.
60 //
61 // If KStatePref is set to "startingAddressBook", then it is (hopefully) the
62 // address book window starting, and hence we are driving the address book
63 // tests.
startBloatTest
64 function startBloatTest()
65 {
66 dump("Inside startBloatTest\n\n\n");
67
68 // Make sure to launch the test harness in the correct state.
69 if (btPrefs.prefHasUserValue(kStatePref)) {
70 dump("pref has user value\n\n\n");
71 if (btPrefs.getCharPref(kStatePref) == "startingAddressBook")
72 setTimeout("handleABState();", kABStartup);
73 else if (btPrefs.getCharPref(kStatePref) == "startingComposeWindow")
74 setTimeout("handleComposeState();", kComposeStartup);
75
76 // Don't hook up for other windows.
77 }
78 else {
79 dump("pref does not have user value\n\n\n");
80 btPrefs.setCharPref(kStatePref, "start");
81
82 // wait a bit then kick the tests off
83 gCurrentTimeout = setTimeout("handleMailState();", kMailStartup);
84 }
85
86 removeEventListener("load", startBloatTest, false);
87 }
88
89 // handleMailState handles running of the Main Mail Window tests.
90 //
91 // It currently consists of:
92 // 1) start the address book
93 // 2) wait for "closingAddressBook"
94 // 3) close the Main Mail Window.
handleMailState
Called: ChromeWindow:getCharPref (10 calls, 173 v-uS)
ChromeWindow:prefHasUserValue (10 calls, 325 v-uS)
ChromeWindow:setTimeout (8 calls, 309 v-uS)
ChromeWindow:setCharPref (5 calls, 448 v-uS)
ChromeWindow:clearTimeout (2 calls, 125 v-uS)
ChromeWindow:clearUserPref (1 calls, 177 v-uS)
bloatTestOverlay.js:startComposeWindow (1 calls, 13803 v-uS)
globalOverlay.js:goQuitApplication (1 calls, 1756 v-uS)
mailCore.js:toOpenWindowByType (1 calls, 10689 v-uS)
95 function handleMailState()
96 {
97 if (!btPrefs.prefHasUserValue(kStatePref)) {
98 // This shouldn't happen.
99 dump(kStatePref + " not set when checked in checkState()\n");
100 return;
101 }
102
103 switch (btPrefs.getCharPref(kStatePref))
104 {
105 case "start":
106 // First thing to do is to start the address book and run its tests
107 btPrefs.setCharPref(kStatePref, "startingAddressBook");
108 toOpenWindowByType("mail:addressbook", "chrome://messenger/content/addressbook/addressbook.xul");
109 break;
110
111 case "closingAddressBook":
112 // Move onto the next step
113 btPrefs.setCharPref(kStatePref, "startComposeWindow");
114 break;
115
116 case "startComposeWindow":
117 btPrefs.setCharPref(kStatePref, "startingComposeWindow");
118 startComposeWindow();
119 break;
120
121 case "closingComposeWindow":
122 // Address book is being closed, so move onto the next state
123 btPrefs.setCharPref(kStatePref, "close");
124 break;
125
126 case "close":
127 // Tests finished, clear the timeout, clear the pref and close
128 // the window
129 clearTimeout(gCurrentTimeout);
130 btPrefs.clearUserPref(kStatePref);
131 goQuitApplication();
132 // Now return so we don't set the timeout again.
133 return;
134
135 // These are valid for other windows, but not part of this one
136 case "startingAddressBook":
137 case "closeAddressBook":
138 case "startingComposeWindow":
139 case "closeComposeWindow":
140 break;
141
142 default:
143 dump(kStatePref + " in invalid state: " + btPrefs.getCharPref(kStatePref) + "\n");
144 }
145 // check the state again after a while
146 gCurrentTimeout = setTimeout("handleMailState();", kMailRecheck);
147 }
148
149 // handleABState handles running of the Address Book Window tests.
150 //
151 // It currently consists of:
152 // 1) wait a little for the address book window to start.
153 // 2) close the address book window.
handleABState
Called: ChromeWindow:close (1 calls, 267 v-uS)
ChromeWindow:getCharPref (1 calls, 17 v-uS)
ChromeWindow:prefHasUserValue (1 calls, 30 v-uS)
ChromeWindow:setCharPref (1 calls, 95 v-uS)
ChromeWindow:setTimeout (1 calls, 46 v-uS)
154 function handleABState()
155 {
156 if (!btPrefs.prefHasUserValue(kStatePref)) {
157 // This shouldn't happen.
158 dump(kStatePref + " not set when checked in handleABState()\n");
159 return;
160 }
161
162 switch (btPrefs.getCharPref(kStatePref))
163 {
164 case "startingAddressBook":
165 // The AB test just moves onto closing itself for now.
166 btPrefs.setCharPref(kStatePref, "closeAddressBook");
167 break;
168
169 case "closeAddressBook":
170 // Tests finished, clear the timeout, set the closing pref and close
171 // the window
172 clearTimeout(gCurrentTimeout);
173 btPrefs.setCharPref(kStatePref, "closingAddressBook");
174 window.close();
175 // Now return so we don't set the timeout again.
176 return;
177
178 default:
179 dump(kStatePref + " in invalid state: " + btPrefs.getCharPref(kStatePref) + "\n");
180 }
181 // check the state again after a while
182 gCurrentTimeout = setTimeout("handleABState();", kABRecheck);
183 }
184
185 // handleComposeState handles running of the Compose Window tests.
186 //
187 // It currently consists of:
188 // 1) wait a little for the compose window to start.
189 // 2) close the compose window.
handleComposeState
Called: ChromeWindow:getCharPref (2 calls, 33 v-uS)
ChromeWindow:prefHasUserValue (2 calls, 65 v-uS)
ChromeWindow:setCharPref (2 calls, 202 v-uS)
ChromeWindow:clearTimeout (1 calls, 12 v-uS)
ChromeWindow:setTimeout (1 calls, 39 v-uS)
MsgComposeCommands.js:MsgComposeCloseWindow (1 calls, 14382 v-uS)
190 function handleComposeState()
191 {
192 if (!btPrefs.prefHasUserValue(kStatePref)) {
193 // This shouldn't happen.
194 dump(kStatePref + " not set when checked in handleABState()\n");
195 return;
196 }
197
198 switch (btPrefs.getCharPref(kStatePref))
199 {
200 case "startingComposeWindow":
201 // The AB test just moves onto closing itself for now.
202 btPrefs.setCharPref(kStatePref, "closeComposeWindow");
203 break;
204
205 case "closeComposeWindow":
206 // Tests finished, clear the timeout, set the closing pref and close
207 // the window
208 clearTimeout(gCurrentTimeout);
209 btPrefs.setCharPref(kStatePref, "closingComposeWindow");
210
211 // Call the correct close compose window function, this also skips the
212 // are you sure you want to close it prompt.
213 MsgComposeCloseWindow(true);
214
215 // Now return so we don't set the timeout again.
216 return;
217
218 default:
219 dump(kStatePref + " in invalid state: " + btPrefs.getCharPref(kStatePref) + "\n");
220 }
221 // check the state again after a while
222 gCurrentTimeout = setTimeout("handleComposeState();", kComposeRecheck);
223 }
224
startComposeWindow
Called: ChromeWindow:OpenComposeWindow (1 calls, 13599 v-uS)
ChromeWindow:getService (1 calls, 21 v-uS)
Called By: bloatTestOverlay.js:handleMailState (1 calls, 13803 v-uS)
225 function startComposeWindow()
226 {
227 var msgComposeService =
228 Components.classes["@mozilla.org/messengercompose;1"]
229 .getService(Components.interfaces.nsIMsgComposeService);
230
231 // Compose a new message, format HTML, default identity
232 msgComposeService.OpenComposeWindow(null, null, 0, 1, null, null);
233 }
234
235 // Add the startBloatTest call to the load event for the window.
236 addEventListener("load", startBloatTest, false);