tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TestLocaleServiceNegotiate.cpp (1826B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #include "gtest/gtest.h"
      7 #include "mozilla/intl/LocaleService.h"
      8 
      9 using namespace mozilla::intl;
     10 
     11 TEST(Intl_Locale_LocaleService, Negotiate)
     12 {
     13  nsTArray<nsCString> requestedLocales;
     14  nsTArray<nsCString> availableLocales;
     15  nsTArray<nsCString> supportedLocales;
     16  nsAutoCString defaultLocale("en-US");
     17  int32_t strategy = LocaleService::kLangNegStrategyFiltering;
     18 
     19  requestedLocales.AppendElement("sr"_ns);
     20 
     21  availableLocales.AppendElement("sr-Cyrl"_ns);
     22  availableLocales.AppendElement("sr-Latn"_ns);
     23 
     24  LocaleService::GetInstance()->NegotiateLanguages(
     25      requestedLocales, availableLocales, defaultLocale, strategy,
     26      supportedLocales);
     27 
     28  ASSERT_TRUE(supportedLocales.Length() == 2);
     29  ASSERT_TRUE(supportedLocales[0].EqualsLiteral("sr-Cyrl"));
     30  ASSERT_TRUE(supportedLocales[1].EqualsLiteral("en-US"));
     31 }
     32 
     33 TEST(Intl_Locale_LocaleService, UseLSDefaultLocale)
     34 {
     35  nsTArray<nsCString> requestedLocales;
     36  nsTArray<nsCString> availableLocales;
     37  nsTArray<nsCString> supportedLocales;
     38  nsAutoCString defaultLocale("en-US");
     39  int32_t strategy = LocaleService::kLangNegStrategyLookup;
     40 
     41  requestedLocales.AppendElement("sr"_ns);
     42 
     43  availableLocales.AppendElement("de"_ns);
     44 
     45  LocaleService::GetInstance()->NegotiateLanguages(
     46      requestedLocales, availableLocales, defaultLocale, strategy,
     47      supportedLocales);
     48 
     49  nsAutoCString lsDefaultLocale;
     50  LocaleService::GetInstance()->GetDefaultLocale(lsDefaultLocale);
     51  ASSERT_TRUE(supportedLocales.Length() == 1);
     52  ASSERT_TRUE(supportedLocales[0].Equals(lsDefaultLocale));
     53 }