DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (e9d6d0965bc6)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */

#include "gtest/gtest.h"
#include "mozilla/Preferences.h"
#include "mozilla/intl/LocaleService.h"
#include "mozilla/intl/MozLocale.h"

using namespace mozilla::intl;

TEST(Intl_Locale_LocaleService, GetAppLocalesAsBCP47)
{
  nsTArray<nsCString> appLocales;
  LocaleService::GetInstance()->GetAppLocalesAsBCP47(appLocales);

  ASSERT_FALSE(appLocales.IsEmpty());
}

TEST(Intl_Locale_LocaleService, GetAppLocalesAsLangTags)
{
  nsTArray<nsCString> appLocales;
  LocaleService::GetInstance()->GetAppLocalesAsLangTags(appLocales);

  ASSERT_FALSE(appLocales.IsEmpty());
}

TEST(Intl_Locale_LocaleService, GetAppLocalesAsLangTags_lastIsEnUS)
{
  nsAutoCString lastFallbackLocale;
  LocaleService::GetInstance()->GetLastFallbackLocale(lastFallbackLocale);

  nsTArray<nsCString> appLocales;
  LocaleService::GetInstance()->GetAppLocalesAsLangTags(appLocales);

  int32_t len = appLocales.Length();
  ASSERT_TRUE(appLocales[len - 1].Equals(lastFallbackLocale));
}

TEST(Intl_Locale_LocaleService, GetAppLocaleAsLangTag)
{
  nsTArray<nsCString> appLocales;
  LocaleService::GetInstance()->GetAppLocalesAsLangTags(appLocales);

  nsAutoCString locale;
  LocaleService::GetInstance()->GetAppLocaleAsLangTag(locale);

  ASSERT_TRUE(appLocales[0] == locale);
}

TEST(Intl_Locale_LocaleService, GetRegionalPrefsLocales)
{
  nsTArray<nsCString> rpLocales;
  LocaleService::GetInstance()->GetRegionalPrefsLocales(rpLocales);

  int32_t len = rpLocales.Length();
  ASSERT_TRUE(len > 0);
}

TEST(Intl_Locale_LocaleService, GetWebExposedLocales)
{
  const nsTArray<nsCString> spoofLocale{NS_LITERAL_CSTRING("de")};
  LocaleService::GetInstance()->SetAvailableLocales(spoofLocale);
  LocaleService::GetInstance()->SetRequestedLocales(spoofLocale);

  nsTArray<nsCString> pvLocales;

  mozilla::Preferences::SetInt("privacy.spoof_english", 0);
  LocaleService::GetInstance()->GetWebExposedLocales(pvLocales);
  ASSERT_TRUE(pvLocales.Length() > 0);
  ASSERT_TRUE(pvLocales[0].Equals(NS_LITERAL_CSTRING("de")));

  mozilla::Preferences::SetCString("intl.locale.privacy.web_exposed", "zh-TW");
  LocaleService::GetInstance()->GetWebExposedLocales(pvLocales);
  ASSERT_TRUE(pvLocales.Length() > 0);
  ASSERT_TRUE(pvLocales[0].Equals(NS_LITERAL_CSTRING("zh-TW")));

  mozilla::Preferences::SetInt("privacy.spoof_english", 2);
  LocaleService::GetInstance()->GetWebExposedLocales(pvLocales);
  ASSERT_EQ(1u, pvLocales.Length());
  ASSERT_TRUE(pvLocales[0].Equals(NS_LITERAL_CSTRING("en-US")));
}

TEST(Intl_Locale_LocaleService, GetRequestedLocales)
{
  nsTArray<nsCString> reqLocales;
  LocaleService::GetInstance()->GetRequestedLocales(reqLocales);

  int32_t len = reqLocales.Length();
  ASSERT_TRUE(len > 0);
}

TEST(Intl_Locale_LocaleService, GetAvailableLocales)
{
  nsTArray<nsCString> availableLocales;
  LocaleService::GetInstance()->GetAvailableLocales(availableLocales);

  int32_t len = availableLocales.Length();
  ASSERT_TRUE(len > 0);
}

TEST(Intl_Locale_LocaleService, GetPackagedLocales)
{
  nsTArray<nsCString> packagedLocales;
  LocaleService::GetInstance()->GetPackagedLocales(packagedLocales);

  int32_t len = packagedLocales.Length();
  ASSERT_TRUE(len > 0);
}

TEST(Intl_Locale_LocaleService, GetDefaultLocale)
{
  nsAutoCString locStr;
  LocaleService::GetInstance()->GetDefaultLocale(locStr);

  ASSERT_FALSE(locStr.IsEmpty());
  ASSERT_TRUE(Locale(locStr).IsWellFormed());
}

TEST(Intl_Locale_LocaleService, IsAppLocaleRTL)
{
  // For now we can only test if the method doesn't crash.
  LocaleService::GetInstance()->IsAppLocaleRTL();
  ASSERT_TRUE(true);
}