Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / android / preferences / pref_service_bridge_unittest.cc
blobc73a998ec74228e8bcdd17d25efdd895bc30139a
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"
7 #include <string>
9 #include "testing/gtest/include/gtest/gtest.h"
12 // A test class for PrefServiceBridge class.
13 class PrefServiceBridgeTest : public testing::Test {
14 public:
15 std::string GetAcceptLanguages(std::string locale,
16 std::string accept_languages) {
17 PrefServiceBridge::PrependToAcceptLanguagesIfNecessary(locale,
18 &accept_languages);
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
30 // the end.
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
38 // Hebrew.
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"));