OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/task_runner.h" | 8 #include "base/task_runner.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/chromeos/customization_document.h" | 11 #include "chrome/browser/chromeos/customization_document.h" |
12 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 12 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
13 #include "chrome/browser/chromeos/login/login_manager_test.h" | 13 #include "chrome/browser/chromeos/login/login_manager_test.h" |
14 #include "chrome/browser/chromeos/login/login_wizard.h" | 14 #include "chrome/browser/chromeos/login/login_wizard.h" |
15 #include "chrome/browser/chromeos/login/test/js_checker.h" | 15 #include "chrome/browser/chromeos/login/test/js_checker.h" |
16 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 16 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
19 #include "chromeos/ime/extension_ime_util.h" | 19 #include "chromeos/ime/extension_ime_util.h" |
20 #include "chromeos/ime/input_method_manager.h" | 20 #include "chromeos/ime/input_method_manager.h" |
21 #include "chromeos/ime/input_method_whitelist.h" | 21 #include "chromeos/ime/input_method_whitelist.h" |
| 22 #include "chromeos/system/fake_statistics_provider.h" |
22 #include "chromeos/system/statistics_provider.h" | 23 #include "chromeos/system/statistics_provider.h" |
23 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
25 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
26 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
27 | 28 |
28 namespace base { | 29 namespace base { |
29 class TaskRunner; | 30 class TaskRunner; |
30 } | 31 } |
31 | 32 |
32 namespace chromeos { | 33 namespace chromeos { |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
36 // OOBE constants. | 37 // OOBE constants. |
37 const char* kLocaleSelect = "language-select"; | 38 const char* kLocaleSelect = "language-select"; |
38 const char* kKeyboardSelect = "keyboard-select"; | 39 const char* kKeyboardSelect = "keyboard-select"; |
39 | 40 |
40 const char* kUSLayout = "xkb:us::eng"; | 41 const char* kUSLayout = "xkb:us::eng"; |
41 | 42 |
42 } | 43 } |
43 | 44 |
44 namespace system { | |
45 | |
46 // Custom StatisticsProvider that will return each set of region settings. | |
47 class FakeStatisticsProvider : public StatisticsProvider { | |
48 public: | |
49 virtual ~FakeStatisticsProvider() {} | |
50 | |
51 void set_locale(const std::string& locale) { | |
52 initial_locale_ = locale; | |
53 } | |
54 | |
55 void set_keyboard_layout(const std::string& keyboard_layout) { | |
56 keyboard_layout_ = keyboard_layout; | |
57 } | |
58 | |
59 private: | |
60 // StatisticsProvider overrides. | |
61 virtual void StartLoadingMachineStatistics( | |
62 const scoped_refptr<base::TaskRunner>& file_task_runner, | |
63 bool load_oem_manifest) override { | |
64 } | |
65 | |
66 // Populates the named machine statistic for initial_locale and | |
67 // keyboard_layout only. | |
68 virtual bool GetMachineStatistic(const std::string& name, | |
69 std::string* result) override { | |
70 if (name == "initial_locale") | |
71 *result = initial_locale_; | |
72 else if (name == "keyboard_layout") | |
73 *result = keyboard_layout_; | |
74 else | |
75 return false; | |
76 | |
77 return true; | |
78 } | |
79 | |
80 virtual bool GetMachineFlag(const std::string& name, bool* result) override { | |
81 return false; | |
82 } | |
83 | |
84 virtual void Shutdown() override { | |
85 } | |
86 | |
87 std::string initial_locale_; | |
88 std::string keyboard_layout_; | |
89 }; | |
90 | |
91 } // namespace system | |
92 | |
93 struct LocalizationTestParams { | 45 struct LocalizationTestParams { |
94 const char* initial_locale; | 46 const char* initial_locale; |
95 const char* keyboard_layout; | 47 const char* keyboard_layout; |
96 const char* expected_locale; | 48 const char* expected_locale; |
97 const char* expected_keyboard_layout; | 49 const char* expected_keyboard_layout; |
98 const char* expected_keyboard_select_control; | 50 const char* expected_keyboard_select_control; |
99 } const oobe_localization_test_parameters[] = { | 51 } const oobe_localization_test_parameters[] = { |
100 // ------------------ Non-Latin setup | 52 // ------------------ Non-Latin setup |
101 // For a non-Latin keyboard layout like Russian, we expect to see the US | 53 // For a non-Latin keyboard layout like Russian, we expect to see the US |
102 // keyboard. | 54 // keyboard. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 "en-AU", | 107 "en-AU", |
156 "xkb:us::eng", | 108 "xkb:us::eng", |
157 "xkb:us::eng,[xkb:gb:extd:eng,xkb:gb:dvorak:eng]"}, | 109 "xkb:us::eng,[xkb:gb:extd:eng,xkb:gb:dvorak:eng]"}, |
158 }; | 110 }; |
159 | 111 |
160 class OobeLocalizationTest | 112 class OobeLocalizationTest |
161 : public LoginManagerTest, | 113 : public LoginManagerTest, |
162 public testing::WithParamInterface<const LocalizationTestParams*> { | 114 public testing::WithParamInterface<const LocalizationTestParams*> { |
163 public: | 115 public: |
164 OobeLocalizationTest(); | 116 OobeLocalizationTest(); |
165 virtual ~OobeLocalizationTest(); | |
166 | 117 |
167 // Verifies that the comma-separated |values| corresponds with the first | 118 // Verifies that the comma-separated |values| corresponds with the first |
168 // values in |select_id|, optionally checking for an options group label after | 119 // values in |select_id|, optionally checking for an options group label after |
169 // the first set of options. | 120 // the first set of options. |
170 bool VerifyInitialOptions(const char* select_id, | 121 bool VerifyInitialOptions(const char* select_id, |
171 const char* values, | 122 const char* values, |
172 bool check_separator); | 123 bool check_separator); |
173 | 124 |
174 // Verifies that |value| exists in |select_id|. | 125 // Verifies that |value| exists in |select_id|. |
175 bool VerifyOptionExists(const char* select_id, const char* value); | 126 bool VerifyOptionExists(const char* select_id, const char* value); |
(...skipping 13 matching lines...) Expand all Loading... |
189 chromeos::OobeUI* oobe_ui = host->GetOobeUI(); | 140 chromeos::OobeUI* oobe_ui = host->GetOobeUI(); |
190 if (!oobe_ui) | 141 if (!oobe_ui) |
191 return; | 142 return; |
192 base::RunLoop run_loop; | 143 base::RunLoop run_loop; |
193 const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop.QuitClosure()); | 144 const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop.QuitClosure()); |
194 if (!oobe_ui_ready) | 145 if (!oobe_ui_ready) |
195 run_loop.Run(); | 146 run_loop.Run(); |
196 } | 147 } |
197 | 148 |
198 private: | 149 private: |
199 scoped_ptr<system::FakeStatisticsProvider> statistics_provider_; | 150 system::ScopedFakeStatisticsProvider fake_statistics_provider_; |
200 test::JSChecker checker; | 151 test::JSChecker checker; |
201 | 152 |
202 DISALLOW_COPY_AND_ASSIGN(OobeLocalizationTest); | 153 DISALLOW_COPY_AND_ASSIGN(OobeLocalizationTest); |
203 }; | 154 }; |
204 | 155 |
205 OobeLocalizationTest::OobeLocalizationTest() : LoginManagerTest(false) { | 156 OobeLocalizationTest::OobeLocalizationTest() : LoginManagerTest(false) { |
206 statistics_provider_.reset(new system::FakeStatisticsProvider()); | 157 fake_statistics_provider_.SetMachineStatistic("initial_locale", |
207 // Set the instance returned by GetInstance() for testing. | 158 GetParam()->initial_locale); |
208 system::StatisticsProvider::SetTestProvider(statistics_provider_.get()); | 159 fake_statistics_provider_.SetMachineStatistic("keyboard_layout", |
209 | 160 GetParam()->keyboard_layout); |
210 statistics_provider_->set_locale(GetParam()->initial_locale); | |
211 statistics_provider_->set_keyboard_layout(GetParam()->keyboard_layout); | |
212 } | |
213 | |
214 OobeLocalizationTest::~OobeLocalizationTest() { | |
215 system::StatisticsProvider::SetTestProvider(NULL); | |
216 } | 161 } |
217 | 162 |
218 bool OobeLocalizationTest::VerifyInitialOptions(const char* select_id, | 163 bool OobeLocalizationTest::VerifyInitialOptions(const char* select_id, |
219 const char* values, | 164 const char* values, |
220 bool check_separator) { | 165 bool check_separator) { |
221 const std::string expression = base::StringPrintf( | 166 const std::string expression = base::StringPrintf( |
222 "(function () {\n" | 167 "(function () {\n" |
223 " var select = document.querySelector('#%s');\n" | 168 " var select = document.querySelector('#%s');\n" |
224 " if (!select)\n" | 169 " if (!select)\n" |
225 " return false;\n" | 170 " return false;\n" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 RunLocalizationTest(); | 347 RunLocalizationTest(); |
403 } | 348 } |
404 | 349 |
405 INSTANTIATE_TEST_CASE_P( | 350 INSTANTIATE_TEST_CASE_P( |
406 StructSequence, | 351 StructSequence, |
407 OobeLocalizationTest, | 352 OobeLocalizationTest, |
408 testing::Range(&oobe_localization_test_parameters[0], | 353 testing::Range(&oobe_localization_test_parameters[0], |
409 &oobe_localization_test_parameters[arraysize( | 354 &oobe_localization_test_parameters[arraysize( |
410 oobe_localization_test_parameters)])); | 355 oobe_localization_test_parameters)])); |
411 } // namespace chromeos | 356 } // namespace chromeos |
OLD | NEW |