| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/login/l10n_util.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "chrome/browser/chromeos/customization/customization_document.h" | 17 #include "chrome/browser/chromeos/customization/customization_document.h" |
| 17 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 18 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
| 18 #include "chrome/browser/ui/webui/chromeos/login/l10n_util_test_util.h" | 19 #include "chrome/browser/ui/webui/chromeos/login/l10n_util_test_util.h" |
| 19 #include "chromeos/system/statistics_provider.h" | 20 #include "chromeos/system/statistics_provider.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/base/ime/chromeos/component_extension_ime_manager.h" | 22 #include "ui/base/ime/chromeos/component_extension_ime_manager.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 L10nUtilTest::L10nUtilTest() | 93 L10nUtilTest::L10nUtilTest() |
| 93 : input_manager_(new MockInputMethodManagerWithInputMethods) { | 94 : input_manager_(new MockInputMethodManagerWithInputMethods) { |
| 94 } | 95 } |
| 95 | 96 |
| 96 L10nUtilTest::~L10nUtilTest() { | 97 L10nUtilTest::~L10nUtilTest() { |
| 97 } | 98 } |
| 98 | 99 |
| 99 void L10nUtilTest::SetUp() { | 100 void L10nUtilTest::SetUp() { |
| 100 chromeos::input_method::InitializeForTesting(input_manager_); | 101 chromeos::input_method::InitializeForTesting(input_manager_); |
| 101 input_manager_->SetComponentExtensionIMEManager( | 102 input_manager_->SetComponentExtensionIMEManager( |
| 102 make_scoped_ptr(new ComponentExtensionIMEManager)); | 103 base::WrapUnique(new ComponentExtensionIMEManager)); |
| 103 MachineStatisticsInitializer::GetInstance(); // Ignore result. | 104 MachineStatisticsInitializer::GetInstance(); // Ignore result. |
| 104 } | 105 } |
| 105 | 106 |
| 106 void L10nUtilTest::TearDown() { | 107 void L10nUtilTest::TearDown() { |
| 107 chromeos::input_method::Shutdown(); | 108 chromeos::input_method::Shutdown(); |
| 108 } | 109 } |
| 109 | 110 |
| 110 void L10nUtilTest::SetInputMethods1() { | 111 void L10nUtilTest::SetInputMethods1() { |
| 111 input_manager_->AddInputMethod("xkb:us::eng", "us", "en-US"); | 112 input_manager_->AddInputMethod("xkb:us::eng", "us", "en-US"); |
| 112 input_manager_->AddInputMethod("xkb:fr::fra", "fr", "fr"); | 113 input_manager_->AddInputMethod("xkb:fr::fra", "fr", "fr"); |
| 113 input_manager_->AddInputMethod("xkb:be::fra", "be", "fr"); | 114 input_manager_->AddInputMethod("xkb:be::fra", "be", "fr"); |
| 114 input_manager_->AddInputMethod("xkb:is::ice", "is", "is"); | 115 input_manager_->AddInputMethod("xkb:is::ice", "is", "is"); |
| 115 } | 116 } |
| 116 | 117 |
| 117 void L10nUtilTest::SetInputMethods2() { | 118 void L10nUtilTest::SetInputMethods2() { |
| 118 input_manager_->AddInputMethod("xkb:us::eng", "us", "en-US"); | 119 input_manager_->AddInputMethod("xkb:us::eng", "us", "en-US"); |
| 119 input_manager_->AddInputMethod("xkb:ch:fr:fra", "ch(fr)", "fr"); | 120 input_manager_->AddInputMethod("xkb:ch:fr:fra", "ch(fr)", "fr"); |
| 120 input_manager_->AddInputMethod("xkb:ch::ger", "ch", "de"); | 121 input_manager_->AddInputMethod("xkb:ch::ger", "ch", "de"); |
| 121 input_manager_->AddInputMethod("xkb:it::ita", "it", "it"); | 122 input_manager_->AddInputMethod("xkb:it::ita", "it", "it"); |
| 122 input_manager_->AddInputMethod("xkb:is::ice", "is", "is"); | 123 input_manager_->AddInputMethod("xkb:is::ice", "is", "is"); |
| 123 } | 124 } |
| 124 | 125 |
| 125 TEST_F(L10nUtilTest, GetUILanguageList) { | 126 TEST_F(L10nUtilTest, GetUILanguageList) { |
| 126 SetInputMethods1(); | 127 SetInputMethods1(); |
| 127 | 128 |
| 128 // This requires initialized StatisticsProvider (see L10nUtilTest()). | 129 // This requires initialized StatisticsProvider (see L10nUtilTest()). |
| 129 scoped_ptr<base::ListValue> list(GetUILanguageList(NULL, std::string())); | 130 std::unique_ptr<base::ListValue> list(GetUILanguageList(NULL, std::string())); |
| 130 | 131 |
| 131 VerifyOnlyUILanguages(*list); | 132 VerifyOnlyUILanguages(*list); |
| 132 } | 133 } |
| 133 | 134 |
| 134 TEST_F(L10nUtilTest, FindMostRelevantLocale) { | 135 TEST_F(L10nUtilTest, FindMostRelevantLocale) { |
| 135 base::ListValue available_locales; | 136 base::ListValue available_locales; |
| 136 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 137 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 137 dict->SetString("value", "de"); | 138 dict->SetString("value", "de"); |
| 138 available_locales.Append(dict.release()); | 139 available_locales.Append(dict.release()); |
| 139 dict.reset(new base::DictionaryValue); | 140 dict.reset(new base::DictionaryValue); |
| 140 dict->SetString("value", "fr"); | 141 dict->SetString("value", "fr"); |
| 141 available_locales.Append(dict.release()); | 142 available_locales.Append(dict.release()); |
| 142 dict.reset(new base::DictionaryValue); | 143 dict.reset(new base::DictionaryValue); |
| 143 dict->SetString("value", "en-GB"); | 144 dict->SetString("value", "en-GB"); |
| 144 available_locales.Append(dict.release()); | 145 available_locales.Append(dict.release()); |
| 145 | 146 |
| 146 std::vector<std::string> most_relevant_language_codes; | 147 std::vector<std::string> most_relevant_language_codes; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 " \"eula_page\" : \"file:///opt/oem/eula/en-US/eula.html\",\n" | 184 " \"eula_page\" : \"file:///opt/oem/eula/en-US/eula.html\",\n" |
| 184 " },\n" | 185 " },\n" |
| 185 " }," | 186 " }," |
| 186 "}"; | 187 "}"; |
| 187 | 188 |
| 188 TEST_F(L10nUtilTest, GetUILanguageListMulti) { | 189 TEST_F(L10nUtilTest, GetUILanguageListMulti) { |
| 189 InitStartupCustomizationDocumentForTesting(kStartupManifest); | 190 InitStartupCustomizationDocumentForTesting(kStartupManifest); |
| 190 SetInputMethods2(); | 191 SetInputMethods2(); |
| 191 | 192 |
| 192 // This requires initialized StatisticsProvider (see L10nUtilTest()). | 193 // This requires initialized StatisticsProvider (see L10nUtilTest()). |
| 193 scoped_ptr<base::ListValue> list(GetUILanguageList(NULL, std::string())); | 194 std::unique_ptr<base::ListValue> list(GetUILanguageList(NULL, std::string())); |
| 194 | 195 |
| 195 VerifyOnlyUILanguages(*list); | 196 VerifyOnlyUILanguages(*list); |
| 196 | 197 |
| 197 // (4 languages (except Icelandic) + divider) = 5 + all other languages | 198 // (4 languages (except Icelandic) + divider) = 5 + all other languages |
| 198 ASSERT_LE(5u, list->GetSize()); | 199 ASSERT_LE(5u, list->GetSize()); |
| 199 | 200 |
| 200 VerifyLanguageCode(*list, 0, "fr"); | 201 VerifyLanguageCode(*list, 0, "fr"); |
| 201 VerifyLanguageCode(*list, 1, "en-US"); | 202 VerifyLanguageCode(*list, 1, "en-US"); |
| 202 VerifyLanguageCode(*list, 2, "de"); | 203 VerifyLanguageCode(*list, 2, "de"); |
| 203 VerifyLanguageCode(*list, 3, "it"); | 204 VerifyLanguageCode(*list, 3, "it"); |
| 204 VerifyLanguageCode(*list, 4, kMostRelevantLanguagesDivider); | 205 VerifyLanguageCode(*list, 4, kMostRelevantLanguagesDivider); |
| 205 } | 206 } |
| 206 | 207 |
| 207 TEST_F(L10nUtilTest, GetUILanguageListWithMostRelevant) { | 208 TEST_F(L10nUtilTest, GetUILanguageListWithMostRelevant) { |
| 208 std::vector<std::string> most_relevant_language_codes; | 209 std::vector<std::string> most_relevant_language_codes; |
| 209 most_relevant_language_codes.push_back("it"); | 210 most_relevant_language_codes.push_back("it"); |
| 210 most_relevant_language_codes.push_back("de"); | 211 most_relevant_language_codes.push_back("de"); |
| 211 most_relevant_language_codes.push_back("nonexistent"); | 212 most_relevant_language_codes.push_back("nonexistent"); |
| 212 | 213 |
| 213 // This requires initialized StatisticsProvider (see L10nUtilTest()). | 214 // This requires initialized StatisticsProvider (see L10nUtilTest()). |
| 214 scoped_ptr<base::ListValue> | 215 std::unique_ptr<base::ListValue> list( |
| 215 list(GetUILanguageList(&most_relevant_language_codes, std::string())); | 216 GetUILanguageList(&most_relevant_language_codes, std::string())); |
| 216 | 217 |
| 217 VerifyOnlyUILanguages(*list); | 218 VerifyOnlyUILanguages(*list); |
| 218 | 219 |
| 219 ASSERT_LE(3u, list->GetSize()); | 220 ASSERT_LE(3u, list->GetSize()); |
| 220 | 221 |
| 221 VerifyLanguageCode(*list, 0, "it"); | 222 VerifyLanguageCode(*list, 0, "it"); |
| 222 VerifyLanguageCode(*list, 1, "de"); | 223 VerifyLanguageCode(*list, 1, "de"); |
| 223 VerifyLanguageCode(*list, 2, kMostRelevantLanguagesDivider); | 224 VerifyLanguageCode(*list, 2, kMostRelevantLanguagesDivider); |
| 224 } | 225 } |
| 225 | 226 |
| 226 } // namespace chromeos | 227 } // namespace chromeos |
| OLD | NEW |