Bug 824150 - Code cleanup in /mail/ and /mailnews/: Use new String methods like startsWith, endsWith, contains, remaining Services.jsm switches and querySelector use instead of NodeList calls: /mailnews/test/: performance and resources. r=mbanner
authorSebastian Hengst <archaeopteryx@coole-files.de>
Sat, 09 Feb 2013 19:57:36 +0100
changeset 14843 e89c30d54a1e8bd5ef82f0ff9d29b6a0d520c6ed
parent 14842 59e6970aea76a5207a7ab01b476a8fd2ce081b71
child 14844 0a6e923be4e9ef0a8ca1e5c32cfcf2a9cfbe40dd
push id867
push userbugzilla@standard8.plus.com
push dateMon, 01 Apr 2013 20:44:27 +0000
treeherdercomm-beta@797726b8d244 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbanner
bugs824150
Bug 824150 - Code cleanup in /mail/ and /mailnews/: Use new String methods like startsWith, endsWith, contains, remaining Services.jsm switches and querySelector use instead of NodeList calls: /mailnews/test/: performance and resources. r=mbanner
mailnews/test/performance/bloat/bloatMainOverlay.js
mailnews/test/resources/logHelper.js
mailnews/test/resources/mailDirService.js
mailnews/test/resources/messageGenerator.js
--- a/mailnews/test/performance/bloat/bloatMainOverlay.js
+++ b/mailnews/test/performance/bloat/bloatMainOverlay.js
@@ -1,13 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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/. */
 
+Components.utils.import("resource://gre/modules/Services.jsm");
+
 // Milliseconds. Decided on MacBook 2.4GHz Intel (Dual Core).
 // 4s seemed a resonable time for the main window to be displayed.
 const kMailStartup = 4000;
 // The other two windows (compose + addrbook) are closed after 3 seconds,
 // well close after 8 to allow a little extra time - if they get delayed, then
 // well get a prompt for closing the compose window that we don't want.
 // See bug 321783.
 const kMailClose = 8000;
@@ -24,20 +26,17 @@ function startMainTest()
   toOpenWindowByType("mail:addressbook",
                      "chrome://messenger/content/addressbook/addressbook.xul");
 
   startComposeWindow();
 }
 
 function shutdownMainWindow()
 {
-  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
-                     .getService(Components.interfaces.nsIWindowMediator);
-
-  var window = wm.getMostRecentWindow("msgcompose");
+  var window = Services.wm.getMostRecentWindow("msgcompose");
 
   // Double-check because of bug 321783
   if (window)
   {
     // It hasn't shutdown yet, reset the timeout
     dump("XXX Trying to quit too early, delaying shutdown to stop bug 321783 affecting us\n");
     setTimeout(shutdownMainWindow, kMailWaitTotal);
     return;
--- a/mailnews/test/resources/logHelper.js
+++ b/mailnews/test/resources/logHelper.js
@@ -5,16 +5,17 @@
  * Right now the most meaningful thing to know is that if XPCOM failures happen
  *  (and get reported to the error console), this will induce a unit test
  *  failure.  You should think this is awesome no matter whether you are Andrew
  *  or not.
  */
 
 Components.utils.import("resource:///modules/gloda/log4moz.js");
 Components.utils.import("resource:///modules/IOUtils.js");
+Components.utils.import("resource://gre/modules/Services.jsm");
 
 var _testLogger;
 var _xpcshellLogger;
 var _testLoggerContexts = [];
 var _testLoggerActiveContext;
 
 var _logHelperInterestedListeners = false;
 
@@ -32,44 +33,38 @@ function logHelperHasInterestedListeners
  *  send everything but I think only script errors are likely of much concern.
  *  Also, this nicely avoids infinite recursions no matter what you do since
  *  what we publish is not going to end up as an nsIScriptError.
  *
  * This is based on my (asuth') exmmad extension.
  */
 let _errorConsoleTunnel = {
   initialize: function () {
-    this.consoleService = Cc["@mozilla.org/consoleservice;1"]
-                            .getService(Ci.nsIConsoleService);
-    this.consoleService.registerListener(this);
+    Services.console.registerListener(this);
 
     // we need to unregister our listener at shutdown if we don't want explosions
-    this.observerService = Cc["@mozilla.org/observer-service;1"]
-                             .getService(Ci.nsIObserverService);
-    this.observerService.addObserver(this, "quit-application", false);
+    Services.obs.addObserver(this, "quit-application", false);
   },
 
   shutdown: function () {
-    this.consoleService.unregisterListener(this);
-    this.observerService.removeObserver(this, "quit-application");
-    this.consoleService = null;
-    this.observerService = null;
+    Services.console.unregisterListener(this);
+    Services.obs.removeObserver(this, "quit-application");
   },
 
   observe: function (aMessage, aTopic, aData) {
     if (aTopic == "quit-application") {
       this.shutdown();
       return;
     }
 
     try {
       // meh, let's just use mark_failure for now.
       // and let's avoid feedback loops (happens in mozmill)
       if ((aMessage instanceof Components.interfaces.nsIScriptError) &&
-        (aMessage.errorMessage.indexOf("Error console says") == -1))
+        (!aMessage.errorMessage.contains("Error console says")))
         mark_failure(["Error console says", aMessage]);
     }
     catch (ex) {
       // This is to avoid pathological error loops.  we definitely do not
       // want to propagate an error here.
     }
   }
 };
@@ -100,19 +95,17 @@ function _init_log_helper() {
   let dapp = new Log4Moz.DumpAppender(formatter);
   dapp.level = Log4Moz.Level.All;
   _testLogger.addAppender(dapp);
 
   // - silent category for xpcshell stuff that already gets dump()ed
   _xpcshellLogger = Log4Moz.repository.getLogger("xpcshell");
 
   // - logsploder
-  let file = Cc["@mozilla.org/file/directory_service;1"]
-               .getService(Ci.nsIProperties)
-               .get("TmpD", Ci.nsIFile);
+  let file = Services.dirsvc.get("TmpD", Ci.nsIFile);
   file.append("logsploder.ptr");
   if (file.exists()) {
     _logHelperInterestedListeners = true;
 
     let data = IOUtils.loadFileToString(file);
     data = data.trim();
     let [host, port] = data.split(":");
     let jf = new Log4Moz.JSONFormatter();
--- a/mailnews/test/resources/mailDirService.js
+++ b/mailnews/test/resources/mailDirService.js
@@ -48,46 +48,45 @@ function initializeDirServer() {
 
             // Then this is the directory we want
             profileDir.append("mailtest");
 
             return profileDir;
           }
           if (prop == "resource:app") {
             // app should return the same as gre...
-            return dirSvc.get("GreD", Ci.nsIFile);
+            return Services.dirsvc.get("GreD", Ci.nsIFile);
           }
           if (prop == "TmpD") {
             throw Components.results.NS_ERROR_FAILURE;
           }
 
           dump("Directory request for: " + prop + " that we (mailDirService.js)" +
                " are not handling, leaving it to another handler.\n");
           throw Components.results.NS_ERROR_FAILURE;
         },
 
         QueryInterface:
           XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider])
       };
       gProfileDirProvider = provider;
