| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/webui/options/language_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/language_options_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // EXPECT_EQ("Japanese input method (for US keyboard)", display_name); | 145 // EXPECT_EQ("Japanese input method (for US keyboard)", display_name); |
| 146 ASSERT_TRUE(language_code_set->HasKey("is")); | 146 ASSERT_TRUE(language_code_set->HasKey("is")); |
| 147 } | 147 } |
| 148 | 148 |
| 149 TEST_F(CrosLanguageOptionsHandlerTest, GetUILanguageList) { | 149 TEST_F(CrosLanguageOptionsHandlerTest, GetUILanguageList) { |
| 150 // This requires initialized StatisticsProvider. | 150 // This requires initialized StatisticsProvider. |
| 151 // (see CrosLanguageOptionsHandlerTest() ) | 151 // (see CrosLanguageOptionsHandlerTest() ) |
| 152 InputMethodDescriptors descriptors = CreateInputMethodDescriptors1(); | 152 InputMethodDescriptors descriptors = CreateInputMethodDescriptors1(); |
| 153 scoped_ptr<base::ListValue> list( | 153 scoped_ptr<base::ListValue> list( |
| 154 chromeos::options::CrosLanguageOptionsHandler::GetUILanguageList( | 154 chromeos::options::CrosLanguageOptionsHandler::GetUILanguageList( |
| 155 descriptors)); | 155 descriptors, |
| 156 NULL)); |
| 156 | 157 |
| 157 for (size_t i = 0; i < list->GetSize(); ++i) { | 158 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 158 base::DictionaryValue* dict; | 159 base::DictionaryValue* dict; |
| 159 ASSERT_TRUE(list->GetDictionary(i, &dict)); | 160 ASSERT_TRUE(list->GetDictionary(i, &dict)); |
| 160 std::string code; | 161 std::string code; |
| 161 ASSERT_TRUE(dict->GetString("code", &code)); | 162 ASSERT_TRUE(dict->GetString("code", &code)); |
| 162 EXPECT_NE("is", code) | 163 EXPECT_NE("is", code) |
| 163 << "Icelandic is an example language which has input method " | 164 << "Icelandic is an example language which has input method " |
| 164 << "but can't use it as UI language."; | 165 << "but can't use it as UI language."; |
| 165 } | 166 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 188 } | 189 } |
| 189 | 190 |
| 190 TEST_F(CrosLanguageOptionsHandlerTest, GetUILanguageListMulti) { | 191 TEST_F(CrosLanguageOptionsHandlerTest, GetUILanguageListMulti) { |
| 191 Test__InitStartupCustomizationDocument(kStartupManifest1); | 192 Test__InitStartupCustomizationDocument(kStartupManifest1); |
| 192 | 193 |
| 193 // This requires initialized StatisticsProvider. | 194 // This requires initialized StatisticsProvider. |
| 194 // (see CrosLanguageOptionsHandlerTest() ) | 195 // (see CrosLanguageOptionsHandlerTest() ) |
| 195 InputMethodDescriptors descriptors = CreateInputMethodDescriptors2(); | 196 InputMethodDescriptors descriptors = CreateInputMethodDescriptors2(); |
| 196 scoped_ptr<base::ListValue> list( | 197 scoped_ptr<base::ListValue> list( |
| 197 chromeos::options::CrosLanguageOptionsHandler::GetUILanguageList( | 198 chromeos::options::CrosLanguageOptionsHandler::GetUILanguageList( |
| 198 descriptors)); | 199 descriptors, |
| 200 NULL)); |
| 199 | 201 |
| 200 base::DictionaryValue* dict; | 202 base::DictionaryValue* dict; |
| 201 std::string code; | 203 std::string code; |
| 202 | 204 |
| 203 for (size_t i = 0; i < list->GetSize(); ++i) { | 205 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 204 ASSERT_TRUE(list->GetDictionary(i, &dict)); | 206 ASSERT_TRUE(list->GetDictionary(i, &dict)); |
| 205 ASSERT_TRUE(dict->GetString("code", &code)); | 207 ASSERT_TRUE(dict->GetString("code", &code)); |
| 206 EXPECT_NE("is", code) | 208 EXPECT_NE("is", code) |
| 207 << "Icelandic is an example language which has input method " | 209 << "Icelandic is an example language which has input method " |
| 208 << "but can't use it as UI language."; | 210 << "but can't use it as UI language."; |
| 209 } | 211 } |
| 210 | 212 |
| 211 // (4 languages (except islandic) + divider)=5 + all other languages | 213 // (4 languages (except islandic) + divider)=5 + all other languages |
| 212 EXPECT_GT(list->GetSize(), 5u); | 214 EXPECT_GT(list->GetSize(), 5u); |
| 213 | 215 |
| 214 EXPECT_LANGUAGE_CODE_AT(0, "fr") | 216 EXPECT_LANGUAGE_CODE_AT(0, "fr") |
| 215 EXPECT_LANGUAGE_CODE_AT(1, "en-US") | 217 EXPECT_LANGUAGE_CODE_AT(1, "en-US") |
| 216 EXPECT_LANGUAGE_CODE_AT(2, "de") | 218 EXPECT_LANGUAGE_CODE_AT(2, "de") |
| 217 EXPECT_LANGUAGE_CODE_AT(3, "it") | 219 EXPECT_LANGUAGE_CODE_AT(3, "it") |
| 218 EXPECT_LANGUAGE_CODE_AT(4, | 220 EXPECT_LANGUAGE_CODE_AT(4, chromeos::options::kMostRelevantLanguagesDivider); |
| 219 chromeos::options::kVendorOtherLanguagesListDivider); | |
| 220 } | 221 } |
| 222 |
| 223 TEST_F(CrosLanguageOptionsHandlerTest, GetUILanguageListWithMostRelevant) { |
| 224 std::vector<std::string> most_relevant_language_codes; |
| 225 most_relevant_language_codes.push_back("it"); |
| 226 most_relevant_language_codes.push_back("de"); |
| 227 most_relevant_language_codes.push_back("nonexistent"); |
| 228 |
| 229 // This requires initialized StatisticsProvider. |
| 230 // (see CrosLanguageOptionsHandlerTest() ) |
| 231 InputMethodDescriptors descriptors = CreateInputMethodDescriptors2(); |
| 232 scoped_ptr<base::ListValue> list( |
| 233 chromeos::options::CrosLanguageOptionsHandler::GetUILanguageList( |
| 234 descriptors, |
| 235 &most_relevant_language_codes)); |
| 236 |
| 237 base::DictionaryValue* dict; |
| 238 std::string code; |
| 239 |
| 240 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 241 ASSERT_TRUE(list->GetDictionary(i, &dict)); |
| 242 ASSERT_TRUE(dict->GetString("code", &code)); |
| 243 EXPECT_NE("is", code) |
| 244 << "Icelandic is an example language which has input method " |
| 245 << "but can't use it as UI language."; |
| 246 } |
| 247 |
| 248 EXPECT_GT(list->GetSize(), 3u); |
| 249 |
| 250 EXPECT_LANGUAGE_CODE_AT(0, "it") |
| 251 EXPECT_LANGUAGE_CODE_AT(1, "de") |
| 252 EXPECT_LANGUAGE_CODE_AT(2, chromeos::options::kMostRelevantLanguagesDivider); |
| 253 } |
| 254 |
| OLD | NEW |