merging
[mozilla-central.git] / testing / extensions / community / chrome / content / qa.js
blob2c47e1911d1389c08d8c9a2e2a0f48acac1d55bb
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is the Mozilla Community QA Extension
15  *
16  * The Initial Developer of the Original Code is the Mozilla Corporation.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  *  Zach Lipton <zach@zachlipton.com>
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 2 or later (the "GPL"), or
25  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26  * in which case the provisions of the GPL or the LGPL are applicable instead
27  * of those above. If you wish to allow use of your version of this file only
28  * under the terms of either the GPL or the LGPL, and not to allow others to
29  * use your version of this file under the terms of the MPL, indicate your
30  * decision by deleting the provisions above and replace them with the notice
31  * and other provisions required by the GPL or the LGPL. If you do not delete
32  * the provisions above, a recipient may use your version of this file under
33  * the terms of any one of the MPL, the GPL or the LGPL.
34  *
35 * ***** END LICENSE BLOCK ***** */
38 var qaMain = {
39   htmlNS: "http://www.w3.org/1999/xhtml",
41   openQATool : function() {
42     window.open("chrome://qa/content/qa.xul", "_blank",
43                 "chrome,all,dialog=no,resizable=yes");
44   },
45   onToolOpen : function() {
46     if (qaPref.getPref(qaPref.prefBase+'.isFirstTime', 'bool') == true) {
47       window.open("chrome://qa/content/setup.xul", "_blank",
48                   "chrome,all,dialog=yes");
49         }
50     else {
51       // We need to log the user into litmus
52       var storedLogin = qaPref.litmus.getPasswordObj();
53       this.correctCredentials(storedLogin.username, storedLogin.password, false);
54     }
55     if (qaPref.getPref(qaPref.prefBase + '.currentTestcase.testrunSummary', 'char') != null) {
56             litmus.readStateFromPref();
57         }
58   },
59     onSwitchTab : function() {
60     var newSelection = $('qa_tabrow').selectedItem;
62     // user is switching to the prefs tab:
63     if ($('qa_tabrow').selectedItem == $('qa-tabbar-prefs')) {
64             qaPrefsWindow.loadPrefsWindow();
65     } else if ($('qa_tabrow').selectedItem == $('qa-tabbar-bugzilla')) {
66             bugzilla.unhighlightTab();
67         }
69     // user is switching away from the prefs tab:
70     if (qaPrefsWindow.lastSelectedTab != null &&
71         qaPrefsWindow.lastSelectedTab == $('qa-tabbar-prefs')) {
72       qaPrefsWindow.savePrefsWindow();
73     }
75     qaPrefsWindow.lastSelectedTab = newSelection;
76   },
78   correctCredentials : function(username, password,isSecondTry) {
79     var callback = function (resp) {
80       if (resp.responseText == 0) {
81         qaMain.doLogin(isSecondTry);
82       } else {
83         // Then we need to store our validated creds
84         qaPref.litmus.setPassword(username, password);
85       }
86     }
88     // First we validate our stored login.
89     litmus.validateLogin(username, password, callback);
90   },
92   doLogin : function(isSecondTry) {
93     try {
94       var username = {value: "username"};
95       var password = {value: "password"};
96       var check = {value: "null"};
97       var title = qaMain.bundle.getString("qa.getpassword.title");
98       var msg = "";
100       if (!isSecondTry)
101         msg = qaMain.bundle.getString("qa.getpassword.message");
102       else
103         msg = qaMain.bundle.getString("qa.getpassword.tryagainmessage");
105       var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
106                               .getService(Components.interfaces.nsIPromptService);
107       var result = prompts.promptUsernameAndPassword(null, title, msg, username,
108                                                      password, null, check);
110       this.correctCredentials(username.value, password.value, true);
111     } catch(ex) {
112       alert("ERROR LOGGING IN: " + ex);
113       dump("Error logging in: " + ex);
114     }
115   }
118 qaMain.__defineGetter__("bundle", function(){return $("bundle_qa");});
119 qaMain.__defineGetter__("urlbundle", function(){return $("bundle_urls");});
120 function $() {
121   var elements = new Array();
123 for (var i = 0; i < arguments.length; i++) {
124   var element = arguments[i];
125   if (typeof element == 'string')
126     element = document.getElementById(element);
128   if (arguments.length == 1)
129     return element;
131   elements.push(element);
132   }
134   return elements;