Bug 1355382 - Use ChromeRegistry in Marionette Puppet when LocaleService is not available. r=whimboo draft
authorZibi Braniecki <gandalf@mozilla.com>
Tue, 11 Apr 2017 06:56:39 -0700
changeset 560494 ddf84f61d02a87212d901069f6a6dca9ddb627f5
parent 559749 b1364675bdf5dffe63fd60373034293de0b513d5
child 623718 c73a57dbd86a939c3fbc106775c87ebad4e78281
push id53437
push userzbraniecki@mozilla.com
push dateTue, 11 Apr 2017 14:12:48 +0000
reviewerswhimboo
bugs1355382
milestone55.0a1
Bug 1355382 - Use ChromeRegistry in Marionette Puppet when LocaleService is not available. r=whimboo MozReview-Commit-ID: Hh7mvyWVKzu
testing/marionette/puppeteer/firefox/firefox_puppeteer/api/appinfo.py
--- a/testing/marionette/puppeteer/firefox/firefox_puppeteer/api/appinfo.py
+++ b/testing/marionette/puppeteer/firefox/firefox_puppeteer/api/appinfo.py
@@ -25,19 +25,29 @@ class AppInfo(BaseLib):
             else:
                 raise AttributeError('{} has no attribute {}'.format(self.__class__.__name__,
                                                                      attr))
 
     @property
     def locale(self):
         with self.marionette.using_context('chrome'):
             return self.marionette.execute_script("""
-              return Components.classes["@mozilla.org/intl/localeservice;1"]
-                               .getService(Components.interfaces.mozILocaleService)
-                               .getAppLocaleAsLangTag();
+              // LocaleService has been added in 55, use ChromeRegistry for
+              // earlier releases.
+              // The ChromeRegistry path can be removed when 52esr is not longer
+              // supported.
+              try {
+                return Components.classes["@mozilla.org/intl/localeservice;1"]
+                                 .getService(Components.interfaces.mozILocaleService)
+                                 .getAppLocaleAsLangTag();
+              } catch (e) {
+                return Components.classes["@mozilla.org/chrome/chrome-registry;1"]
+                                 .getService(Components.interfaces.nsIXULChromeRegistry)
+                                 .getSelectedLocale("global");
+              }
             """)
 
     @property
     def user_agent(self):
         with self.marionette.using_context('chrome'):
             return self.marionette.execute_script("""
               return Components.classes["@mozilla.org/network/protocol;1?name=http"]
                                .getService(Components.interfaces.nsIHttpProtocolHandler)