/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // Generate XML result data and submit it to Litmus // Note that this is essentially a direct port of the Test::Litmus perl // module. Please see http://search.cpan.org/~zlipton/Test-Litmus-0.03/lib/Test/Litmus.pm // for further information // See also the Litmus Web Services Specification at // http://wiki.mozilla.org/Litmus:Web_Services const VERSION = '0.0.2'; /** * Result constructor. * * @param machinename * (optional) * The name of the machine running the tests * @param username * Username of the account submitting results * @param password * Authentication token to be sent to the Litmus server * @param server * (optional) * The server to send results to */ function LitmusResults(a) { this.machinename = a.machinename || ''; this.requireField('username', a); this.requireField('password', a); this.server = a.server || 'https://litmus.mozilla.org/process_test.cgi'; this.action = 'submit'; this.results = new Array(); this.logs = new Array(); } LitmusResults.prototype = { // add fieldname to this unless it's missing, at which point we throw an // exception to the caller requireField : function (name, args) { if (args[name] === undefined) { throw "Missing required field in Litmus result submission: "+name; } this[name] = args[name]; }, sysconfig : function (a) { this.requireField('product', a); this.requireField('platform', a); this.requireField('opsys', a); this.requireField('branch', a); this.requireField('buildid', a); this.requireField('locale', a); this.buildtype = a.buildtype; }, addLog : function(log) { this.logs.push(log); }, addResult : function(result) { this.results.push(result); }, toXML : function() { var d = ''+"\n"; d += ''+"\n"; d += '' : '>') +"\n"; d += ' \n"; } else { d += ">\n"; } if (this.logs) { if (this.logs instanceof Array) { for(var i=0; i'+"\n"; d += ' '+"\n"; d += ''+"\n"; return d; } }; /** * Result constructor. * */ function Result(a) { this.requireField('testid', a); this.requireField('resultstatus', a); this.requireField('exitstatus', a); this.requireField('duration', a); // if no timestamp specified, use the current time if (a.timestamp) { this.timestamp = a.timestamp; } else { var d = new Date(); this.timestamp=''+d.getFullYear()+leadZero((d.getMonth()+1))+ leadZero(d.getDate())+leadZero(d.getHours())+leadZero(d.getMinutes())+ leadZero(d.getSeconds()); } this.comment = a.comment; this.bugnumber = a.bugnumber; this.logs = a.log; this.automated = a.isAutomatedResult ? a.isAutomatedResult : 1; } Result.prototype = { requireField : function (name, args) { if (args[name] === undefined) { throw "Missing required field in Litmus result submission: "+name; } this[name] = args[name]; }, toXML : function() { var d = ''+"\n"; if (this.comment) { d += ' '+this.comment+''+"\n"; } if (this.bugnumber) { d += ' '+this.bugnumber+''+"\n"; } if (this.logs) { if (this.logs instanceof Array) { for(var i=0; i