Bug 1519742 - fix tests test_autoconfig*.js to run under Thunderbird. r=BenB
authoraceman <acelists@atlas.sk>
Tue, 15 Jan 2019 12:31:00 +0100
changeset 34210 4c0e476ae8188300310bff6fe6f2614cc3a17a23
parent 34209 279f3823f22354595e65d3327b39627ac838320d
child 34211 b6ff801164a840a79e8992ad733c0e9d8e500085
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersBenB
bugs1519742
Bug 1519742 - fix tests test_autoconfig*.js to run under Thunderbird. r=BenB
mail/components/accountcreation/content/guessConfig.js
mail/components/test/unit/data/example.com.xml
mail/components/test/unit/test_autoconfigFetchDisk.js
mail/components/test/unit/test_autoconfigUtils.js
mail/components/test/unit/test_autoconfigXML.js
mail/components/test/unit/xpcshell.ini
mailnews/base/test/unit/data/example.com.xml
mailnews/base/test/unit/test_autoconfigFetchDisk.js
mailnews/base/test/unit/test_autoconfigUtils.js
mailnews/base/test/unit/test_autoconfigXML.js
mailnews/base/test/unit/xpcshell.ini
--- a/mail/components/accountcreation/content/guessConfig.js
+++ b/mail/components/accountcreation/content/guessConfig.js
@@ -865,17 +865,17 @@ SSLErrorHandler.prototype =
     let flags = 0;
 
     let parts = targetSite.split(":");
     let host = parts[0];
     let port = parts[1];
 
     /* The following 2 cert problems are unfortunately common:
      * 1) hostname mismatch:
-     * user is custeromer at a domain hoster, he owns yourname.org,
+     * user is customer at a domain hoster, he owns yourname.org,
      * and the IMAP server is imap.hoster.com (but also reachable as
      * imap.yourname.org), and has a cert for imap.hoster.com.
      * 2) self-signed:
      * a company has an internal IMAP server, and it's only for
      * 30 employees, and they didn't want to buy a cert, so
      * they use a self-signed cert.
      *
      * We would like the above to pass, somehow, with user confirmation.
rename from mailnews/base/test/unit/data/example.com.xml
rename to mail/components/test/unit/data/example.com.xml
rename from mailnews/base/test/unit/test_autoconfigFetchDisk.js
rename to mail/components/test/unit/test_autoconfigFetchDisk.js
--- a/mailnews/base/test/unit/test_autoconfigFetchDisk.js
+++ b/mail/components/test/unit/test_autoconfigFetchDisk.js
@@ -19,33 +19,27 @@ var copyLocation;
 
 var xmlReader =
 {
   setTimeout : function(func, interval) {
     do_timeout(interval, func);
   }
 };
 
-try {
-  Services.scriptloader.loadSubScript(
+Services.scriptloader.loadSubScript(
     "chrome://messenger/content/accountcreation/util.js", xmlReader);
-  Services.scriptloader.loadSubScript(
+Services.scriptloader.loadSubScript(
     "chrome://messenger/content/accountcreation/fetchConfig.js", xmlReader);
-  Services.scriptloader.loadSubScript(
+Services.scriptloader.loadSubScript(
     "chrome://messenger/content/accountcreation/accountConfig.js", xmlReader);
-  Services.scriptloader.loadSubScript(
+Services.scriptloader.loadSubScript(
     "chrome://messenger/content/accountcreation/sanitizeDatatypes.js",
     xmlReader);
-  Services.scriptloader.loadSubScript(
+Services.scriptloader.loadSubScript(
     "chrome://messenger/content/accountcreation/readFromXML.js", xmlReader);
-} catch (ex) {
-  dump(ex);
-  // The "accountcreation" files are not available in SeaMonkey (yet).
-  xmlReader = null;
-}
 
 function onTestSuccess(config)
 {
   // Check that we got the expected config.
   xmlReader.replaceVariables(config,
                              "Yamato Nadeshiko",
                              "yamato.nadeshiko@example.com",
                              "abc12345");
@@ -61,22 +55,16 @@ function onTestSuccess(config)
 
 function onTestFailure(e)
 {
   do_throw(e);
 }
 
 function run_test()
 {
-  if (!xmlReader) {
-    // if you see this and this is Thunderbird, then it's an error
-    dump("INFO | test_autoconfigFetchDisk.js not running, because this is SeaMonkey.");
-    return;
-  }
-
   registerCleanupFunction(finish_test);
 
   // Copy the xml file into place
   let file = do_get_file("data/" + kXMLFile);
 
   copyLocation = Services.dirsvc.get("CurProcD", Ci.nsIFile);
   copyLocation.append("isp");
 
rename from mailnews/base/test/unit/test_autoconfigUtils.js
rename to mail/components/test/unit/test_autoconfigUtils.js
--- a/mailnews/base/test/unit/test_autoconfigUtils.js
+++ b/mail/components/test/unit/test_autoconfigUtils.js
@@ -15,27 +15,21 @@
  * - Test the returned CMDS.
  * - Figure out what else to test.
  */
 
 // Globals
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-var loaded = false;
-try {
-  Services.scriptloader.loadSubScript("chrome://messenger/content/accountcreation/util.js");
-  Services.scriptloader.loadSubScript("chrome://messenger/content/accountcreation/accountConfig.js");
-  Services.scriptloader.loadSubScript("chrome://messenger/content/accountcreation/sanitizeDatatypes.js");
-  Services.scriptloader.loadSubScript("chrome://messenger/content/accountcreation/guessConfig.js");
-  loaded = true;
-} catch (ex) {
-  // The "accountcreation" files are not available in SeaMonkey (yet).
-  dump("loading accountcreation JS files failed: " + ex + "\n" + ex.stack + "\n");
-}
+Services.scriptloader.loadSubScript("chrome://messenger/content/accountcreation/util.js");
+Services.scriptloader.loadSubScript("chrome://messenger/content/accountcreation/accountConfig.js");
+Services.scriptloader.loadSubScript("chrome://messenger/content/accountcreation/sanitizeDatatypes.js");
+Services.scriptloader.loadSubScript("chrome://messenger/content/accountcreation/fetchhttp.js");
+Services.scriptloader.loadSubScript("chrome://messenger/content/accountcreation/guessConfig.js");
 
 /*
  * UTILITIES
  */
 
 function assert(aBeTrue, aWhy)
 {
   if (!aBeTrue)
@@ -73,29 +67,33 @@ function assert_equal_try_orders(aA, aB)
 };
 
 /**
  * Check that the POP calculations are correct for a given host and
  * protocol.
  */
 function checkPop(host, protocol)
 {
+  // The list of protocol+ssl+port configurations should match
+  // getIncomingTryOrder() in guessConfig.js.
+  // SSL configs are separated until bug 1520283 is fixed.
+
   // port == UNKNOWN
     // [POP, TLS, 110], [POP, SSL, 995], [POP, NONE, 110]
   // port != UNKNOWN
     // ssl == UNKNOWN
       // [POP, TLS, port], [POP, SSL, port], [POP, NONE, port]
     // ssl != UNKNOWN
       // [POP, ssl, port]
   let ssl = UNKNOWN;
   let port = UNKNOWN;
   let tryOrder = getIncomingTryOrder(host, protocol, ssl, port);
   assert_equal_try_orders(tryOrder,
                           [[POP, TLS, 110],
-                           [POP, SSL, 995],
+                        // [POP, SSL, 995],
                            [POP, NONE, 110]]);
 
   ssl = TLS;
   tryOrder = getIncomingTryOrder(host, protocol, ssl, port);
   assert_equal_try_orders(tryOrder,
                           [[POP, ssl, 110]]);
 
   ssl = SSL;
@@ -108,46 +106,50 @@ function checkPop(host, protocol)
   assert_equal_try_orders(tryOrder,
                           [[POP, ssl, 110]]);
 
   ssl = UNKNOWN;
   port = 31337;
   tryOrder = getIncomingTryOrder(host, protocol, ssl, port);
   assert_equal_try_orders(tryOrder,
                           [[POP, TLS, port],
-                           [POP, SSL, port],
+                        // [POP, SSL, port],
                            [POP, NONE, port]]);
 
   for (ssl in [TLS, SSL, NONE]) {
     tryOrder = getIncomingTryOrder(host, protocol, ssl, port);
     assert_equal_try_orders(tryOrder,
                             [[POP, ssl, port]]);
   }
 };
 
 /**
  * Check that the IMAP calculations are correct for a given host and
  * protocol.
  */
 function checkImap(host, protocol)
 {
+  // The list of protocol+ssl+port configurations should match
+  // getIncomingTryOrder() in guessConfig.js.
+  // SSL configs are separated until bug 1520283 is fixed.
+
   // port == UNKNOWN
     // [IMAP, TLS, 143], [IMAP, SSL, 993], [IMAP, NONE, 143]
   // port != UNKNOWN
     // ssl == UNKNONWN
       // [IMAP, TLS, port], [IMAP, SSL, port], [IMAP, NONE, port]
     // ssl != UNKNOWN
      // [IMAP, ssl, port];
 
   let ssl = UNKNOWN;
   let port = UNKNOWN;
   let tryOrder = getIncomingTryOrder(host, protocol, ssl, port);
   assert_equal_try_orders(tryOrder,
                           [[IMAP, TLS, 143],
-                           [IMAP, SSL, 993],
+                        // [IMAP, SSL, 993],
                            [IMAP, NONE, 143]]);
 
   ssl = TLS;
   tryOrder = getIncomingTryOrder(host, protocol, ssl, port);
   assert_equal_try_orders(tryOrder,
                           [[IMAP, ssl, 143]]);
 
   ssl = SSL;
@@ -160,17 +162,17 @@ function checkImap(host, protocol)
   assert_equal_try_orders(tryOrder,
                           [[IMAP, ssl, 143]]);
 
   ssl = UNKNOWN;
   port = 31337;
   tryOrder = getIncomingTryOrder(host, protocol, ssl, port);
   assert_equal_try_orders(tryOrder,
                           [[IMAP, TLS, port],
-                           [IMAP, SSL, port],
+                        // [IMAP, SSL, port],
                            [IMAP, NONE, port]]);
 
   for (ssl in [TLS, SSL, NONE]) {
     tryOrder = getIncomingTryOrder(host, protocol, ssl, port);
     assert_equal_try_orders(tryOrder,
                             [[IMAP, ssl, port]]);
   }
 };