-      dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(gProfileDirProvider);
+      Services.dirsvc.QueryInterface(Ci.nsIDirectoryService)
+                     .registerProvider(gProfileDirProvider);
     }
   };
 
   // If there's no location registered for the profile directory, register one
-  var dirSvc = Cc["@mozilla.org/file/directory_service;1"]
-                 .getService(Ci.nsIProperties);
   var profileDir;
   try {
-    profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
+    profileDir = Services.dirsvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
   } catch (e) { }
 
   if (!profileDir) {
     MailTestDirServer.makeDirectoryService();
-    profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
+    profileDir = Services.dirsvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
   }
   return profileDir;
 }
 
 // Left as a global to make things like copying files easy.
 var gProfileDir = initializeDirServer();
 
 // Ensure we start with a clean profile directory for all tests
--- a/mailnews/test/resources/messageGenerator.js
+++ b/mailnews/test/resources/messageGenerator.js
@@ -421,17 +421,17 @@ SyntheticMessage.prototype = {
    *  string suitable for use in a to/from/cc header line.
    *
    * @param aNameAndAddress A list with two elements.  The first should be the
    *     display name (sans wrapping quotes).  The second element should be the
    *     e-mail address (sans wrapping greater-than/less-than).
    */
   _formatMailFromNameAndAddress: function(aNameAndAddress) {
     // if the name is encoded, do not put it in quotes!
-    return (aNameAndAddress[0][0] == "=" ?
+    return (aNameAndAddress[0].startsWith("=") ?
               (aNameAndAddress[0] + " ") :
               ('"' + aNameAndAddress[0] + '" ')) +
            '<' + aNameAndAddress[1] + '>';
   },
 
   /**
    * Given a mailbox, parse out name and email. The mailbox
    * can (per rfc 2822) be of two forms:
@@ -871,17 +871,17 @@ MessageGenerator.prototype = {
       //  the set because the caller may be using them.
       let srcMsg = aArgs.inReplyTo.synMessages ?
                      aArgs.inReplyTo.synMessages[0] :
                      aArgs.inReplyTo;
 
       msg.parent = srcMsg;
       msg.parent.children.push(msg);
 
-      msg.subject = (srcMsg.subject.substring(0, 4) == "Re: ") ? srcMsg.subject
+      msg.subject = (srcMsg.subject.startsWith("Re: ")) ? srcMsg.subject
                     : ("Re: " + srcMsg.subject);
       if (aArgs.replyAll)
         msg.to = [srcMsg.from].concat(srcMsg.to.slice(1));
       else
         msg.to = [srcMsg.from];
       msg.from = srcMsg.to[0];
 
       // we want the <>'s.