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

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
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 // defined(GOOGLE_CHROME_BUILD)
robertshield 2010/11/11 14:42:18 you don't really need the qualifying comments on t
grt (UTC plus 2) 2010/11/11 16:29:27 Done.
22 L"en-us"
23 #endif // !defined(GOOGLE_CHROME_BUILD)
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 // defined(GOOGLE_CHROME_BUILD)
31 // There is only en-us.
32 L"en-us"
33 #endif // !defined(GOOGLE_CHROME_BUILD)
robertshield 2010/11/11 14:42:18 You don't really need them on the #endif either gi
grt (UTC plus 2) 2010/11/11 15:23:57 My style for these is to make the comment contain
robertshield 2010/11/11 16:18:53 The comments are great for longer blocks, IMO they
grt (UTC plus 2) 2010/11/11 16:29:27 Done.
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 // defined(GOOGLE_CHROME_BUILD)
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_EQ(L"fr", instance.matched_candidate());
62 #else // defined(GOOGLE_CHROME_BUILD)
63 EXPECT_EQ(L"en-us", instance.matched_candidate());
64 #endif // !defined(GOOGLE_CHROME_BUILD)
65 }
66 {
67 std::wstring candidates[] = {
68 L"xx-YY"
69 };
70 installer_util::LanguageSelector instance(
71 std::vector<std::wstring>(&candidates[0],
72 &candidates[arraysize(candidates)]));
73 EXPECT_EQ(L"en-us", instance.matched_candidate());
74 }
75 }
76
77 // A fixture for testing sets of single-candidate selections.
78 class LanguageSelectorMatchCandidateTest
79 : public ::testing::TestWithParam<const wchar_t*> {
80 };
81
82 TEST_P(LanguageSelectorMatchCandidateTest, TestMatchCandidate) {
83 installer_util::LanguageSelector instance(
84 std::vector<std::wstring>(1, std::wstring(GetParam())));
85 EXPECT_EQ(GetParam(), instance.matched_candidate());
86 }
87
88 // Test that all existing translations can be found by exact match.
89 INSTANTIATE_TEST_CASE_P(
90 TestExactMatches,
91 LanguageSelectorMatchCandidateTest,
92 ::testing::ValuesIn(
93 &kExactMatchCandidates[0],
94 &kExactMatchCandidates[arraysize(kExactMatchCandidates)]));
95
96 // Test the alias matches.
97 INSTANTIATE_TEST_CASE_P(
98 TestAliasMatches,
99 LanguageSelectorMatchCandidateTest,
100 ::testing::ValuesIn(
101 &kAliasMatchCandidates[0],
102 &kAliasMatchCandidates[arraysize(kAliasMatchCandidates)]));
103
104 // Test a few wildcard matches.
105 INSTANTIATE_TEST_CASE_P(
106 TestWildcardMatches,
107 LanguageSelectorMatchCandidateTest,
108 ::testing::ValuesIn(
109 &kWildcardMatchCandidates[0],
110 &kWildcardMatchCandidates[arraysize(kWildcardMatchCandidates)]));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698