@@ -212,16 +214,20 @@ function test_getHostEntry()
                             [SMTP, NONE, 587]);
 };
 
 /**
  * Test the getIncomingTryOrder method.
  */
 function test_getIncomingTryOrder()
 {
+  // The list of protocol+ssl+port configurations should match
+  // getIncomingTryOrder() in guessConfig.js.
+  // SSL configs are separated until bug 1520283 is fixed.
+
   // protocol == POP || host starts with pop. || host starts with pop3.
   checkPop( "example.com", POP );
   checkPop( "pop.example.com", UNKNOWN );
   checkPop( "pop3.example.com", UNKNOWN );
   checkPop( "imap.example.com", POP );
 
   // protocol == IMAP || host starts with imap.
   checkImap( "example.com", IMAP );
@@ -230,63 +236,84 @@ function test_getIncomingTryOrder()
 
   let domain = "example.com";
   let protocol = UNKNOWN;
   let ssl = UNKNOWN;
   let port = UNKNOWN;
   let tryOrder = getIncomingTryOrder(domain, protocol, ssl, port);
   assert_equal_try_orders(tryOrder,
                           [[IMAP, TLS, 143],
-                           [IMAP, SSL, 993],
+                        // [IMAP, SSL, 993],
                            [POP, TLS, 110],
-                           [POP, SSL, 995],
+                        // [POP, SSL, 995],
                            [IMAP, NONE, 143],
                            [POP, NONE, 110]]);
 
+  ssl = SSL;
+  tryOrder = getIncomingTryOrder(domain, protocol, ssl, port);
+  assert_equal_try_orders(tryOrder,
+                          [[IMAP, SSL, 993],
+                           [POP, SSL, 995]]);
+
+  ssl = UNKNOWN;
   port = 31337;
   tryOrder = getIncomingTryOrder(domain, protocol, ssl, port);
   assert_equal_try_orders(tryOrder,
                           [[IMAP, TLS, port],
-                           [IMAP, SSL, port],
+                        // [IMAP, SSL, port],
                            [POP, TLS, port],
-                           [POP, SSL, port],
+                        // [POP, SSL, port],
                            [IMAP, NONE, port],
                            [POP, NONE, port]]);
+
+  ssl = SSL;
+  tryOrder = getIncomingTryOrder(domain, protocol, ssl, port);
+  assert_equal_try_orders(tryOrder,
+                          [[IMAP, SSL, port],
+                           [POP, SSL, port]]);
 };
 
 /**
  * Test the getOutgoingTryOrder method.
  */
 function test_getOutgoingTryOrder()
 {
+  // The list of protocol+ssl+port configurations should match
+  // getOutgoingTryOrder() in guessConfig.js.
+  // SSL configs are separated until bug 1520283 is fixed.
   let domain = "example.com";
   let protocol = SMTP;
   let ssl = UNKNOWN;
   let port = UNKNOWN;
   let tryOrder = getOutgoingTryOrder(domain, protocol, ssl, port);
   assert_equal_try_orders(tryOrder,
                           [[SMTP, TLS, 587],
                            [SMTP, TLS, 25],
-                           [SMTP, SSL, 465],
+                        // [SMTP, SSL, 465],
                            [SMTP, NONE, 587],
                            [SMTP, NONE, 25]]);
+
+  ssl = SSL;
+  tryOrder = getOutgoingTryOrder(domain, protocol, ssl, port);
+  assert_equal_try_orders(tryOrder,
+                          [[SMTP, SSL, 465]]);
+
+  ssl = UNKNOWN;
   port = 31337
   tryOrder = getOutgoingTryOrder(domain, protocol, ssl, port);
   assert_equal_try_orders(tryOrder,
                           [[SMTP, TLS, port],
-                           [SMTP, SSL, port],
+                        // [SMTP, SSL, port],
                            [SMTP, NONE, port]]);
+
+  ssl = SSL;
+  tryOrder = getOutgoingTryOrder(domain, protocol, ssl, port);
+  assert_equal_try_orders(tryOrder,
+                          [[SMTP, SSL, port]]);
 };
 
 
 function run_test()
 {
-  if (!loaded)
-  {
-    // if you see this with Thunderbird, then it's an error
-    dump("INFO | test_autoconfigUtils.js not running, because this is SeaMonkey.\n");
-    return true;
-  }
-
   test_getHostEntry();
   test_getIncomingTryOrder();
   test_getOutgoingTryOrder();
 };
