Added noresults option.
authorMark Cote <mcote@mozilla.com>
Thu, 23 Jun 2011 12:55:40 -0400
changeset 52 03f7a22ca861ed8adad1d250cc354cfdf6bdf2e4
parent 51 19e184c0802181e6454e7a6bfd164b0367434dea
child 53 e6e7ec76a5b94904aa66e3eed5b5394a8e0ab41b
push id50
push usermcote@mozilla.com
push dateThu, 23 Jun 2011 16:55:45 +0000
Added noresults option.
client/speedtests.py
html/js/speedtests.js
--- a/client/speedtests.py
+++ b/client/speedtests.py
@@ -27,17 +27,17 @@ class Config(object):
     DEFAULT_CONF_FILE = 'speedtests.conf'
     
     def __init__(self):
         self.cfg = None
         self.local_port = 8111
         self.test_url = 'http://brasstacks.mozilla.com/speedtestssvr/start/?auto=true'
         self.cfg = None
 
-    def read(self, testmode=False, conf_file=None):
+    def read(self, testmode=False, noresults=False, conf_file=None):
         if not conf_file:
             conf_file = Config.DEFAULT_CONF_FILE
         self.cfg = ConfigParser.ConfigParser()
         self.cfg.read(conf_file)
         
         try:
             self.local_port = self.cfg.getint('speedtests', 'local_port')
         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
@@ -56,16 +56,18 @@ class Config(object):
         local_ip = socket.gethostbyname(socket.gethostname())
         if self.test_url.find('?') == -1:
             self.test_url += '?'
         else:
             self.test_url += '&'
         self.test_url += 'ip=%s&port=%d' % (local_ip, self.local_port)
         if testmode:
             self.test_url += '&test=true'
+        if noresults:
+            self.test_url += '&noresults=true'
 
 
 config = Config()
 
 
 class BrowserController(object):
     
     def __init__(self, os_name, browser_name, profiles, cmd, args_tuple=()):
@@ -370,19 +372,18 @@ class BrowserRunner(object):
             while True:
                 try:
                     n = self.iter.next()
                 except StopIteration:
                     raise
                 if not self.browser_names or n.browser_name in self.browser_names:
                     return n
                    
-    def __init__(self, evt, browser_names=[], testmode=False):
+    def __init__(self, evt, browser_names=[]):
         self.evt = evt
-        self.testmode = testmode
         try:
             self.browsers = BrowserRunner.browsers_by_os(platform.system())
         except KeyError:
             sys.stderr.write('Unknown platform "%s".\n' % platform.system())
             sys.exit(errno.EOPNOTSUPP)
         self.browser_iter = BrowserRunner.BrowserControllerIter(self.browsers, browser_names)
         self.current_controller = None
         self.lock = threading.Lock()
@@ -498,18 +499,19 @@ class TestRunnerRequestHandler(BaseHTTPS
 
 
 MAX_TEST_TIME = datetime.timedelta(seconds=60*10)
         
 def main():
     from optparse import OptionParser
     parser = OptionParser()
     parser.add_option('-t', '--test', dest='testmode', action='store_true')
+    parser.add_option('-n', '--noresults', dest='noresults', action='store_true')
     (options, args) = parser.parse_args()
-    config.read(options.testmode)
+    config.read(options.testmode, options.noresults)
     
     def get_browser_arg():
         try:
             browser = args[1]
         except IndexError:
             print 'Specify a browser.'
             sys.exit(errno.EINVAL)
         return browser
--- a/html/js/speedtests.js
+++ b/html/js/speedtests.js
@@ -73,32 +73,34 @@ var SpeedTests = function() {
       return etms;
     },
     nextTest: function (testname) {
       if (loadingNextTest) {
         return;
       }
       loadingNextTest = true;
       var searchParams = getSearchParams();
-      var results = {
+      if (searchParams.noresults === undefined) {
+        var results = {
           testname: testname,
           ip: searchParams.ip,
           results: all_results,
           ua: navigator.userAgent
-      };
-      if (searchParams.test !== undefined) {
+        };
+        if (searchParams.test !== undefined) {
           results.test = true;
+        }
+        var body = JSON.stringify(results);
+        var req = new XMLHttpRequest();
+        req.open("POST", DYNAMIC_SERVER_URL + "/testresults/", false);
+        req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+        req.setRequestHeader("Content-length", body.length);
+        req.setRequestHeader("Connection", "close");
+        req.send(body);
       }
-      var body = JSON.stringify(results);
-      var req = new XMLHttpRequest();
-      req.open("POST", DYNAMIC_SERVER_URL + "/testresults/", false);
-      req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
-      req.setRequestHeader("Content-length", body.length);
-      req.setRequestHeader("Connection", "close");
-      req.send(body);
 
       var url = DYNAMIC_SERVER_URL + "/nexttest/" + testname + "/" +
                 document.location.search;
       window.location.assign(url);
 //      var local_url = 'http://' + searchParams.ip + ':' + searchParams.port + '/';
 //      crossDomainPost(local_url, {body: body}, function () {
 //        var url = DYNAMIC_SERVER_URL + "/nexttest/" + testname + "/" +
 //                  document.location.search;