Fix result submission, mac platform detection (intel vs ppc), and add statistics display to litmus tab
authorzach@zachlipton.com
Wed, 15 Aug 2007 13:26:27 -0700
changeset 4682 2a91cc4c684c2126cf6612a8dd5f7bfb9b027bc5
parent 4681 fb91a6f30f3ffd85d138e1a6d48f0040edcc1aa7
child 4683 eacf56a59d315a0a1e73d2c280a8ae4a3e58895c
push idunknown
push userunknown
push dateunknown
milestone1.9a8pre
Fix result submission, mac platform detection (intel vs ppc), and add statistics display to litmus tab
testing/extensions/community/chrome/content/litmus.js
testing/extensions/community/chrome/content/tabs/litmus.xul
testing/extensions/community/chrome/locale/en-US/qa.properties
--- a/testing/extensions/community/chrome/content/litmus.js
+++ b/testing/extensions/community/chrome/content/litmus.js
@@ -35,16 +35,17 @@
  *
 * ***** END LICENSE BLOCK ***** */
 
 
  const FIREFOX_ID = "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}";
  
  var litmus = {
 	baseURL : qaPref.getPref(qaPref.prefBase+".litmus.url", "char"),
+	userStats : '',
 	
 	getTestcase : function(testcase_id, callback) {
         litmus.getLitmusJson(testcase_id, callback, "testcase_id=");
 	},
 	getSubgroup : function(subgroupID, callback) {
         litmus.getLitmusJson(subgroupID, callback, "subgroup_id=");
     },
     getTestgroup : function(testgroupID, callback) {
@@ -147,28 +148,28 @@
 	        password: passwd
 	    });
 	    qaTools.httpPostRequest(litmus.baseURL+'json.cgi', qs, callback);
 	},
 	createAccount : function() {
 	    alert("XXX: not implemented");
 	},
 	postResultXML : function(xml, callback, errback) {
-		var req = doSimpleXMLHttpRequest(litmus.baseURL+'process_test.cgi', 
-										    { data: xml });
-		req.addErrback(errback);
-		req.addCallback(function(resp) {
+		var qs = queryString({ data: xml});
+		var fake_callback = function(resp) {
 			// only call callback() if we really had a sucuess. XML 
 			// processing errors should result in a call to errback()
-			if ((/ok/i).exec(resp.responseText)) {
+			if ((/^ok/i).exec(resp.responseText)) {
 				callback(resp);
 			} else {
 				errback(resp);
 			}
-		});
+		};
+		qaTools.httpPostRequest(litmus.baseURL+'process_test.cgi', 
+										    qs, fake_callback, errback);
 	},
     
     currentSubgroupID: null,	
     
     writeStateToPref : function(testrunSummary, testgroupSummary, subgroupID, index) {
         qaPref.setPref(qaPref.prefBase + ".currentTestcase.testrunSummary", testrunSummary, "char");
         qaPref.setPref(qaPref.prefBase + ".currentTestcase.testgroupSummary", testgroupSummary, "char");
         qaPref.setPref(qaPref.prefBase + ".currentTestcase.subgroupId", subgroupID, "int");
@@ -178,16 +179,33 @@
         $("qa-testrun-label").value = qaPref.getPref(qaPref.prefBase + ".currentTestcase.testrunSummary", "char");
         $("qa-testgroup-label").value = qaPref.getPref(qaPref.prefBase + ".currentTestcase.testgroupSummary", "char");
         litmus.currentSubgroupID = qaPref.getPref(qaPref.prefBase + ".currentTestcase.subgroupId", "int");
         litmus.disableAll();
         
         if (litmus.currentSubgroupID != 0)
             litmus.getSubgroup(litmus.currentSubgroupID, function(subgroup) {litmus.statePopulateFields(subgroup); litmus.undisableAll();});
     },
+    loadStats : function() {
+    	// pull new user statistics from litmus
+    	var url = litmus.baseURL+'json.cgi?' + 'user_stats=' + qaPref.litmus.getUsername();
+    	var req = loadJSONDoc(url);
+    	req.addCallback(function(data) {
+    	  litmus.userStats = data;  
+    	  litmus.displayStats();
+    	});
+    },
+    displayStats : function() {
+    	var statbox = $('qa-litmus-stats');
+    	if (litmus.userStats != '') {
+    		var statline = qaMain.bundle.getFormattedString('qa.extension.litmus.stats', 
+    			[litmus.userStats.week, litmus.userStats.month, litmus.userStats.alltime]);
+    		statbox.value = statline;
+    	}
+    },
     checkRadioButtons : function() {
         var menu = document.getElementById('testlist');
         if (menu.selectedIndex == -1) return;
         var disable = menu.selectedItem.firstChild.getAttribute("checked");
         document.getElementById("qa-testcase-result").disabled = disable;
     },
     
     prevButton : function() {
@@ -310,17 +328,21 @@
 			resultstatus: rs,
 			exitstatus: 'Exited Normally',
 			duration: 0,
 			comment: $('qa-testcase-comment').value,
 			isAutomatedResult: 0
 		}));
 		
 		var callback = function(resp) {
-			
+			// increment the stat counters:
+			for (var i in litmus.userStats) {
+				litmus.userStats[i]++;
+			}
+			litmus.displayStats();
 		};
 		
 		var errback = function(resp) {
 			alert(resp.responseText);
 		};
 		
 		litmus.postResultXML(l.toXML(), callback, errback);        
         var item = menu.selectedItem;