rename from mailnews/base/test/unit/test_autoconfigXML.js
rename to mail/components/test/unit/test_autoconfigXML.js
--- a/mailnews/base/test/unit/test_autoconfigXML.js
+++ b/mail/components/test/unit/test_autoconfigXML.js
@@ -17,31 +17,26 @@
 // Globals
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource:///modules/JXON.js");
 
 Cu.importGlobalProperties(["DOMParser"]);
 
 var xmlReader = {};
-try {
-  Services.scriptloader.loadSubScript(
+Services.scriptloader.loadSubScript(
       "chrome://messenger/content/accountcreation/util.js", xmlReader);
-  Services.scriptloader.loadSubScript(
+Services.scriptloader.loadSubScript(
       "chrome://messenger/content/accountcreation/accountConfig.js",
       xmlReader);
-  Services.scriptloader.loadSubScript(
+Services.scriptloader.loadSubScript(
       "chrome://messenger/content/accountcreation/sanitizeDatatypes.js",
       xmlReader);
-  Services.scriptloader.loadSubScript(
+Services.scriptloader.loadSubScript(
       "chrome://messenger/content/accountcreation/readFromXML.js", xmlReader);
-} catch (ex) {
-  // The "accountcreation" files are not available in SeaMonkey (yet).
-  xmlReader = null;
-}
 
 /*
  * UTILITIES
  */
 
 function assert_equal(aA, aB, aWhy)
 {
   if (aA != aB)
@@ -260,18 +255,11 @@ function test_replaceVariables()
                       "user real name");
   assert_equal_config(config.identity.emailAddress,
                       "yamato.nadeshiko@example.com",
                       "user email address");
 }
 
 function run_test()
 {
-  if (!xmlReader)
-  {
-    // if you see this and this is Thunderbird, then it's an error
-    dump("test_autoconfigXML.js not running, because this is SeaMonkey.");
-    return;
-  }
-
   test_readFromXML_config1();
   test_replaceVariables();
 };
--- a/mail/components/test/unit/xpcshell.ini
+++ b/mail/components/test/unit/xpcshell.ini
@@ -1,5 +1,9 @@
 [DEFAULT]
 head = head_mailcomponents.js
 tail =
+support-files = data/*
 
 [test_about_support.js]
+[test_autoconfigFetchDisk.js]
+[test_autoconfigUtils.js]
+[test_autoconfigXML.js]
--- a/mailnews/base/test/unit/xpcshell.ini
+++ b/mailnews/base/test/unit/xpcshell.ini
@@ -2,19 +2,16 @@
 head = head_mailbase.js
 tail =
 support-files = nodelist_test.xml data/*
 
 [test_accountMgr.js]
 [test_accountMgrCustomTypes.js]
 [test_accountMigration.js]
 [test_acctRepair.js]
-[test_autoconfigFetchDisk.js]
-[test_autoconfigUtils.js]
-[test_autoconfigXML.js]
 [test_bccInDatabase.js]
 [test_bug366491.js]
 [test_bug404489.js]
 [test_bug428427.js]
 [test_bug434810.js]
 [test_bug471682.js]
 [test_bug514945.js]
 [test_base64_decoding.js]