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 PrefServiceBridge::PrependToAcceptLanguagesIfNecessary(locale
,
19 return accept_languages
;
23 TEST_F(PrefServiceBridgeTest
, PrependToAcceptLanguagesAsNecessary
) {
24 EXPECT_EQ("ms-MY,ms,en-US,en", GetAcceptLanguages("ms_MY", "en-US,en"));
26 EXPECT_EQ("de-CH,de-DE,de,en-US,en",
27 GetAcceptLanguages("de_CH", "de-DE,de,en-US,en"));
29 // Make sure we do not prepend language code even when a language code is at
31 EXPECT_EQ("zh-TW,zh-CN,zh", GetAcceptLanguages("zh_TW", "zh-CN,zh"));
34 TEST_F(PrefServiceBridgeTest
,
35 ShouldNotPrependToAcceptLanguagesWhenNotNecessary
) {
36 // Java has some deprecated two letter language code. For instance, "iw" is
37 // an old code that needs to be replaced by "he" which is the new code for
39 EXPECT_EQ("he-IL,he,en-US,en",
40 GetAcceptLanguages("iw_IL", "he-IL,he,en-US,en"));
42 // This logic should not affect cases where original accept language already
43 // reflects the language code in the locale.
44 EXPECT_EQ("en-US,en", GetAcceptLanguages("en_US", "en-US,en"));
45 EXPECT_EQ("zh-CN,zh", GetAcceptLanguages("zh_CN", "zh-CN,zh"));
47 // "ms" is not expected. No replacement takes place.
48 EXPECT_EQ("en-US,en", GetAcceptLanguages("ms", "en-US,en"));