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

Side by Side Diff: chrome/browser/chromeos/options/language_config_view_test.cc

Issue 2764001: Sort input methods names in the language selector by language names. (Closed)
Patch Set: fixed all Created 10 years, 6 months 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
« no previous file with comments | « chrome/browser/chromeos/options/language_config_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <map>
5 #include <string> 6 #include <string>
7 #include <utility>
6 #include <vector> 8 #include <vector>
9
7 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
8 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/chromeos/options/language_config_view.h" 12 #include "chrome/browser/chromeos/options/language_config_view.h"
10 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
11 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
12 15
13 namespace chromeos { 16 namespace chromeos {
14 17
15 TEST(LanguageConfigViewTest, MaybeRewriteLanguageName) { 18 TEST(LanguageConfigViewTest, MaybeRewriteLanguageName) {
16 EXPECT_EQ(L"English", 19 EXPECT_EQ(L"English",
17 LanguageConfigView::MaybeRewriteLanguageName(L"English")); 20 LanguageConfigView::MaybeRewriteLanguageName(L"English"));
18 EXPECT_EQ(l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_OTHERS), 21 EXPECT_EQ(l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_OTHERS),
19 LanguageConfigView::MaybeRewriteLanguageName(L"t")); 22 LanguageConfigView::MaybeRewriteLanguageName(L"t"));
20 } 23 }
21 24
22 TEST(LanguageConfigViewTest, GetLanguageDisplayNameFromCode) { 25 TEST(LanguageConfigViewTest, GetLanguageDisplayNameFromCode) {
23 EXPECT_EQ(L"French", 26 EXPECT_EQ(L"French",
24 LanguageConfigView::GetLanguageDisplayNameFromCode("fr")); 27 LanguageConfigView::GetLanguageDisplayNameFromCode("fr"));
25 // MaybeRewriteLanguageName() should be applied. 28 // MaybeRewriteLanguageName() should be applied.
26 EXPECT_EQ(l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_OTHERS), 29 EXPECT_EQ(l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_OTHERS),
27 LanguageConfigView::GetLanguageDisplayNameFromCode("t")); 30 LanguageConfigView::GetLanguageDisplayNameFromCode("t"));
28 } 31 }
29 32
30 TEST(LanguageConfigViewTest, SortLanguageCodesByNames) { 33 TEST(LanguageConfigViewTest, SortLanguageCodesByNames) {
31 std::vector<std::string> language_codes; 34 std::vector<std::string> language_codes;
35 // Check if this function can handle an empty list.
36 LanguageConfigView::SortLanguageCodesByNames(&language_codes);
37
32 language_codes.push_back("ja"); 38 language_codes.push_back("ja");
33 language_codes.push_back("fr"); 39 language_codes.push_back("fr");
34 language_codes.push_back("t"); 40 language_codes.push_back("t");
35 LanguageConfigView::SortLanguageCodesByNames(&language_codes); 41 LanguageConfigView::SortLanguageCodesByNames(&language_codes);
36 ASSERT_EQ(3, static_cast<int>(language_codes.size())); 42 ASSERT_EQ(3, static_cast<int>(language_codes.size()));
37 ASSERT_EQ("fr", language_codes[0]); // French 43 ASSERT_EQ("fr", language_codes[0]); // French
38 ASSERT_EQ("ja", language_codes[1]); // Japanese 44 ASSERT_EQ("ja", language_codes[1]); // Japanese
39 ASSERT_EQ("t", language_codes[2]); // Others 45 ASSERT_EQ("t", language_codes[2]); // Others
40 46
41 // Add a duplicate entry and see if it works. 47 // Add a duplicate entry and see if it works.
42 language_codes.push_back("ja"); 48 language_codes.push_back("ja");
43 LanguageConfigView::SortLanguageCodesByNames(&language_codes); 49 LanguageConfigView::SortLanguageCodesByNames(&language_codes);
44 ASSERT_EQ(4, static_cast<int>(language_codes.size())); 50 ASSERT_EQ(4, static_cast<int>(language_codes.size()));
45 ASSERT_EQ("fr", language_codes[0]); // French 51 ASSERT_EQ("fr", language_codes[0]); // French
46 ASSERT_EQ("ja", language_codes[1]); // Japanese 52 ASSERT_EQ("ja", language_codes[1]); // Japanese
47 ASSERT_EQ("ja", language_codes[2]); // Japanese 53 ASSERT_EQ("ja", language_codes[2]); // Japanese
48 ASSERT_EQ("t", language_codes[3]); // Others 54 ASSERT_EQ("t", language_codes[3]); // Others
49 } 55 }
50 56
57 TEST(LanguageConfigViewTest, SortInputMethodIdsByNames) {
58 std::map<std::string, std::string> id_to_language_code_map;
59 id_to_language_code_map.insert(std::make_pair("mozc", "ja"));
60 id_to_language_code_map.insert(std::make_pair("mozc-jp", "ja"));
61 id_to_language_code_map.insert(std::make_pair("xkb:jp::jpn", "ja"));
62 id_to_language_code_map.insert(std::make_pair("xkb:fr::fra", "fr"));
63 id_to_language_code_map.insert(std::make_pair("m17n:latn-pre", "t"));
64
65 std::vector<std::string> input_method_ids;
66 // Check if this function can handle an empty list.
67 LanguageConfigView::SortInputMethodIdsByNames(id_to_language_code_map,
68 &input_method_ids);
69
70 input_method_ids.push_back("mozc"); // Japanese
71 input_method_ids.push_back("xkb:fr::fra"); // French
72 input_method_ids.push_back("m17n:latn-pre"); // Others
73 LanguageConfigView::SortInputMethodIdsByNames(id_to_language_code_map,
74 &input_method_ids);
75 ASSERT_EQ(3, static_cast<int>(input_method_ids.size()));
76 ASSERT_EQ("xkb:fr::fra", input_method_ids[0]); // French
77 ASSERT_EQ("mozc", input_method_ids[1]); // Japanese
78 ASSERT_EQ("m17n:latn-pre", input_method_ids[2]); // Others
79
80 // Add a duplicate entry and see if it works.
81 // Note that SortInputMethodIdsByNames uses std::stable_sort.
82 input_method_ids.push_back("xkb:jp::jpn"); // also Japanese
83 LanguageConfigView::SortInputMethodIdsByNames(id_to_language_code_map,
84 &input_method_ids);
85 ASSERT_EQ(4, static_cast<int>(input_method_ids.size()));
86 ASSERT_EQ("xkb:fr::fra", input_method_ids[0]); // French
87 ASSERT_EQ("mozc", input_method_ids[1]); // Japanese
88 ASSERT_EQ("xkb:jp::jpn", input_method_ids[2]); // Japanese
89 ASSERT_EQ("m17n:latn-pre", input_method_ids[3]); // Others
90
91 input_method_ids.push_back("mozc-jp"); // also Japanese
92 LanguageConfigView::SortInputMethodIdsByNames(id_to_language_code_map,
93 &input_method_ids);
94 ASSERT_EQ(5, static_cast<int>(input_method_ids.size()));
95 ASSERT_EQ("xkb:fr::fra", input_method_ids[0]); // French
96 ASSERT_EQ("mozc", input_method_ids[1]); // Japanese
97 ASSERT_EQ("xkb:jp::jpn", input_method_ids[2]); // Japanese
98 ASSERT_EQ("mozc-jp", input_method_ids[3]); // Japanese
99 ASSERT_EQ("m17n:latn-pre", input_method_ids[4]); // Others
100 }
101
51 TEST(LanguageConfigViewTest, ReorderInputMethodIdsForLanguageCode_DE) { 102 TEST(LanguageConfigViewTest, ReorderInputMethodIdsForLanguageCode_DE) {
52 std::vector<std::string> input_method_ids; 103 std::vector<std::string> input_method_ids;
53 input_method_ids.push_back("xkb:ch::ger"); // Switzerland - German 104 input_method_ids.push_back("xkb:ch::ger"); // Switzerland - German
54 input_method_ids.push_back("xkb:de::ger"); // Germany - German 105 input_method_ids.push_back("xkb:de::ger"); // Germany - German
55 LanguageConfigView::ReorderInputMethodIdsForLanguageCode( 106 LanguageConfigView::ReorderInputMethodIdsForLanguageCode(
56 "de", &input_method_ids); 107 "de", &input_method_ids);
57 // The list should be reordered. 108 // The list should be reordered.
58 ASSERT_EQ(2, static_cast<int>(input_method_ids.size())); 109 ASSERT_EQ(2, static_cast<int>(input_method_ids.size()));
59 EXPECT_EQ("xkb:de::ger", input_method_ids[0]); 110 EXPECT_EQ("xkb:de::ger", input_method_ids[0]);
60 EXPECT_EQ("xkb:ch::ger", input_method_ids[1]); 111 EXPECT_EQ("xkb:ch::ger", input_method_ids[1]);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 EXPECT_EQ("de", model.GetLocaleFromIndex(model.GetLanguageIndex(2))); 231 EXPECT_EQ("de", model.GetLocaleFromIndex(model.GetLanguageIndex(2)));
181 EXPECT_EQ("ko", model.GetLocaleFromIndex(model.GetLanguageIndex(3))); 232 EXPECT_EQ("ko", model.GetLocaleFromIndex(model.GetLanguageIndex(3)));
182 233
183 // Mark "ja" (not in the model) to be ignored. 234 // Mark "ja" (not in the model) to be ignored.
184 model.SetIgnored("ja", true); 235 model.SetIgnored("ja", true);
185 // The GetItemCount() should not be changed. 236 // The GetItemCount() should not be changed.
186 ASSERT_EQ(4, model.GetItemCount()); 237 ASSERT_EQ(4, model.GetItemCount());
187 } 238 }
188 239
189 } // namespace chromeos 240 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/options/language_config_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698