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

Side by Side Diff: chrome/browser/ui/webui/options/language_options_handler_unittest.cc

Issue 9814030: get rid of old options pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "chrome/browser/ui/webui/options/language_options_handler.h"
6
7 #include <string>
8
9 #include "base/values.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 #if defined(OS_CHROMEOS)
13 #include "chrome/browser/chromeos/input_method/input_method_descriptor.h"
14 #include "chrome/browser/chromeos/input_method/input_method_whitelist.h"
15 #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler .h"
16
17 using chromeos::input_method::InputMethodDescriptor;
18 using chromeos::input_method::InputMethodDescriptors;
19 using chromeos::input_method::InputMethodWhitelist;
20
21 namespace {
22
23 class LanguageOptionsHandlerTest : public testing::Test {
24 protected:
25 InputMethodDescriptors CreateInputMethodDescriptors() {
26 InputMethodDescriptors descriptors;
27 descriptors.push_back(GetDesc("xkb:us::eng", "us", "en-US"));
28 descriptors.push_back(GetDesc("xkb:fr::fra", "fr", "fr"));
29 descriptors.push_back(GetDesc("xkb:be::fra", "be", "fr"));
30 descriptors.push_back(GetDesc("mozc", "us", "ja"));
31 return descriptors;
32 }
33
34 private:
35 InputMethodDescriptor GetDesc(const std::string& id,
36 const std::string& raw_layout,
37 const std::string& language_code) {
38 return InputMethodDescriptor(whitelist_,
39 id,
40 "", // name
41 raw_layout,
42 language_code);
43 }
44
45 const InputMethodWhitelist whitelist_;
46 };
47
48 } // namespace
49 #else
50 typedef testing::Test LanguageOptionsHandlerTest;
51 #endif
52
53 #if defined(OS_CHROMEOS)
54 TEST_F(LanguageOptionsHandlerTest, GetInputMethodList) {
55 InputMethodDescriptors descriptors = CreateInputMethodDescriptors();
56 scoped_ptr<ListValue> list(
57 chromeos::CrosLanguageOptionsHandler::GetInputMethodList(descriptors));
58 ASSERT_EQ(4U, list->GetSize());
59
60 DictionaryValue* entry = NULL;
61 DictionaryValue *language_code_set = NULL;
62 std::string input_method_id;
63 std::string display_name;
64 std::string language_code;
65
66 // As shown below, the list should be input method ids should appear in
67 // the same order of the descriptors.
68 ASSERT_TRUE(list->GetDictionary(0, &entry));
69 ASSERT_TRUE(entry->GetString("id", &input_method_id));
70 ASSERT_TRUE(entry->GetString("displayName", &display_name));
71 ASSERT_TRUE(entry->GetDictionary("languageCodeSet", &language_code_set));
72 EXPECT_EQ("xkb:us::eng", input_method_id);
73 // Commented out as it depends on translation in generated_resources.grd
74 // (i.e. makes the test fragile).
75 // EXPECT_EQ("English (USA) keyboard layout", display_name);
76 ASSERT_TRUE(language_code_set->HasKey("en-US"));
77 ASSERT_TRUE(language_code_set->HasKey("id")); // From kExtraLanguages.
78 ASSERT_TRUE(language_code_set->HasKey("fil")); // From kExtraLanguages.
79
80 ASSERT_TRUE(list->GetDictionary(1, &entry));
81 ASSERT_TRUE(entry->GetString("id", &input_method_id));
82 ASSERT_TRUE(entry->GetString("displayName", &display_name));
83 ASSERT_TRUE(entry->GetDictionary("languageCodeSet", &language_code_set));
84 EXPECT_EQ("xkb:fr::fra", input_method_id);
85 // Commented out. See above.
86 // EXPECT_EQ("French keyboard layout", display_name);
87 ASSERT_TRUE(language_code_set->HasKey("fr"));
88
89 ASSERT_TRUE(list->GetDictionary(2, &entry));
90 ASSERT_TRUE(entry->GetString("id", &input_method_id));
91 ASSERT_TRUE(entry->GetString("displayName", &display_name));
92 ASSERT_TRUE(entry->GetDictionary("languageCodeSet", &language_code_set));
93 EXPECT_EQ("xkb:be::fra", input_method_id);
94 // Commented out. See above.
95 // EXPECT_EQ("Belgian keyboard layout", display_name);
96 ASSERT_TRUE(language_code_set->HasKey("fr"));
97
98 ASSERT_TRUE(list->GetDictionary(3, &entry));
99 ASSERT_TRUE(entry->GetString("id", &input_method_id));
100 ASSERT_TRUE(entry->GetString("displayName", &display_name));
101 ASSERT_TRUE(entry->GetDictionary("languageCodeSet", &language_code_set));
102 EXPECT_EQ("mozc", input_method_id);
103 // Commented out. See above.
104 // EXPECT_EQ("Japanese input method (for US keyboard)", display_name);
105 ASSERT_TRUE(language_code_set->HasKey("ja"));
106 }
107
108 TEST_F(LanguageOptionsHandlerTest, GetLanguageList) {
109 InputMethodDescriptors descriptors = CreateInputMethodDescriptors();
110 scoped_ptr<ListValue> list(
111 chromeos::CrosLanguageOptionsHandler::GetLanguageList(descriptors));
112 ASSERT_EQ(8U, list->GetSize());
113
114 DictionaryValue* entry = NULL;
115 std::string language_code;
116 std::string display_name;
117 std::string native_display_name;
118
119 // As shown below, the list should be sorted by the display names,
120 // and these names should not have duplicates.
121
122 // This comes from kExtraLanguages.
123 ASSERT_TRUE(list->GetDictionary(0, &entry));
124 ASSERT_TRUE(entry->GetString("code", &language_code));
125 ASSERT_TRUE(entry->GetString("displayName", &display_name));
126 ASSERT_TRUE(entry->GetString("nativeDisplayName", &native_display_name));
127 EXPECT_EQ("nl", language_code);
128 EXPECT_EQ("Dutch", display_name);
129 EXPECT_EQ("Nederlands", native_display_name);
130
131 // This comes from kExtraLanguages.
132 ASSERT_TRUE(list->GetDictionary(1, &entry));
133 ASSERT_TRUE(entry->GetString("code", &language_code));
134 ASSERT_TRUE(entry->GetString("displayName", &display_name));
135 ASSERT_TRUE(entry->GetString("nativeDisplayName", &native_display_name));
136 EXPECT_EQ("en-AU", language_code);
137 EXPECT_EQ("English (Australia)", display_name);
138 EXPECT_EQ("English (Australia)", native_display_name);
139
140 ASSERT_TRUE(list->GetDictionary(2, &entry));
141 ASSERT_TRUE(entry->GetString("code", &language_code));
142 ASSERT_TRUE(entry->GetString("displayName", &display_name));
143 ASSERT_TRUE(entry->GetString("nativeDisplayName", &native_display_name));
144 EXPECT_EQ("en-US", language_code);
145 EXPECT_EQ("English (United States)", display_name);
146 EXPECT_EQ("English (United States)", native_display_name);
147
148 // This comes from kExtraLanguages.
149 ASSERT_TRUE(list->GetDictionary(3, &entry));
150 ASSERT_TRUE(entry->GetString("code", &language_code));
151 ASSERT_TRUE(entry->GetString("displayName", &display_name));
152 ASSERT_TRUE(entry->GetString("nativeDisplayName", &native_display_name));
153 EXPECT_EQ("fil", language_code);
154 EXPECT_EQ("Filipino", display_name);
155 EXPECT_EQ("Filipino", native_display_name);
156
157 ASSERT_TRUE(list->GetDictionary(4, &entry));
158 ASSERT_TRUE(entry->GetString("code", &language_code));
159 ASSERT_TRUE(entry->GetString("displayName", &display_name));
160 ASSERT_TRUE(entry->GetString("nativeDisplayName", &native_display_name));
161 EXPECT_EQ("fr", language_code);
162 EXPECT_EQ("French", display_name);
163 EXPECT_EQ("fran\u00E7ais", native_display_name);
164
165 // This comes from kExtraLanguages.
166 ASSERT_TRUE(list->GetDictionary(5, &entry));
167 ASSERT_TRUE(entry->GetString("code", &language_code));
168 ASSERT_TRUE(entry->GetString("displayName", &display_name));
169 ASSERT_TRUE(entry->GetString("nativeDisplayName", &native_display_name));
170 EXPECT_EQ("id", language_code);
171 EXPECT_EQ("Indonesian", display_name);
172 EXPECT_EQ("Bahasa Indonesia", native_display_name);
173
174 ASSERT_TRUE(list->GetDictionary(6, &entry));
175 ASSERT_TRUE(entry->GetString("code", &language_code));
176 ASSERT_TRUE(entry->GetString("displayName", &display_name));
177 ASSERT_TRUE(entry->GetString("nativeDisplayName", &native_display_name));
178 EXPECT_EQ("ja", language_code);
179 EXPECT_EQ("Japanese", display_name);
180 EXPECT_EQ("\u65E5\u672C\u8A9E", native_display_name);
181
182 // This comes from kExtraLanguages.
183 ASSERT_TRUE(list->GetDictionary(7, &entry));
184 ASSERT_TRUE(entry->GetString("code", &language_code));
185 ASSERT_TRUE(entry->GetString("displayName", &display_name));
186 ASSERT_TRUE(entry->GetString("nativeDisplayName", &native_display_name));
187 EXPECT_EQ("es-419", language_code);
188 EXPECT_EQ("Spanish (Latin America)", display_name);
189 EXPECT_EQ("espa\u00F1ol (Latinoam\u00E9rica)", native_display_name);
190 }
191 #endif // defined(OS_CHROMEOS)
192
193 #if !defined(OS_MACOSX)
194 TEST_F(LanguageOptionsHandlerTest, GetUILanguageCodeSet) {
195 scoped_ptr<DictionaryValue> dictionary(
196 LanguageOptionsHandler::GetUILanguageCodeSet());
197 EXPECT_TRUE(dictionary->HasKey("en-US"));
198 // Note that we don't test a false case, as such an expectation will
199 // fail when we add support for the language.
200 // EXPECT_FALSE(dictionary->HasKey("no"));
201 }
202 #endif // !defined(OS_MACOSX)
203
204 TEST_F(LanguageOptionsHandlerTest, GetSpellCheckLanguageCodeSet) {
205 scoped_ptr<DictionaryValue> dictionary(
206 LanguageOptionsHandler::GetSpellCheckLanguageCodeSet());
207 EXPECT_TRUE(dictionary->HasKey("en-US"));
208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698