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..0e64621a7237036a0e3a58819bf1ebabd34ea95b 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, |
@@ -53,8 +83,15 @@ class CrosLanguageOptionsHandlerTest : public testing::Test { |
} // namespace |
+void Test__InitStartupCustomizationDocument(const std::string& manifest) { |
+ chromeos::StartupCustomizationDocument::GetInstance()->LoadManifestFromString( |
+ manifest); |
+ chromeos::StartupCustomizationDocument::GetInstance()->Init( |
+ chromeos::system::StatisticsProvider::GetInstance()); |
+} |
+ |
TEST_F(CrosLanguageOptionsHandlerTest, GetInputMethodList) { |
- InputMethodDescriptors descriptors = CreateInputMethodDescriptors(); |
+ InputMethodDescriptors descriptors = CreateInputMethodDescriptors1(); |
scoped_ptr<base::ListValue> list( |
chromeos::options::CrosLanguageOptionsHandler::GetInputMethodList( |
descriptors)); |
@@ -107,7 +144,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 +161,57 @@ 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) { |
+ Test__InitStartupCustomizationDocument(kStartupManifest1); |
+ |
+ // 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(), 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::kVendorOtherLanguagesListDivider); |
+} |