Bug 763988 - Make Account Provisioner compare providers against general.useragent.locale instead of any values of intl.accept_languages. r=bwinton, a=Standard8. SEAMONKEY_2_11b2_BUILD1 SEAMONKEY_2_11b2_RELEASE
authorMike Conley <mconley@mozilla.com>
Tue, 12 Jun 2012 14:57:07 -0400
changeset 11881 2d4b4998b70b0fa494f27e6418a44d069018e0dd
parent 11880 0b48feb6927a07885621b1b54df8be1e0dac236a
child 11882 e4299549ad30c0d0bd2b82b8af947933442533c1
child 11883 dcab8bea652122b1957ccafd2da476068035a95d
child 11885 b698b796fdb658b4e0cde3a2837761940c2d4d5b
push idunknown
push userunknown
push dateunknown
reviewersbwinton, Standard8
bugs763988
Bug 763988 - Make Account Provisioner compare providers against general.useragent.locale instead of any values of intl.accept_languages. r=bwinton, a=Standard8.
mail/components/newmailaccount/content/accountProvisioner.js
mail/test/mozmill/newmailaccount/html/providerListWildcard
mail/test/mozmill/newmailaccount/test-newmailaccount.js
--- a/mail/components/newmailaccount/content/accountProvisioner.js
+++ b/mail/components/newmailaccount/content/accountProvisioner.js
@@ -136,26 +136,20 @@ var EmailAccountProvisioner = {
    * Returns the URL for retrieving suggested names from the
    * selected providers.
    */
   get suggestFromName() {
     return Services.prefs.getCharPref("mail.provider.suggestFromName");
   },
 
   /**
-   * Returns the languages that the user currently accepts.
+   * Returns the language that the user currently accepts.
    */
-  get userLanguages() {
-    let userLanguages =
-      Services.prefs.getComplexValue("intl.accept_languages",
-                                     Ci.nsIPrefLocalizedString)
-                                       .data
-                                       .toLowerCase()
-                                       .split(",");
-    return $.map(userLanguages, $.trim);
+  get userLanguage() {
+    return Services.prefs.getCharPref("general.useragent.locale");
   },
 
   /**
    * A helper function to enable or disable the Search button.
    */
   searchButtonEnabled: function EAP_searchButtonEnabled(aVal) {
     if (aVal) {
       $("#searchSubmit").removeAttr("disabled");
@@ -570,25 +564,23 @@ var EmailAccountProvisioner = {
       if (!(EmailAccountProvisioner.providerHasCorrectFields(provider))) {
         gLog.error("A provider had incorrect fields, and has been skipped");
         return;
       }
 
       EmailAccountProvisioner.providers[provider.id] = provider;
 
       // Let's go through the array of languages for this provider, and
-      // check to see if at least one of them matches one of the accepted
-      // languages for this user profile.  If so, supportsSomeUserLang becomes
-      // true, and we'll show / select this provider by default.
+      // check to see if at least one of them matches general.useragent.locale.
+      // If so, we'll show / select this provider by default.
       let supportsSomeUserLang = provider
                                  .languages
                                  .some(function (x) {
-                                   return EmailAccountProvisioner
-                                          .userLanguages
-                                          .indexOf(x.toLowerCase()) >= 0
+                                   return x == "*" ||
+                                          x == EmailAccountProvisioner.userLanguage
                                  });
 
       let checkboxId = provider.id + "-check";
 
       let providerCheckbox = $('<input type="checkbox" />')
                              .val(provider.id)
                              .addClass("providerCheckbox")
                              .attr("id", checkboxId);
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/newmailaccount/html/providerListWildcard
@@ -0,0 +1,37 @@
+[{"id": "universal",
+  "label": "Universal",
+  "paid": true,
+  "languages" : ["*"],
+  "api": "http://www.example.com/tbReg?first={firstname}&last={lastname}&email={email}",
+  "tos_url": "http://www.example.com/foo-tos",
+  "privacy_url": "http://www.example.com/foo-privacy",
+  "search_engine": "universal"
+ },
+{"id": "otherUniversal",
+  "label": "Other Universal",
+  "paid": true,
+  "languages" : ["*", "fr-FR"],
+  "api": "http://www.example.com/tbReg?first={firstname}&last={lastname}&email={email}",
+  "tos_url": "http://www.example.com/foo-tos",
+  "privacy_url": "http://www.example.com/foo-privacy",
+  "search_engine": "otherUniversal"
+ },
+ {"id": "French",
+  "label": "French Provider",
+  "paid": false,
+  "languages" : ["fr-FR"],
+  "api": "http://localhost:43336/registration.html",
+  "tos_url": "http://www.example.com/French-tos",
+  "privacy_url": "http://www.example.com/French-privacy",
+  "search_engine": "French"
+ },
+ {"id": "German",
+  "label": "German Provider",
+  "paid": false,
+  "languages" : ["de-DE"],
+  "api": "http://localhost:43336/registration.html",
+  "tos_url": "http://www.example.com/German-tos",
+  "privacy_url": "http://www.example.com/German-privacy",
+  "search_engine": "German"
+ }
+]
--- a/mail/test/mozmill/newmailaccount/test-newmailaccount.js
+++ b/mail/test/mozmill/newmailaccount/test-newmailaccount.js
@@ -67,17 +67,17 @@ Cu.import('resource://mozmill/stdlib/htt
 
 // RELATIVE_ROOT messes with the collector, so we have to bring the path back
 // so we get the right path for the resources.
 var url = collector.addHttpResource('../newmailaccount/html', '');
 const kProvisionerUrl = "chrome://messenger/content/newmailaccount/accountProvisioner.xhtml";
 const kProvisionerEnabledPref = "mail.provider.enabled";
 const kSuggestFromNamePref = "mail.provider.suggestFromName";
 const kProviderListPref = "mail.provider.providerList";
-const kAcceptLangs = "intl.accept_languages";
+const kAcceptedLanguage = "general.useragent.locale";
 const kDefaultServerPort = 4444;
 const kDefaultServerRoot = "http://localhost:" + kDefaultServerPort;
 
 Services.prefs.setCharPref(kProviderListPref, url + "providerList");
 Services.prefs.setCharPref(kSuggestFromNamePref, url + "suggestFromName");
 
 // Here's a name that we'll type in later on.  It's a global const because
 // we'll be using it in several distinct modal dialog event loops.
@@ -85,17 +85,17 @@ const NAME = "Leonard Shelby";
 
 // Record what the original value of the mail.provider.enabled pref is so
 // that we can put it back once the tests are done.
 var gProvisionerEnabled = Services.prefs.getBoolPref(kProvisionerEnabledPref);
 
 // Record what the original value of the mail.provider.enabled pref is so
 // that we can put it back once the tests are done.
 var gProvisionerEnabled = Services.prefs.getBoolPref(kProvisionerEnabledPref);
-var gOldAcceptLangs = Services.prefs.getComplexValue(kAcceptLangs, Ci.nsIPrefLocalizedString);
+var gOldAcceptLangs = Services.prefs.getCharPref(kAcceptedLanguage);
 var gNumAccounts;
 
 function setupModule(module) {
   let fdh = collector.getModule('folder-display-helpers');
   fdh.installInto(module);
   let cth = collector.getModule('content-tab-helpers');
   cth.installInto(module);
   let wh = collector.getModule('window-helpers');
@@ -103,31 +103,29 @@ function setupModule(module) {
   let nmah = collector.getModule('newmailaccount-helpers');
   nmah.installInto(module);
   let kh = collector.getModule('keyboard-helpers');
   kh.installInto(module);
   collector.getModule('dom-helpers').installInto(module);
 
   // Make sure we enable the Account Provisioner.
   Services.prefs.setBoolPref(kProvisionerEnabledPref, true);
-  // First, restrict the user's language to just en-US
-  let langs = Cc["@mozilla.org/pref-localizedstring;1"].createInstance(Ci.nsIPrefLocalizedString);
-  langs.data = "en-US";
-  Services.prefs.setComplexValue(kAcceptLangs, Ci.nsIPrefLocalizedString, langs);
+  // Restrict the user's language to just en-US
+  Services.prefs.setCharPref(kAcceptedLanguage, "en-US");
 
   // Add a "bar" search engine that we can switch to be the default.
   Services.search.addEngineWithDetails("bar", null, null, null, "post",
                                        "http://www.example.com/search");
 };
 
 function teardownModule(module) {
   // Put the mail.provider.enabled pref back the way it was.
   Services.prefs.setBoolPref(kProvisionerEnabledPref, gProvisionerEnabled);
   // And same with the user languages
-  Services.prefs.setComplexValue(kAcceptLangs, Ci.nsIPrefLocalizedString, gOldAcceptLangs);
+  Services.prefs.setCharPref(kAcceptedLanguage, gOldAcceptLangs);
 }
 
 /* Helper function that returns the number of accounts associated with the
  * current profile.
  */
 function nAccounts() {
   return [x for each (x in fixIterator(MailServices.accounts.accounts))].length;
 }
@@ -1159,40 +1157,77 @@ function subtest_disabled_fields_when_se
 
 /**
  * Tests that the search button is disabled if there is no initially
  * supported language for the user.
  */
 function test_search_button_disabled_if_no_lang_support() {
   // Set the user's supported language to something ridiculous (caching the
   // old one so we can put it back later).
-  let oldLangs = Services.prefs.getCharPref(kAcceptLangs);
-  Services.prefs.setCharPref(kAcceptLangs, "foo,bar,baz");
+  let oldLang = Services.prefs.getCharPref(kAcceptedLanguage);
+  Services.prefs.setCharPref(kAcceptedLanguage, "foo");
 
   plan_for_modal_dialog("AccountCreation",
                         subtest_search_button_disabled_on_init);
   open_provisioner_window();
   wait_for_modal_dialog("AccountCreation");
 
-  Services.prefs.setCharPref(kAcceptLangs, oldLangs);
+  Services.prefs.setCharPref(kAcceptedLanguage, oldLang);
 }
 
 /**
  * Subtest used by several functions that checks to make sure that the
  * search button is disabled when the Account Provisioner dialog  is opened.
  */
 function subtest_search_button_disabled_on_init(aController) {
   wait_for_provider_list_loaded(aController);
 
   // The search button should be disabled.
   wait_for_element_enabled(aController, aController.e("searchSubmit"), false);
   close_dialog_immediately(aController);
 }
 
 /**
+ * Test that if the providerList contains entries with supported languages
+ * including "*", they are always displayed, even if the users locale pref
+ * is not set to "*".
+ */
+function test_provider_language_wildcard() {
+  let oldLang = Services.prefs.getCharPref(kAcceptedLanguage);
+  Services.prefs.setCharPref(kAcceptedLanguage, "foo-bar");
+
+  let original = Services.prefs.getCharPref(kProviderListPref);
+  Services.prefs.setCharPref(kProviderListPref, url + "providerListWildcard");
+
+  plan_for_modal_dialog("AccountCreation",
+                        subtest_provider_language_wildcard);
+  open_provisioner_window();
+  wait_for_modal_dialog("AccountCreation");
+  Services.prefs.setCharPref(kProviderListPref, original);
+  Services.prefs.setCharPref(kAcceptedLanguage, oldLang);
+}
+
+/**
+ * Subtest used by test_provider_language_wildcard, ensures that the
+ * "Universal" and "OtherUniversal" providers are displayed, but the French
+ * and German ones are not.
+ */
+function subtest_provider_language_wildcard(aController) {
+  wait_for_provider_list_loaded(aController);
+  let doc = aController.window.document;
+  // Check that the two universal providers are visible.
+  wait_for_element_visible(aController, "universal-check");
+  wait_for_element_visible(aController, "otherUniversal-check");
+  // The French and German providers should not be visible.
+  wait_for_element_invisible(aController, "french-check");
+  wait_for_element_invisible(aController, "german-check");
+  close_dialog_immediately(aController);
+}
+
+/**
  * Tests that the search button is disabled if we start up the Account
  * Provisioner, and we have no search in the input.
  */
 function test_search_button_disabled_if_no_query_on_init() {
   // We have to do a little bit of gymnastics to access the local storage
   // for the accountProvisioner dialog...
   let url = "chrome://content/messenger/accountProvisionerStorage/accountProvisioner";
   let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]