Chromium Code Reviews| Index: chrome/browser/ui/webui/options/chromeos/cros_language_options_handler_unittest.cc |
| diff --git a/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler_unittest.cc b/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler_unittest.cc |
| index 3173a88b87948eae8848df9f1aaf151379251a4a..e4ea855a79545102ab995f6c2664f4264551517c 100644 |
| --- a/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler_unittest.cc |
| +++ b/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler_unittest.cc |
| @@ -6,11 +6,15 @@ |
| #include <string> |
| +#include "base/memory/singleton.h" |
| +#include "base/message_loop/message_loop.h" |
| #include "base/values.h" |
| +#include "chrome/browser/chromeos/customization_document.h" |
| #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
| #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" |
| #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.h" |
| #include "chromeos/ime/input_method_descriptor.h" |
| +#include "chromeos/system/statistics_provider.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| using chromeos::input_method::InputMethodDescriptor; |
| @@ -19,17 +23,33 @@ using chromeos::input_method::MockInputMethodManager; |
| namespace { |
| +class MachineStatisticsInitializer { |
| + public: |
| + MachineStatisticsInitializer() { |
| + base::MessageLoop tmp_loop(base::MessageLoop::TYPE_DEFAULT); |
| + chromeos::system::StatisticsProvider::GetInstance() |
| + ->StartLoadingMachineStatistics(tmp_loop.message_loop_proxy(), false); |
| + tmp_loop.RunUntilIdle(); |
| + } |
| + static MachineStatisticsInitializer* GetInstance(); |
| +}; |
| + |
| +MachineStatisticsInitializer* MachineStatisticsInitializer::GetInstance() { |
| + return Singleton<MachineStatisticsInitializer>::get(); |
| +} |
| + |
| class CrosLanguageOptionsHandlerTest : public testing::Test { |
| public: |
| CrosLanguageOptionsHandlerTest() { |
| chromeos::input_method::InitializeForTesting(new MockInputMethodManager); |
| + MachineStatisticsInitializer::GetInstance(); // Ignore result |
| } |
| virtual ~CrosLanguageOptionsHandlerTest() { |
| chromeos::input_method::Shutdown(); |
| } |
| protected: |
| - InputMethodDescriptors CreateInputMethodDescriptors() { |
| + InputMethodDescriptors CreateInputMethodDescriptors1() { |
| InputMethodDescriptors descriptors; |
| descriptors.push_back(GetDesc("xkb:us::eng", "us", "en-US")); |
| descriptors.push_back(GetDesc("xkb:fr::fra", "fr", "fr")); |
| @@ -38,6 +58,16 @@ class CrosLanguageOptionsHandlerTest : public testing::Test { |
| return descriptors; |
| } |
| + InputMethodDescriptors CreateInputMethodDescriptors2() { |
| + InputMethodDescriptors descriptors; |
| + descriptors.push_back(GetDesc("xkb:us::eng", "us", "en-US")); |
| + descriptors.push_back(GetDesc("xkb:ch:fr:fra", "ch(fr)", "fr")); |
| + descriptors.push_back(GetDesc("xkb:ch::ger", "ch", "de")); |
| + descriptors.push_back(GetDesc("xkb:it::ita", "it", "it")); |
| + descriptors.push_back(GetDesc("xkb:is::ice", "is", "is")); |
| + return descriptors; |
| + } |
| + |
| private: |
| InputMethodDescriptor GetDesc(const std::string& id, |
| const std::string& raw_layout, |
| @@ -54,7 +84,7 @@ class CrosLanguageOptionsHandlerTest : public testing::Test { |
| } // namespace |
| TEST_F(CrosLanguageOptionsHandlerTest, GetInputMethodList) { |
| - InputMethodDescriptors descriptors = CreateInputMethodDescriptors(); |
| + InputMethodDescriptors descriptors = CreateInputMethodDescriptors1(); |
| scoped_ptr<base::ListValue> list( |
| chromeos::options::CrosLanguageOptionsHandler::GetInputMethodList( |
| descriptors)); |
| @@ -107,7 +137,9 @@ TEST_F(CrosLanguageOptionsHandlerTest, GetInputMethodList) { |
| } |
| TEST_F(CrosLanguageOptionsHandlerTest, GetUILanguageList) { |
| - InputMethodDescriptors descriptors = CreateInputMethodDescriptors(); |
| + // This requires initialized StatisticsProvider. |
| + // (see CrosLanguageOptionsHandlerTest() ) |
| + InputMethodDescriptors descriptors = CreateInputMethodDescriptors1(); |
| scoped_ptr<base::ListValue> list( |
| chromeos::options::CrosLanguageOptionsHandler::GetUILanguageList( |
| descriptors)); |
| @@ -122,3 +154,60 @@ TEST_F(CrosLanguageOptionsHandlerTest, GetUILanguageList) { |
| << "but can't use it as UI language."; |
| } |
| } |
| + |
| +const char kStartupManifest1[] = |
| + "{\n" |
| + " \"version\": \"1.0\",\n" |
| + " \"initial_locale\" : \"fr,en-US,de,is,it\",\n" |
| + " \"initial_timezone\" : \"Europe/Zurich\",\n" |
| + " \"keyboard_layout\" : \"xkb:ch:fr:fra\",\n" |
| + " \"registration_url\" : \"http://www.google.com\",\n" |
| + " \"setup_content\" : {\n" |
| + " \"default\" : {\n" |
| + " \"help_page\" : \"file:///opt/oem/help/en-US/help.html\",\n" |
| + " \"eula_page\" : \"file:///opt/oem/eula/en-US/eula.html\",\n" |
| + " },\n" |
| + " }," |
| + "}"; |
| + |
| +#define EXPECT_LANGUAGE_CODE_AT(i, value) \ |
| + if (list->GetSize() > i) { \ |
| + ASSERT_TRUE(list->GetDictionary(i, &dict)); \ |
| + ASSERT_TRUE(dict->GetString("code", &code)); \ |
| + EXPECT_EQ(value, code) << "Wrong language code at index " << i << "."; \ |
| + } |
| + |
| +TEST_F(CrosLanguageOptionsHandlerTest, GetUILanguageListMulti) { |
| + chromeos::StartupCustomizationDocument::GetInstance()->LoadManifestFromString( |
| + kStartupManifest1); |
| + chromeos::StartupCustomizationDocument::GetInstance()->Init( |
| + chromeos::system::StatisticsProvider::GetInstance()); |
| + |
| + // This requires initialized StatisticsProvider. |
| + // (see CrosLanguageOptionsHandlerTest() ) |
| + InputMethodDescriptors descriptors = CreateInputMethodDescriptors2(); |
| + scoped_ptr<base::ListValue> list( |
| + chromeos::options::CrosLanguageOptionsHandler::GetUILanguageList( |
| + descriptors)); |
| + |
| + base::DictionaryValue* dict; |
| + std::string code; |
| + |
| + for (size_t i = 0; i < list->GetSize(); ++i) { |
| + ASSERT_TRUE(list->GetDictionary(i, &dict)); |
| + ASSERT_TRUE(dict->GetString("code", &code)); |
| + EXPECT_NE("is", code) |
| + << "Icelandic is an example language which has input method " |
| + << "but can't use it as UI language."; |
| + } |
| + |
| + // (4 languages (except islandic) + divider)=5 + all other languages |
| + EXPECT_GT(list->GetSize(), (size_t)5); |
|
Nikita (slow)
2014/01/31 15:47:20
nit: Insert space after (size_t)
Dmitry Polukhin
2014/01/31 17:04:41
Please don't use C-style cast. Use static_cast<siz
Alexander Alekseev
2014/01/31 17:21:00
Done.
Alexander Alekseev
2014/01/31 17:21:00
I've changed it to suffix-style "5u".
|
| + |
| + EXPECT_LANGUAGE_CODE_AT(0, "fr") |
| + EXPECT_LANGUAGE_CODE_AT(1, "en-US") |
| + EXPECT_LANGUAGE_CODE_AT(2, "de") |
| + EXPECT_LANGUAGE_CODE_AT(3, "it") |
| + EXPECT_LANGUAGE_CODE_AT( |
| + 4, chromeos::options::kVENDOR_OTHER_LANGUAGES_LIST_DIVIDER); |
| +} |