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: news. r=jcranmer
authorSebastian Hengst <archaeopteryx@coole-files.de>
Tue, 15 Jan 2013 21:28:25 +0100
changeset 14727 7feccbd27039a940f88203607a3495bbb50ff767
parent 14726 11dc139c9e5325351412136ab25e21f7428879e1
child 14728 2968b7dbde32067455f8bf9ddedb1c7b6c21d629
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)
reviewersjcranmer
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: news. r=jcranmer
mail/base/content/commandglue.js
mail/test/mozmill/shared-modules/test-nntp-helpers.js
mailnews/news/test/unit/test_nntpGroupPassword.js
mailnews/news/test/unit/test_nntpPassword3.js
mailnews/news/test/unit/test_nntpPasswordFailure.js
--- a/mail/base/content/commandglue.js
+++ b/mail/base/content/commandglue.js
@@ -21,21 +21,21 @@ function UpdateMailToolbar(caller)
   document.commandDispatcher.updateCommands('mail-toolbar');
 
   // hook for extra toolbar items
   Services.obs.notifyObservers(window, "mail:updateToolbarItems", null);
 }
 
 function isNewsURI(uri)
 {
-    if (!uri || uri[0] != 'n') {
+    if (!uri || !uri.startsWith('n')) {
         return false;
     }
     else {
-        return ((uri.substring(0,6) == "news:/") || (uri.substring(0,14) == "news-message:/"));
+        return ((uri.startsWith("news:/")) || (uri.startsWith("news-message:/")));
     }
 }
 
 function SwitchView(command)
 {
   // when switching thread views, we might be coming out of quick search
   // or a message view.
   // first set view picker to all
--- a/mail/test/mozmill/shared-modules/test-nntp-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-nntp-helpers.js
@@ -1,16 +1,18 @@
 /* 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/. */
 
 var Ci = Components.interfaces;
 var Cc = Components.classes;
 var Cu = Components.utils;
 
+Cu.import("resource://gre/modules/Services.jsm");
+
 var elib = {};
 Cu.import('resource://mozmill/modules/elementslib.js', elib);
 var mozmill = {};
 Cu.import('resource://mozmill/modules/mozmill.js', mozmill);
 
 const MODULE_NAME = 'test-nntp-helpers';
 
 const RELATIVE_ROOT = '../shared-modules';
@@ -79,19 +81,17 @@ function setupNNTPDaemon() {
 
   var article = new testHelperModule.newsArticle(kSimpleNewsArticle);
   daemon.addArticleToGroup(article, "test.subscribe.simple", 1);
 
   return daemon;
 }
 
 // Enable strict threading
-var prefs = Cc["@mozilla.org/preferences-service;1"]
-              .getService(Ci.nsIPrefBranch);
-prefs.setBoolPref("mail.strict_threading", true);
+Services.prefs.setBoolPref("mail.strict_threading", true);
 
 
 // Make sure we don't try to use a protected port. I like adding 1024 to the
 // default port when doing so...
 const NNTP_PORT = 1024+119;
 
 var _server = null;
 
--- a/mailnews/news/test/unit/test_nntpGroupPassword.js
+++ b/mailnews/news/test/unit/test_nntpGroupPassword.js
@@ -20,27 +20,26 @@ function run_test() {
 
   var server = makeServer(NNTP_RFC4643_extension, daemon);
   server.start(NNTP_PORT);
   var localserver = setupLocalServer(NNTP_PORT);
   localserver.singleSignon = false;
 
   // Add passwords to the manager
   var serverURI = "news://localhost/";
-  var loginMgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
   var loginInfo1 = Cc["@mozilla.org/login-manager/loginInfo;1"]
                      .createInstance(Ci.nsILoginInfo);
   loginInfo1.init(serverURI + "test.subscribe.empty", null,
     serverURI + "test.subscribe.empty", "group1", "pass1", "", "");
-  loginMgr.addLogin(loginInfo1);
+  Services.logins.addLogin(loginInfo1);
   var loginInfo2 = Cc["@mozilla.org/login-manager/loginInfo;1"]
                      .createInstance(Ci.nsILoginInfo);
   loginInfo2.init(serverURI + "test.filter", null,
     serverURI + "test.filter", "group2", "pass2", "", "");
-  loginMgr.addLogin(loginInfo2);
+  Services.logins.addLogin(loginInfo2);
   try {
     var prefix = "news://localhost:"+NNTP_PORT+"/";
     var transaction;
 
     test = "per-group password part 1";
     setupProtocolTest(NNTP_PORT, prefix+"test.subscribe.empty", localserver);
     server.performTest();
     transaction = server.playTransaction();
--- a/mailnews/news/test/unit/test_nntpPassword3.js
+++ b/mailnews/news/test/unit/test_nntpPassword3.js
@@ -1,26 +1,25 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /**
  * Extra tests for forgetting newsgroup usernames and passwords.
  */
 
 load("../../../resources/mailTestUtils.js");
 
+Components.utils.import("resource://gre/modules/Services.jsm");
+
 const kUsername = "testnews";
 const kPassword = "newstest";
 const kProtocol = "nntp";
 const kHostname = "localhost";
 const kServerUrl = "news://" + kHostname;
 
 function run_test()
 {
-  // Login Manager
-  var loginMgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
-
   // Passwords File (generated from Mozilla 1.8 branch).
   var signons = do_get_file("../../../data/signons-mailnews1.8.txt");
 
   // Copy the file to the profile directory for a PAB
   signons.copyTo(gProfileDir, "signons.txt");
 
   // Set up the basic accounts and folders.
   loadLocalMailAccount();
@@ -34,22 +33,22 @@ function run_test()
   // Force move to new credentials
   incomingServer.rootFolder.QueryInterface(Ci.nsIMsgNewsFolder)
                            .migrateLegacyCredentials();
 
   var i;
   var count = {};
 
   // Test - Check there is a password to begin with...
-  var logins = loginMgr.findLogins(count, kServerUrl, null, kServerUrl);
+  var logins = Services.logins.findLogins(count, kServerUrl, null, kServerUrl);
 
   do_check_eq(count.value, 1);
   do_check_eq(logins[0].username, kUsername);
   do_check_eq(logins[0].password, kPassword);
 
   // Test - Remove the news password login via the incoming server
   incomingServer.forgetPassword();
 
-  logins = loginMgr.findLogins(count, kServerUrl, null, kServerUrl);
+  logins = Services.logins.findLogins(count, kServerUrl, null, kServerUrl);
 
   // should be no passwords left...
   do_check_eq(count.value, 0);
 }
--- a/mailnews/news/test/unit/test_nntpPasswordFailure.js
+++ b/mailnews/news/test/unit/test_nntpPasswordFailure.js
@@ -17,17 +17,16 @@ load("../../../resources/asyncTestUtils.
 load("../../../resources/alertTestUtils.js");
 
 var test = null;
 var server;
 var daemon;
 var incomingServer;
 var folder;
 var attempt = 0;
-var loginMgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
 var count = {};
 var logins;
 
 const kUserName = "testnews";
 const kInvalidPassword = "newstest";
 const kValidPassword = "notallama";
 
 function alert(aDialogText, aText)
@@ -123,18 +122,18 @@ function getMail1() {
   getMail();
   yield false;
   dump("\nGot Mail 1\n");
 
   do_check_eq(attempt, 2);
 
   // Check that we haven't forgotten the login even though we've retried and
   // canceled.
-  logins = loginMgr.findLogins(count, "news://localhost", null,
-                                   "news://localhost");
+  logins = Services.logins.findLogins(count, "news://localhost", null,
+                                      "news://localhost");
 
   do_check_eq(count.value, 1);
   do_check_eq(logins[0].username, kUserName);
   do_check_eq(logins[0].password, kInvalidPassword);
 
   server.resetTest();
   yield true;
 }
@@ -145,18 +144,18 @@ function getMail2() {
   // Now get the mail
   getMail();
   yield false;
   dump("\nGot Mail 2\n");
 }
 
 function endTest() {
   // Now check the new one has been saved.
-  logins = loginMgr.findLogins(count, "news://localhost", null,
-                               "news://localhost");
+  logins = Services.logins.findLogins(count, "news://localhost", null,
+                                      "news://localhost");
 
   do_check_eq(count.value, 1);
   do_check_eq(logins[0].username, kUserName);
   do_check_eq(logins[0].password, kValidPassword);
   yield true;
 }
 
 function run_test()