private void setOSLocale(Locale locale) {
   Locale.setDefault(locale);
   BrowserLocaleManager.storeAndNotifyOSLocale(GoannaSharedPrefs.forProfile(mActivity), locale);
 }
Beispiel #2
0
  public void testOSLocale() throws Exception {
    blockForDelayedStartup();

    final SharedPreferences prefs = GoannaSharedPrefs.forProfile(getActivity());
    final PrefState state = new PrefState();

    state.fetch();

    // We don't know at this point whether we were run against a dirty profile or not.
    //
    // If we cleared the pref above prior to BrowserApp's delayed init, or our Goanna
    // profile has been used before, then we're already going to be set up for en-US.
    //
    // If we cleared the pref after the initial broadcast, and our Android-side profile
    // has been used before but the Goanna profile is clean, then the Goanna prefs won't
    // have been set.
    //
    // Instead, we always send a new locale code, and see what we get.
    final Locale fr = Locales.parseLocaleCode("fr");
    BrowserLocaleManager.storeAndNotifyOSLocale(prefs, fr);

    state.fetch();

    mAsserter.is(state.osLocale, "fr", "We're in fr.");

    // Now we can see what the expected Accept-Languages header should be.
    // The OS locale is 'fr', so we have our app locale (en-US),
    // the OS locale (fr), then any remaining fallbacks from intl.properties.
    mAsserter.is(
        state.acceptLanguages, "en-us,fr,en", "We have the default en-US+fr Accept-Languages.");

    // Now set the app locale to be es-ES.
    BrowserLocaleManager.getInstance().setSelectedLocale(getActivity(), "es-ES");

    state.fetch();

    mAsserter.is(state.osLocale, "fr", "We're still in fr.");

    // The correct set here depends on whether the
    // browser was built with multiple locales or not.
    // This is exasperating, but hey.
    final boolean isMultiLocaleBuild = false;

    // This never changes.
    final String SELECTED_LOCALES = "es-es,fr,";

    // Expected, from es-ES's intl.properties:
    final String EXPECTED =
        SELECTED_LOCALES
            + (isMultiLocaleBuild
                ? "es,en-us,en"
                : // Expected, from es-ES's intl.properties.
                "en-us,en"); // Expected, from en-US (the default).

    mAsserter.is(
        state.acceptLanguages,
        EXPECTED,
        "We have the right es-ES+fr Accept-Languages for this build.");

    // And back to en-US.
    final Locale en_US = Locales.parseLocaleCode("en-US");
    BrowserLocaleManager.storeAndNotifyOSLocale(prefs, en_US);
    BrowserLocaleManager.getInstance().resetToSystemLocale(getActivity());

    state.fetch();

    mAsserter.is(state.osLocale, "en-US", "We're in en-US.");
    mAsserter.is(
        state.acceptLanguages, "en-us,en", "We have the default processed en-US Accept-Languages.");
  }