Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: chrome/installer/util/language_selector_unittest.cc

Issue 4139010: The UI language rather than the locale is now used to pick Chrome's language ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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.
4
5 #include <string>
6 #include <vector>
7
8 #include "chrome/installer/util/language_selector.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace {
12
13 const wchar_t* const kExactMatchCandidates[] = {
14 #if defined(GOOGLE_CHROME_BUILD)
15 L"am", L"ar", L"bg", L"bn", L"ca", L"cs", L"da", L"de", L"el", L"en-gb",
16 L"en-us", L"es", L"es-419", L"et", L"fa", L"fi", L"fil", L"fr", L"gu", L"hi",
17 L"hr", L"hu", L"id", L"it", L"iw", L"ja", L"kn", L"ko", L"lt", L"lv", L"ml",
18 L"mr", L"nl", L"no", L"pl", L"pt-br", L"pt-pt", L"ro", L"ru", L"sk", L"sl",
19 L"sr", L"sv", L"sw", L"ta", L"te", L"th", L"tr", L"uk", L"vi", L"zh-cn",
20 L"zh-tw"
21 #else
22 L"en-us"
23 #endif
24 };
25
26 const wchar_t* const kAliasMatchCandidates[] = {
27 #if defined(GOOGLE_CHROME_BUILD)
28 L"he", L"nb", L"tl", L"zh-chs", L"zh-cht", L"zh-hans", L"zh-hant", L"zh-hk",
29 L"zh-mk", L"zh-mo"
30 #else
31 // There is only en-us.
32 L"en-us"
33 #endif
34 };
35
36 const wchar_t* const kWildcardMatchCandidates[] = {
37 L"en-AU",
38 #if defined(GOOGLE_CHROME_BUILD)
39 L"es-CO", L"pt-AB", L"zh-SG"
40 #endif
41 };
42
43 } // namespace
44
45 // Test that a language is selected from the system.
46 TEST(LanguageSelectorTest, DefaultSelection) {
47 installer_util::LanguageSelector instance;
48 EXPECT_FALSE(instance.matched_candidate().empty());
49 }
50
51 // Test some hypothetical candidate sets.
52 TEST(LanguageSelectorTest, AssortedSelections) {
53 {
54 std::wstring candidates[] = {
55 L"fr-BE", L"fr", L"en"
56 };
57 installer_util::LanguageSelector instance(
58 std::vector<std::wstring>(&candidates[0],
59 &candidates[arraysize(candidates)]));
60 #if defined(GOOGLE_CHROME_BUILD)
61 // Expect the exact match to win.
62 EXPECT_EQ(L"fr", instance.matched_candidate());
63 #else
64 // Expect the exact match to win.
65 EXPECT_EQ(L"en", instance.matched_candidate());
66 #endif
67 }
68 {
69 std::wstring candidates[] = {
70 L"xx-YY", L"cc-Ssss-RR"
71 };
72 installer_util::LanguageSelector instance(
73 std::vector<std::wstring>(&candidates[0],
74 &candidates[arraysize(candidates)]));
75 // Expect the fallback to win.
76 EXPECT_EQ(L"en-us", instance.matched_candidate());
77 }
78 {
79 std::wstring candidates[] = {
80 L"zh-SG", L"en-GB"
81 };
82 installer_util::LanguageSelector instance(
83 std::vector<std::wstring>(&candidates[0],
84 &candidates[arraysize(candidates)]));
85 #if defined(GOOGLE_CHROME_BUILD)
86 // Expect the alias match to win.
87 EXPECT_EQ(L"zh-SG", instance.matched_candidate());
88 #else
89 // Expect the exact match to win.
90 EXPECT_EQ(L"en-GB", instance.matched_candidate());
91 #endif
92 }
93 }
94
95 // A fixture for testing sets of single-candidate selections.
96 class LanguageSelectorMatchCandidateTest
97 : public ::testing::TestWithParam<const wchar_t*> {
98 };
99
100 TEST_P(LanguageSelectorMatchCandidateTest, TestMatchCandidate) {
101 installer_util::LanguageSelector instance(
102 std::vector<std::wstring>(1, std::wstring(GetParam())));
103 EXPECT_EQ(GetParam(), instance.matched_candidate());
104 }
105
106 // Test that all existing translations can be found by exact match.
107 INSTANTIATE_TEST_CASE_P(
108 TestExactMatches,
109 LanguageSelectorMatchCandidateTest,
110 ::testing::ValuesIn(
111 &kExactMatchCandidates[0],
112 &kExactMatchCandidates[arraysize(kExactMatchCandidates)]));
113
114 // Test the alias matches.
115 INSTANTIATE_TEST_CASE_P(
116 TestAliasMatches,
117 LanguageSelectorMatchCandidateTest,
118 ::testing::ValuesIn(
119 &kAliasMatchCandidates[0],
120 &kAliasMatchCandidates[arraysize(kAliasMatchCandidates)]));
121
122 // Test a few wildcard matches.
123 INSTANTIATE_TEST_CASE_P(
124 TestWildcardMatches,
125 LanguageSelectorMatchCandidateTest,
126 ::testing::ValuesIn(
127 &kWildcardMatchCandidates[0],
128 &kWildcardMatchCandidates[arraysize(kWildcardMatchCandidates)]));
OLDNEW
« no previous file with comments | « chrome/installer/util/language_selector.cc ('k') | chrome/installer/util/prebuild/create_string_rc.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698