OLD | NEW |
| (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 "chrome/browser/chromeos/dom_ui/language_options_handler.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/scoped_ptr.h" | |
10 #include "base/values.h" | |
11 #include "chrome/browser/chromeos/cros/cros_library.h" | |
12 #include "chrome/browser/chromeos/cros/input_method_library.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 namespace chromeos { | |
16 | |
17 static InputMethodDescriptors CreateInputMethodDescriptors() { | |
18 InputMethodDescriptors descriptors; | |
19 descriptors.push_back( | |
20 InputMethodDescriptor("xkb:us::eng", "USA", "us", "eng")); | |
21 descriptors.push_back( | |
22 InputMethodDescriptor("xkb:fr::fra", "France", "fr", "fra")); | |
23 descriptors.push_back( | |
24 InputMethodDescriptor("xkb:be::fra", "Belgium", "be", "fr")); | |
25 descriptors.push_back( | |
26 InputMethodDescriptor("mozc", "Mozc (US keyboard layout)", "us", "ja")); | |
27 return descriptors; | |
28 } | |
29 | |
30 TEST(LanguageOptionsHandlerTest, GetInputMethodList) { | |
31 // Use the stub libcros. The object will take care of the cleanup. | |
32 ScopedStubCrosEnabler stub_cros_enabler; | |
33 | |
34 // Reset the library implementation so it will be initialized | |
35 // again. Otherwise, non-stub implementation can be reused, if it's | |
36 // already initialized elsewhere, which results in a crash. | |
37 CrosLibrary::Get()->GetTestApi()->SetInputMethodLibrary(NULL, false); | |
38 | |
39 InputMethodDescriptors descriptors = CreateInputMethodDescriptors(); | |
40 scoped_ptr<ListValue> list( | |
41 LanguageOptionsHandler::GetInputMethodList(descriptors)); | |
42 ASSERT_EQ(4U, list->GetSize()); | |
43 | |
44 DictionaryValue* entry = NULL; | |
45 DictionaryValue *language_code_set = NULL; | |
46 std::string input_method_id; | |
47 std::string display_name; | |
48 std::string language_code; | |
49 | |
50 // As shown below, the list should be input method ids should appear in | |
51 // the same order of the descriptors. | |
52 ASSERT_TRUE(list->GetDictionary(0, &entry)); | |
53 ASSERT_TRUE(entry->GetString("id", &input_method_id)); | |
54 ASSERT_TRUE(entry->GetString("displayName", &display_name)); | |
55 ASSERT_TRUE(entry->GetDictionary("languageCodeSet", &language_code_set)); | |
56 EXPECT_EQ("xkb:us::eng", input_method_id); | |
57 // Commented out as it depends on translation in generated_resources.grd | |
58 // (i.e. makes the test fragile). | |
59 // EXPECT_EQ("English (USA) keyboard layout", display_name); | |
60 ASSERT_TRUE(language_code_set->HasKey("en-US")); | |
61 ASSERT_TRUE(language_code_set->HasKey("id")); // From kExtraLanguages. | |
62 ASSERT_TRUE(language_code_set->HasKey("fil")); // From kExtraLanguages. | |
63 | |
64 ASSERT_TRUE(list->GetDictionary(1, &entry)); | |
65 ASSERT_TRUE(entry->GetString("id", &input_method_id)); | |
66 ASSERT_TRUE(entry->GetString("displayName", &display_name)); | |
67 ASSERT_TRUE(entry->GetDictionary("languageCodeSet", &language_code_set)); | |
68 EXPECT_EQ("xkb:fr::fra", input_method_id); | |
69 // Commented out. See above. | |
70 // EXPECT_EQ("French keyboard layout", display_name); | |
71 ASSERT_TRUE(language_code_set->HasKey("fr")); | |
72 | |
73 ASSERT_TRUE(list->GetDictionary(2, &entry)); | |
74 ASSERT_TRUE(entry->GetString("id", &input_method_id)); | |
75 ASSERT_TRUE(entry->GetString("displayName", &display_name)); | |
76 ASSERT_TRUE(entry->GetDictionary("languageCodeSet", &language_code_set)); | |
77 EXPECT_EQ("xkb:be::fra", input_method_id); | |
78 // Commented out. See above. | |
79 // EXPECT_EQ("Belgian keyboard layout", display_name); | |
80 ASSERT_TRUE(language_code_set->HasKey("fr")); | |
81 | |
82 ASSERT_TRUE(list->GetDictionary(3, &entry)); | |
83 ASSERT_TRUE(entry->GetString("id", &input_method_id)); | |
84 ASSERT_TRUE(entry->GetString("displayName", &display_name)); | |
85 ASSERT_TRUE(entry->GetDictionary("languageCodeSet", &language_code_set)); | |
86 EXPECT_EQ("mozc", input_method_id); | |
87 // Commented out. See above. | |
88 // EXPECT_EQ("Japanese input method (for US keyboard)", display_name); | |
89 ASSERT_TRUE(language_code_set->HasKey("ja")); | |
90 } | |
91 | |
92 TEST(LanguageOptionsHandlerTest, GetLanguageList) { | |
93 InputMethodDescriptors descriptors = CreateInputMethodDescriptors(); | |
94 scoped_ptr<ListValue> list( | |
95 LanguageOptionsHandler::GetLanguageList(descriptors)); | |
96 ASSERT_EQ(6U, list->GetSize()); | |
97 | |
98 DictionaryValue* entry = NULL; | |
99 std::string language_code; | |
100 std::string display_name; | |
101 std::string native_display_name; | |
102 | |
103 // As shown below, the list should be sorted by the display names, | |
104 // and these names should not have duplicates. | |
105 ASSERT_TRUE(list->GetDictionary(0, &entry)); | |
106 ASSERT_TRUE(entry->GetString("code", &language_code)); | |
107 ASSERT_TRUE(entry->GetString("displayName", &display_name)); | |
108 ASSERT_TRUE(entry->GetString("nativeDisplayName", &native_display_name)); | |
109 EXPECT_EQ("en-US", language_code); | |
110 EXPECT_EQ("English (United States)", display_name); | |
111 EXPECT_EQ("English (United States)", native_display_name); | |
112 | |
113 // This comes from kExtraLanguages. | |
114 ASSERT_TRUE(list->GetDictionary(1, &entry)); | |
115 ASSERT_TRUE(entry->GetString("code", &language_code)); | |
116 ASSERT_TRUE(entry->GetString("displayName", &display_name)); | |
117 ASSERT_TRUE(entry->GetString("nativeDisplayName", &native_display_name)); | |
118 EXPECT_EQ("fil", language_code); | |
119 EXPECT_EQ("Filipino", display_name); | |
120 EXPECT_EQ("Filipino", native_display_name); | |
121 | |
122 ASSERT_TRUE(list->GetDictionary(2, &entry)); | |
123 ASSERT_TRUE(entry->GetString("code", &language_code)); | |
124 ASSERT_TRUE(entry->GetString("displayName", &display_name)); | |
125 ASSERT_TRUE(entry->GetString("nativeDisplayName", &native_display_name)); | |
126 EXPECT_EQ("fr", language_code); | |
127 EXPECT_EQ("French", display_name); | |
128 EXPECT_EQ("fran\u00E7ais", native_display_name); | |
129 | |
130 // This comes from kExtraLanguages. | |
131 ASSERT_TRUE(list->GetDictionary(3, &entry)); | |
132 ASSERT_TRUE(entry->GetString("code", &language_code)); | |
133 ASSERT_TRUE(entry->GetString("displayName", &display_name)); | |
134 ASSERT_TRUE(entry->GetString("nativeDisplayName", &native_display_name)); | |
135 EXPECT_EQ("id", language_code); | |
136 EXPECT_EQ("Indonesian", display_name); | |
137 EXPECT_EQ("Bahasa Indonesia", native_display_name); | |
138 | |
139 ASSERT_TRUE(list->GetDictionary(4, &entry)); | |
140 ASSERT_TRUE(entry->GetString("code", &language_code)); | |
141 ASSERT_TRUE(entry->GetString("displayName", &display_name)); | |
142 ASSERT_TRUE(entry->GetString("nativeDisplayName", &native_display_name)); | |
143 EXPECT_EQ("ja", language_code); | |
144 EXPECT_EQ("Japanese", display_name); | |
145 EXPECT_EQ("\u65E5\u672C\u8A9E", native_display_name); | |
146 | |
147 // This comes from kExtraLanguages. | |
148 ASSERT_TRUE(list->GetDictionary(5, &entry)); | |
149 ASSERT_TRUE(entry->GetString("code", &language_code)); | |
150 ASSERT_TRUE(entry->GetString("displayName", &display_name)); | |
151 ASSERT_TRUE(entry->GetString("nativeDisplayName", &native_display_name)); | |
152 EXPECT_EQ("es-419", language_code); | |
153 EXPECT_EQ("Spanish (Latin America and the Caribbean)", display_name); | |
154 EXPECT_EQ("espa\u00F1ol (Latinoam\u00E9rica y el Caribe)", | |
155 native_display_name); | |
156 } | |
157 | |
158 TEST(LanguageOptionsHandlerTest, GetUiLanguageCodeSet) { | |
159 scoped_ptr<DictionaryValue> dictionary( | |
160 LanguageOptionsHandler::GetUiLanguageCodeSet()); | |
161 EXPECT_TRUE(dictionary->HasKey("en-US")); | |
162 // Note that we don't test a false case, as such an expectation will | |
163 // fail when we add support for the language. | |
164 // EXPECT_FALSE(dictionary->HasKey("no")); | |
165 } | |
166 | |
167 TEST(LanguageOptionsHandlerTest, GetSpellCheckLanguageCodeSet) { | |
168 scoped_ptr<DictionaryValue> dictionary( | |
169 LanguageOptionsHandler::GetSpellCheckLanguageCodeSet()); | |
170 EXPECT_TRUE(dictionary->HasKey("en-US")); | |
171 } | |
172 | |
173 } // namespace chromeos | |
OLD | NEW |