bug 433936 r=jay Fix QAC login process
authorctalbert@mozilla.com
Fri, 16 May 2008 09:59:37 -0700
changeset 15151 f61cf81288302cf95a0818ed5a72a5843809c04e
parent 15134 e70e05d8eda2ad68d8b1039d7f78944dda15ee13
child 15152 a2d0b3f6238742f1d194759988639f557877f69b
push idunknown
push userunknown
push dateunknown
reviewersjay
bugs433936
milestone1.9pre
bug 433936 r=jay Fix QAC login process
testing/extensions/community/chrome/content/prefs.js
testing/extensions/community/chrome/content/qa.js
testing/extensions/community/chrome/locale/en-US/qa.properties
testing/extensions/community/install.rdf
--- a/testing/extensions/community/chrome/content/prefs.js
+++ b/testing/extensions/community/chrome/content/prefs.js
@@ -171,28 +171,28 @@ var CC_loginManager = Components.classes
       }
 
       var nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
                                         Components.interfaces.nsILoginInfo,
                                         "init");
 
       // The LoginManager does not like "null" for username/password fields,
       // So we send in the field names from the XUL.
-      var newLogin = new nsLoginInfo('chrome://qa', 'Litmus Login', litmus.baseURL,
+      var newLogin = new nsLoginInfo('chrome://qa', null, litmus.baseURL,
                                      username, password, "username", "password");
       try {
         this.manager().addLogin(newLogin);
       } catch (err) {
         alert("ERROR: " + err);
       }
     },
     getPasswordObj: function() {
       try {
         var logins = this.manager().findLogins({}, 'chrome://qa',
-          'Litmus Login', litmus.baseURL);
+          null, litmus.baseURL);
         if (logins.length > 0 && logins[0] != null)
           return logins[0];
         return false;
       } catch(ex) {
         return false;
       }
     }
   };
--- a/testing/extensions/community/chrome/content/qa.js
+++ b/testing/extensions/community/chrome/content/qa.js
@@ -42,16 +42,21 @@ var qaMain = {
     window.open("chrome://qa/content/qa.xul", "_blank",
                 "chrome,all,dialog=no,resizable=yes");
   },
   onToolOpen : function() {
     if (qaPref.getPref(qaPref.prefBase+'.isFirstTime', 'bool') == true) {
       window.open("chrome://qa/content/setup.xul", "_blank",
                   "chrome,all,dialog=yes");
         }
+    else {
+      // We need to log the user into litmus
+      var storedLogin = qaPref.litmus.getPasswordObj();
+      this.correctCredentials(storedLogin.username, storedLogin.password, false);
+    }
     if (qaPref.getPref(qaPref.prefBase + '.currentTestcase.testrunSummary', 'char') != null) {
             litmus.readStateFromPref();
         }
   },
     onSwitchTab : function() {
     var newSelection = $('qa_tabrow').selectedItem;
 
     // user is switching to the prefs tab:
@@ -63,16 +68,55 @@ var qaMain = {
 
     // user is switching away from the prefs tab:
     if (qaPrefsWindow.lastSelectedTab != null &&
         qaPrefsWindow.lastSelectedTab == $('qa-tabbar-prefs')) {
       qaPrefsWindow.savePrefsWindow();
     }
 
     qaPrefsWindow.lastSelectedTab = newSelection;
+  },
+
+  correctCredentials : function(username, password,isSecondTry) {
+    var callback = function (resp) {
+      if (resp.responseText == 0) {
+        qaMain.doLogin(isSecondTry);
+      } else {
+        // Then we need to store our validated creds
+        qaPref.litmus.setPassword(username, password);
+      }
+    }
+
+    // First we validate our stored login.
+    litmus.validateLogin(username, password, callback);
+  },
+
+  doLogin : function(isSecondTry) {
+    try {
+      var username = {value: "username"};
+      var password = {value: "password"};
+      var check = {value: "null"};
+      var title = qaMain.bundle.getString("qa.getpassword.title");
+      var msg = "";
+
+      if (!isSecondTry)
+        msg = qaMain.bundle.getString("qa.getpassword.message");
+      else
+        msg = qaMain.bundle.getString("qa.getpassword.tryagainmessage");
+
+      var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+                              .getService(Components.interfaces.nsIPromptService);
+      var result = prompts.promptUsernameAndPassword(null, title, msg, username,
+                                                     password, null, check);
+
+      this.correctCredentials(username.value, password.value, true);
+    } catch(ex) {
+      alert("ERROR LOGGING IN: " + ex);
+      dump("Error logging in: " + ex);
+    }
   }
 };
 
 qaMain.__defineGetter__("bundle", function(){return $("bundle_qa");});
 qaMain.__defineGetter__("urlbundle", function(){return $("bundle_urls");});
 function $() {
   var elements = new Array();
 
--- a/testing/extensions/community/chrome/locale/en-US/qa.properties
+++ b/testing/extensions/community/chrome/locale/en-US/qa.properties
@@ -37,9 +37,12 @@
 
 qa.extension.testcase.head = Testcase #
 qa.extension.prefs.loginError = Login Error. Please check your username and password or create a new account.
 qa.extension.prefs.loadingMsg = Validating account information. Please Wait...
 qa.extension.prefs.savedMsg = Your settings have been saved
 qa.extension.sysconfig.loadingMsg = Loading menu options...
 qa.extension.loading = Loading...
 qa.extension.litmus.progress = Now Testing %1$S of %2$S
-qa.extension.litmus.stats = Tests Completed - Week: %1$S, Month: %2$S, All Time: %3$S
\ No newline at end of file
+qa.extension.litmus.stats = Tests Completed - Week: %1$S, Month: %2$S, All Time: %3$S
+qa.getpassword.title = Login to Litmus
+qa.getpassword.message = Enter the login information for your Litmus Account
+qa.getpassword.tryagainmessage = Incorrect login information.  Please enter the email address and password for your Litmus Account, if you have forgotten it, ask on IRC in #qa to have it reset.
--- a/testing/extensions/community/install.rdf
+++ b/testing/extensions/community/install.rdf
@@ -1,19 +1,19 @@
 <?xml version="1.0"?>
 <RDF:RDF xmlns:em="http://www.mozilla.org/2004/em-rdf#"
          xmlns:NC="http://home.netscape.com/NC-rdf#"
          xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
   <RDF:Description RDF:about="rdf:#$QJqvE"
                    em:id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
                    em:minVersion="2.0"
-                   em:maxVersion="3.0"/>
+                   em:maxVersion="3.0.*"/>
   <RDF:Description RDF:about="urn:mozilla:install-manifest"
                    em:id="{667e9f3d-0096-4d2b-b171-9a96afbabe20}"
-                   em:version="0.1.12"
+                   em:version="0.1.14"
                    em:type="2"
                    em:name="Mozilla QA Companion"
                    em:description="The QA tool for testers."
                    em:creator="Mozilla QA Team"
                    em:homepageURL="http://quality.mozilla.org/"
                    em:iconURL="chrome://qa/skin/qmo_logo_32x32.png">
     <em:targetApplication RDF:resource="rdf:#$QJqvE"/>
   </RDF:Description>