1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/android/preferences/pref_service_bridge.h"
9 #include "testing/gtest/include/gtest/gtest.h"
12 // A test class for PrefServiceBridge class.
13 class PrefServiceBridgeTest
: public testing::Test
{
15 std::string
GetAcceptLanguages(std::string locale
,
16 std::string accept_languages
) {
17 PrependToAcceptLanguagesIfNecessary(locale
, &accept_languages
);
18 return accept_languages
;
22 TEST_F(PrefServiceBridgeTest
, PrependToAcceptLanguagesAsNecessary
) {
23 EXPECT_EQ("ms-MY,ms,en-US,en", GetAcceptLanguages("ms_MY", "en-US,en"));
25 EXPECT_EQ("de-CH,de-DE,de,en-US,en",
26 GetAcceptLanguages("de_CH", "de-DE,de,en-US,en"));
28 // Make sure we do not prepend language code even when a language code is at
30 EXPECT_EQ("zh-TW,zh-CN,zh", GetAcceptLanguages("zh_TW", "zh-CN,zh"));
33 TEST_F(PrefServiceBridgeTest
,
34 ShouldNotPrependToAcceptLanguagesWhenNotNecessary
) {
35 // Java has some deprecated two letter language code. For instance, "iw" is
36 // an old code that needs to be replaced by "he" which is the new code for
38 EXPECT_EQ("he-IL,he,en-US,en",
39 GetAcceptLanguages("iw_IL", "he-IL,he,en-US,en"));
41 // This logic should not affect cases where original accept language already
42 // reflects the language code in the locale.
43 EXPECT_EQ("en-US,en", GetAcceptLanguages("en_US", "en-US,en"));
44 EXPECT_EQ("zh-CN,zh", GetAcceptLanguages("zh_CN", "zh-CN,zh"));
46 // "ms" is not expected. No replacement takes place.
47 EXPECT_EQ("en-US,en", GetAcceptLanguages("ms", "en-US,en"));