@@ -392,18 +414,20 @@ Sysconfig.prototype = {
 			this.branch = '2.0 Branch';
 		} else if ((/^1\.5\./).exec(appinfo.version)) {
 			this.branch = '1.5 Branch';
 		}
 		if (! this.branch) { throw "branch" }
 			
         // platform:
         if (! this.platform) {
-			if ((/^Mac/).exec(navigator.platform)) {
-				this.platform = 'Mac';
+			if ((/^MacPPC/).exec(navigator.platform)) {
+				this.platform = 'Mac (PPC)';
+			} else if ((/^MacIntel/).exec(navigator.platform)) {
+				this.platform = 'Mac (Intel)';
 			} else if ((/^Win/).exec(navigator.platform)) {
 				this.platform = 'Windows';
 			} else if ((/^Linux/).exec(navigator.platform)) {
 				this.platform = 'Linux';
 			} else if ((/^Solaris/).exec(navigator.platform)) {
 				this.platform = 'Solaris';
 			}
 			if (! this.platform) { throw "platform" }
@@ -427,17 +451,17 @@ Sysconfig.prototype = {
         			this.opsys = 'Windows ME';
         			break;
         		case 'Win98':
         			this.opsys = 'Windows 98';
         			break;
         	}
         } else if (this.platform == 'Linux') {
         	this.opsys = 'Linux';
-        } else if (this.platform == 'Mac') {
+        } else if (this.platform == 'Mac (PPC)' || this.platform == 'Mac (Intel)') {
         	// no way to detect the OS on mac, so just assume 
         	// it's 10.4. The user can provide the real OS in setup
         	this.opsys = 'Mac OS 10.4';
         }
         if (! this.opsys) {throw "opsys" }
         
         // locale
 		this.locale = navigator.language;
--- a/testing/extensions/community/chrome/content/tabs/litmus.xul
+++ b/testing/extensions/community/chrome/content/tabs/litmus.xul
@@ -39,17 +39,17 @@
 <?xml-stylesheet href="chrome://qa/skin/" type="text/css"?>
 
 <!DOCTYPE overlay [
 <!ENTITY % qaDTD SYSTEM "chrome://qa/locale/qa.dtd"> %qaDTD;
 <!ENTITY % xhtmlDTD SYSTEM "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> %xhtmlDTD;
 ]>
 
 <overlay id="qa-litmus-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
-<tabpanel id="qa-tab-litmus" onload="litmus.readStateFromPref()">
+<tabpanel id="qa-tab-litmus" onload="litmus.readStateFromPref();">
 		
 <vbox align="start" pack="start">
 	<hbox align="start" pack="start">
 		<vbox minwidth="150">
 			 <button maxwidth="110" label="&qa.litmus.selecttests;"
                      oncommand="litmus.handleDialog()"
                      style="margin-left: 4px;" />
 			 <label maxwidth="160" value="" id="qa-testrun-label"/>
@@ -103,12 +103,16 @@
 	<caption control="qa-testcase-comment" label="&qa.testcase.comment;"/>
 	<textbox id="qa-testcase-comment" style="min-height: 75px; width:150px;" class="plain"/>
     </groupbox>
 	</hbox>
 	<hbox flex="1" maxheight="30px">
 		 <button id="qa-mainwindow-previousButton" label="Previous" oncommand="litmus.prevButton()"/> 
 		<button id="qa-mainwindow-nextButton" label="Next (Submit)" oncommand="litmus.nextButton()"/>
 	</hbox>
+  <label id="qa-litmus-stats" value="" />
+  <script type="application/x-javascript">
+    this.addEventListener('load', litmus.loadStats, false);
+  </script>
 </vbox>
 </tabpanel>
 
 </overlay>
\ No newline at end of file
--- a/testing/extensions/community/chrome/locale/en-US/qa.properties
+++ b/testing/extensions/community/chrome/locale/en-US/qa.properties
@@ -1,8 +1,9 @@
 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 = Test %1$S of %2$S
\ No newline at end of file
+qa.extension.litmus.progress = Test %1$S of %2$S
+qa.extension.litmus.stats = My tests run - week: %1$S, month: %2$S, all time: %3$S
\ No newline at end of file