Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / chromeos / cros_language_options_handler_unittest.cc
blob3173a88b87948eae8848df9f1aaf151379251a4a
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/options/language_options_handler.h"
7 #include <string>
9 #include "base/values.h"
10 #include "chrome/browser/chromeos/input_method/input_method_configuration.h"
11 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h"
12 #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.h"
13 #include "chromeos/ime/input_method_descriptor.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 using chromeos::input_method::InputMethodDescriptor;
17 using chromeos::input_method::InputMethodDescriptors;
18 using chromeos::input_method::MockInputMethodManager;
20 namespace {
22 class CrosLanguageOptionsHandlerTest : public testing::Test {
23 public:
24 CrosLanguageOptionsHandlerTest() {
25 chromeos::input_method::InitializeForTesting(new MockInputMethodManager);
27 virtual ~CrosLanguageOptionsHandlerTest() {
28 chromeos::input_method::Shutdown();
31 protected:
32 InputMethodDescriptors CreateInputMethodDescriptors() {
33 InputMethodDescriptors descriptors;
34 descriptors.push_back(GetDesc("xkb:us::eng", "us", "en-US"));
35 descriptors.push_back(GetDesc("xkb:fr::fra", "fr", "fr"));
36 descriptors.push_back(GetDesc("xkb:be::fra", "be", "fr"));
37 descriptors.push_back(GetDesc("xkb:is::ice", "is", "is"));
38 return descriptors;
41 private:
42 InputMethodDescriptor GetDesc(const std::string& id,
43 const std::string& raw_layout,
44 const std::string& language_code) {
45 std::vector<std::string> layouts;
46 layouts.push_back(raw_layout);
47 std::vector<std::string> languages;
48 languages.push_back(language_code);
49 return InputMethodDescriptor(
50 id, std::string(), layouts, languages, true, GURL(), GURL());
54 } // namespace
56 TEST_F(CrosLanguageOptionsHandlerTest, GetInputMethodList) {
57 InputMethodDescriptors descriptors = CreateInputMethodDescriptors();
58 scoped_ptr<base::ListValue> list(
59 chromeos::options::CrosLanguageOptionsHandler::GetInputMethodList(
60 descriptors));
61 ASSERT_EQ(4U, list->GetSize());
63 base::DictionaryValue* entry = NULL;
64 base::DictionaryValue *language_code_set = NULL;
65 std::string input_method_id;
66 std::string display_name;
67 std::string language_code;
69 // As shown below, the list should be input method ids should appear in
70 // the same order of the descriptors.
71 ASSERT_TRUE(list->GetDictionary(0, &entry));
72 ASSERT_TRUE(entry->GetString("id", &input_method_id));
73 ASSERT_TRUE(entry->GetString("displayName", &display_name));
74 ASSERT_TRUE(entry->GetDictionary("languageCodeSet", &language_code_set));
75 EXPECT_EQ("xkb:us::eng", input_method_id);
76 // Commented out as it depends on translation in generated_resources.grd
77 // (i.e. makes the test fragile).
78 // EXPECT_EQ("English (USA) keyboard layout", display_name);
79 ASSERT_TRUE(language_code_set->HasKey("en-US"));
81 ASSERT_TRUE(list->GetDictionary(1, &entry));
82 ASSERT_TRUE(entry->GetString("id", &input_method_id));
83 ASSERT_TRUE(entry->GetString("displayName", &display_name));
84 ASSERT_TRUE(entry->GetDictionary("languageCodeSet", &language_code_set));
85 EXPECT_EQ("xkb:fr::fra", input_method_id);
86 // Commented out. See above.
87 // EXPECT_EQ("French keyboard layout", display_name);
88 ASSERT_TRUE(language_code_set->HasKey("fr"));
90 ASSERT_TRUE(list->GetDictionary(2, &entry));
91 ASSERT_TRUE(entry->GetString("id", &input_method_id));
92 ASSERT_TRUE(entry->GetString("displayName", &display_name));
93 ASSERT_TRUE(entry->GetDictionary("languageCodeSet", &language_code_set));
94 EXPECT_EQ("xkb:be::fra", input_method_id);
95 // Commented out. See above.
96 // EXPECT_EQ("Belgian keyboard layout", display_name);
97 ASSERT_TRUE(language_code_set->HasKey("fr"));
99 ASSERT_TRUE(list->GetDictionary(3, &entry));
100 ASSERT_TRUE(entry->GetString("id", &input_method_id));
101 ASSERT_TRUE(entry->GetString("displayName", &display_name));
102 ASSERT_TRUE(entry->GetDictionary("languageCodeSet", &language_code_set));
103 EXPECT_EQ("xkb:is::ice", input_method_id);
104 // Commented out. See above.
105 // EXPECT_EQ("Japanese input method (for US keyboard)", display_name);
106 ASSERT_TRUE(language_code_set->HasKey("is"));
109 TEST_F(CrosLanguageOptionsHandlerTest, GetUILanguageList) {
110 InputMethodDescriptors descriptors = CreateInputMethodDescriptors();
111 scoped_ptr<base::ListValue> list(
112 chromeos::options::CrosLanguageOptionsHandler::GetUILanguageList(
113 descriptors));
115 for (size_t i = 0; i < list->GetSize(); ++i) {
116 base::DictionaryValue* dict;
117 ASSERT_TRUE(list->GetDictionary(i, &dict));
118 std::string code;
119 ASSERT_TRUE(dict->GetString("code", &code));
120 EXPECT_NE("is", code)
121 << "Icelandic is an example language which has input method "
122 << "but can't use it as UI language.";