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/chromeos/cros_language_options_handler.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h"
9 #include "chrome/browser/chromeos/input_method/input_method_configuration.h"
10 #include "chrome/browser/ui/webui/chromeos/login/l10n_util_test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
16 class CrosLanguageOptionsHandlerTest
: public testing::Test
{
18 CrosLanguageOptionsHandlerTest()
19 : input_manager_(new MockInputMethodManagerWithInputMethods
) {
20 chromeos::input_method::InitializeForTesting(input_manager_
);
23 ~CrosLanguageOptionsHandlerTest() override
{
24 chromeos::input_method::Shutdown();
28 void SetUp() override
{
29 input_manager_
->AddInputMethod("xkb:us::eng", "us", "en-US");
30 input_manager_
->AddInputMethod("xkb:fr::fra", "fr", "fr");
31 input_manager_
->AddInputMethod("xkb:be::fra", "be", "fr");
32 input_manager_
->AddInputMethod("xkb:is::ice", "is", "is");
36 MockInputMethodManagerWithInputMethods
* input_manager_
;
39 TEST_F(CrosLanguageOptionsHandlerTest
, GetInputMethodList
) {
40 scoped_ptr
<base::ListValue
> list(
41 CrosLanguageOptionsHandler::GetInputMethodList());
42 ASSERT_EQ(4U, list
->GetSize());
44 base::DictionaryValue
* entry
= NULL
;
45 base::DictionaryValue
*language_code_set
= NULL
;
46 std::string input_method_id
;
47 std::string display_name
;
48 std::string language_code
;
50 // As shown below, the list should be input method ids should appear in
51 // the same order of the descriptors.
52 ASSERT_TRUE(list
->GetDictionary(0, &entry
));
53 ASSERT_TRUE(entry
->GetString("id", &input_method_id
));
54 ASSERT_TRUE(entry
->GetString("displayName", &display_name
));
55 ASSERT_TRUE(entry
->GetDictionary("languageCodeSet", &language_code_set
));
56 EXPECT_EQ("xkb:us::eng", input_method_id
);
57 // Commented out as it depends on translation in generated_resources.grd
58 // (i.e. makes the test fragile).
59 // EXPECT_EQ("English (USA) keyboard layout", display_name);
60 ASSERT_TRUE(language_code_set
->HasKey("en-US"));
62 ASSERT_TRUE(list
->GetDictionary(1, &entry
));
63 ASSERT_TRUE(entry
->GetString("id", &input_method_id
));
64 ASSERT_TRUE(entry
->GetString("displayName", &display_name
));
65 ASSERT_TRUE(entry
->GetDictionary("languageCodeSet", &language_code_set
));
66 EXPECT_EQ("xkb:fr::fra", input_method_id
);
67 // Commented out. See above.
68 // EXPECT_EQ("French keyboard layout", display_name);
69 ASSERT_TRUE(language_code_set
->HasKey("fr"));
71 ASSERT_TRUE(list
->GetDictionary(2, &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:be::fra", input_method_id
);
76 // Commented out. See above.
77 // EXPECT_EQ("Belgian keyboard layout", display_name);
78 ASSERT_TRUE(language_code_set
->HasKey("fr"));
80 ASSERT_TRUE(list
->GetDictionary(3, &entry
));
81 ASSERT_TRUE(entry
->GetString("id", &input_method_id
));
82 ASSERT_TRUE(entry
->GetString("displayName", &display_name
));
83 ASSERT_TRUE(entry
->GetDictionary("languageCodeSet", &language_code_set
));
84 EXPECT_EQ("xkb:is::ice", input_method_id
);
85 // Commented out. See above.
86 // EXPECT_EQ("Japanese input method (for US keyboard)", display_name);
87 ASSERT_TRUE(language_code_set
->HasKey("is"));
90 } // namespace options
91 } // namespace chromeos