Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/cros_language_options_handler_unittest.cc

Issue 144363006: Expand VPD initial_locale to a list of locales. Use the expanded VPD initial_locale on the OOBE. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: After-review. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/options/language_options_handler.h" 5 #include "chrome/browser/ui/webui/options/language_options_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/singleton.h"
10 #include "base/message_loop/message_loop.h"
9 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/chromeos/customization_document.h"
10 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" 13 #include "chrome/browser/chromeos/input_method/input_method_configuration.h"
11 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" 14 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h"
12 #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler .h" 15 #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler .h"
13 #include "chromeos/ime/input_method_descriptor.h" 16 #include "chromeos/ime/input_method_descriptor.h"
17 #include "chromeos/system/statistics_provider.h"
14 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
15 19
16 using chromeos::input_method::InputMethodDescriptor; 20 using chromeos::input_method::InputMethodDescriptor;
17 using chromeos::input_method::InputMethodDescriptors; 21 using chromeos::input_method::InputMethodDescriptors;
18 using chromeos::input_method::MockInputMethodManager; 22 using chromeos::input_method::MockInputMethodManager;
19 23
20 namespace { 24 namespace {
21 25
26 class MachineStatisticsInitializer {
27 public:
28 MachineStatisticsInitializer() {
29 base::MessageLoop tmp_loop(base::MessageLoop::TYPE_DEFAULT);
30 chromeos::system::StatisticsProvider::GetInstance()
31 ->StartLoadingMachineStatistics(tmp_loop.message_loop_proxy(), false);
32 tmp_loop.RunUntilIdle();
33 }
34 static MachineStatisticsInitializer* GetInstance();
35 };
36
37 MachineStatisticsInitializer* MachineStatisticsInitializer::GetInstance() {
38 return Singleton<MachineStatisticsInitializer>::get();
39 }
40
22 class CrosLanguageOptionsHandlerTest : public testing::Test { 41 class CrosLanguageOptionsHandlerTest : public testing::Test {
23 public: 42 public:
24 CrosLanguageOptionsHandlerTest() { 43 CrosLanguageOptionsHandlerTest() {
25 chromeos::input_method::InitializeForTesting(new MockInputMethodManager); 44 chromeos::input_method::InitializeForTesting(new MockInputMethodManager);
45 MachineStatisticsInitializer::GetInstance(); // Ignore result
26 } 46 }
27 virtual ~CrosLanguageOptionsHandlerTest() { 47 virtual ~CrosLanguageOptionsHandlerTest() {
28 chromeos::input_method::Shutdown(); 48 chromeos::input_method::Shutdown();
29 } 49 }
30 50
31 protected: 51 protected:
32 InputMethodDescriptors CreateInputMethodDescriptors() { 52 InputMethodDescriptors CreateInputMethodDescriptors1() {
33 InputMethodDescriptors descriptors; 53 InputMethodDescriptors descriptors;
34 descriptors.push_back(GetDesc("xkb:us::eng", "us", "en-US")); 54 descriptors.push_back(GetDesc("xkb:us::eng", "us", "en-US"));
35 descriptors.push_back(GetDesc("xkb:fr::fra", "fr", "fr")); 55 descriptors.push_back(GetDesc("xkb:fr::fra", "fr", "fr"));
36 descriptors.push_back(GetDesc("xkb:be::fra", "be", "fr")); 56 descriptors.push_back(GetDesc("xkb:be::fra", "be", "fr"));
37 descriptors.push_back(GetDesc("xkb:is::ice", "is", "is")); 57 descriptors.push_back(GetDesc("xkb:is::ice", "is", "is"));
38 return descriptors; 58 return descriptors;
39 } 59 }
40 60
61 InputMethodDescriptors CreateInputMethodDescriptors2() {
62 InputMethodDescriptors descriptors;
63 descriptors.push_back(GetDesc("xkb:us::eng", "us", "en-US"));
64 descriptors.push_back(GetDesc("xkb:ch:fr:fra", "ch(fr)", "fr"));
65 descriptors.push_back(GetDesc("xkb:ch::ger", "ch", "de"));
66 descriptors.push_back(GetDesc("xkb:it::ita", "it", "it"));
67 descriptors.push_back(GetDesc("xkb:is::ice", "is", "is"));
68 return descriptors;
69 }
70
41 private: 71 private:
42 InputMethodDescriptor GetDesc(const std::string& id, 72 InputMethodDescriptor GetDesc(const std::string& id,
43 const std::string& raw_layout, 73 const std::string& raw_layout,
44 const std::string& language_code) { 74 const std::string& language_code) {
45 std::vector<std::string> layouts; 75 std::vector<std::string> layouts;
46 layouts.push_back(raw_layout); 76 layouts.push_back(raw_layout);
47 std::vector<std::string> languages; 77 std::vector<std::string> languages;
48 languages.push_back(language_code); 78 languages.push_back(language_code);
49 return InputMethodDescriptor( 79 return InputMethodDescriptor(
50 id, std::string(), layouts, languages, true, GURL(), GURL()); 80 id, std::string(), layouts, languages, true, GURL(), GURL());
51 } 81 }
52 }; 82 };
53 83
54 } // namespace 84 } // namespace
55 85
86 void Test__InitStartupCustomizationDocument(const std::string& manifest) {
87 chromeos::StartupCustomizationDocument::GetInstance()->LoadManifestFromString(
88 manifest);
89 chromeos::StartupCustomizationDocument::GetInstance()->Init(
90 chromeos::system::StatisticsProvider::GetInstance());
91 }
92
56 TEST_F(CrosLanguageOptionsHandlerTest, GetInputMethodList) { 93 TEST_F(CrosLanguageOptionsHandlerTest, GetInputMethodList) {
57 InputMethodDescriptors descriptors = CreateInputMethodDescriptors(); 94 InputMethodDescriptors descriptors = CreateInputMethodDescriptors1();
58 scoped_ptr<base::ListValue> list( 95 scoped_ptr<base::ListValue> list(
59 chromeos::options::CrosLanguageOptionsHandler::GetInputMethodList( 96 chromeos::options::CrosLanguageOptionsHandler::GetInputMethodList(
60 descriptors)); 97 descriptors));
61 ASSERT_EQ(4U, list->GetSize()); 98 ASSERT_EQ(4U, list->GetSize());
62 99
63 base::DictionaryValue* entry = NULL; 100 base::DictionaryValue* entry = NULL;
64 base::DictionaryValue *language_code_set = NULL; 101 base::DictionaryValue *language_code_set = NULL;
65 std::string input_method_id; 102 std::string input_method_id;
66 std::string display_name; 103 std::string display_name;
67 std::string language_code; 104 std::string language_code;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 ASSERT_TRUE(entry->GetString("id", &input_method_id)); 137 ASSERT_TRUE(entry->GetString("id", &input_method_id));
101 ASSERT_TRUE(entry->GetString("displayName", &display_name)); 138 ASSERT_TRUE(entry->GetString("displayName", &display_name));
102 ASSERT_TRUE(entry->GetDictionary("languageCodeSet", &language_code_set)); 139 ASSERT_TRUE(entry->GetDictionary("languageCodeSet", &language_code_set));
103 EXPECT_EQ("xkb:is::ice", input_method_id); 140 EXPECT_EQ("xkb:is::ice", input_method_id);
104 // Commented out. See above. 141 // Commented out. See above.
105 // EXPECT_EQ("Japanese input method (for US keyboard)", display_name); 142 // EXPECT_EQ("Japanese input method (for US keyboard)", display_name);
106 ASSERT_TRUE(language_code_set->HasKey("is")); 143 ASSERT_TRUE(language_code_set->HasKey("is"));
107 } 144 }
108 145
109 TEST_F(CrosLanguageOptionsHandlerTest, GetUILanguageList) { 146 TEST_F(CrosLanguageOptionsHandlerTest, GetUILanguageList) {
110 InputMethodDescriptors descriptors = CreateInputMethodDescriptors(); 147 // This requires initialized StatisticsProvider.
148 // (see CrosLanguageOptionsHandlerTest() )
149 InputMethodDescriptors descriptors = CreateInputMethodDescriptors1();
111 scoped_ptr<base::ListValue> list( 150 scoped_ptr<base::ListValue> list(
112 chromeos::options::CrosLanguageOptionsHandler::GetUILanguageList( 151 chromeos::options::CrosLanguageOptionsHandler::GetUILanguageList(
113 descriptors)); 152 descriptors));
114 153
115 for (size_t i = 0; i < list->GetSize(); ++i) { 154 for (size_t i = 0; i < list->GetSize(); ++i) {
116 base::DictionaryValue* dict; 155 base::DictionaryValue* dict;
117 ASSERT_TRUE(list->GetDictionary(i, &dict)); 156 ASSERT_TRUE(list->GetDictionary(i, &dict));
118 std::string code; 157 std::string code;
119 ASSERT_TRUE(dict->GetString("code", &code)); 158 ASSERT_TRUE(dict->GetString("code", &code));
120 EXPECT_NE("is", code) 159 EXPECT_NE("is", code)
121 << "Icelandic is an example language which has input method " 160 << "Icelandic is an example language which has input method "
122 << "but can't use it as UI language."; 161 << "but can't use it as UI language.";
123 } 162 }
124 } 163 }
164
165 const char kStartupManifest1[] =
166 "{\n"
167 " \"version\": \"1.0\",\n"
168 " \"initial_locale\" : \"fr,en-US,de,is,it\",\n"
169 " \"initial_timezone\" : \"Europe/Zurich\",\n"
170 " \"keyboard_layout\" : \"xkb:ch:fr:fra\",\n"
171 " \"registration_url\" : \"http://www.google.com\",\n"
172 " \"setup_content\" : {\n"
173 " \"default\" : {\n"
174 " \"help_page\" : \"file:///opt/oem/help/en-US/help.html\",\n"
175 " \"eula_page\" : \"file:///opt/oem/eula/en-US/eula.html\",\n"
176 " },\n"
177 " },"
178 "}";
179
180 #define EXPECT_LANGUAGE_CODE_AT(i, value) \
181 if (list->GetSize() > i) { \
182 ASSERT_TRUE(list->GetDictionary(i, &dict)); \
183 ASSERT_TRUE(dict->GetString("code", &code)); \
184 EXPECT_EQ(value, code) << "Wrong language code at index " << i << "."; \
185 }
186
187 TEST_F(CrosLanguageOptionsHandlerTest, GetUILanguageListMulti) {
188 Test__InitStartupCustomizationDocument(kStartupManifest1);
189
190 // This requires initialized StatisticsProvider.
191 // (see CrosLanguageOptionsHandlerTest() )
192 InputMethodDescriptors descriptors = CreateInputMethodDescriptors2();
193 scoped_ptr<base::ListValue> list(
194 chromeos::options::CrosLanguageOptionsHandler::GetUILanguageList(
195 descriptors));
196
197 base::DictionaryValue* dict;
198 std::string code;
199
200 for (size_t i = 0; i < list->GetSize(); ++i) {
201 ASSERT_TRUE(list->GetDictionary(i, &dict));
202 ASSERT_TRUE(dict->GetString("code", &code));
203 EXPECT_NE("is", code)
204 << "Icelandic is an example language which has input method "
205 << "but can't use it as UI language.";
206 }
207
208 // (4 languages (except islandic) + divider)=5 + all other languages
209 EXPECT_GT(list->GetSize(), 5u);
210
211 EXPECT_LANGUAGE_CODE_AT(0, "fr")
212 EXPECT_LANGUAGE_CODE_AT(1, "en-US")
213 EXPECT_LANGUAGE_CODE_AT(2, "de")
214 EXPECT_LANGUAGE_CODE_AT(3, "it")
215 EXPECT_LANGUAGE_CODE_AT(4,
216 chromeos::options::kVendorOtherLanguagesListDivider);
217 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698