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

Side by Side Diff: chrome/browser/chromeos/login/oobe_localization_browsertest.cc

Issue 153473004: OOBE localization browser test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use selected configs 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/customization_document.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/message_loop/message_loop.h"
6 #include "base/prefs/pref_service.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/task_runner.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/chromeos/customization_document.h"
12 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
13 #include "chrome/browser/chromeos/login/login_wizard.h"
14 #include "chrome/common/pref_names.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chromeos/system/statistics_provider.h"
17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/test/browser_test_utils.h"
20 #include "content/public/test/test_utils.h"
21
22 namespace base {
23 class TaskRunner;
24 }
25
26 namespace chromeos {
27 namespace system {
28
29 // Custom StatisticsProvider that will return each set of region settings.
30 class FakeStatisticsProvider : public StatisticsProvider {
achuithb 2014/02/10 22:19:07 Do you mind not inlining the functions of this cla
michaelpg 2014/02/10 23:38:26 This is what I see in the majority of tests. There
achuithb 2014/02/11 00:02:19 Yup, that's the thread. I guess it kind of went in
31 public:
achuithb 2014/02/10 22:19:07 protected?
michaelpg 2014/02/10 23:38:26 why? the browser test and the customization docume
achuithb 2014/02/11 00:02:19 I didn't realize the base class had a protected dt
32 virtual ~FakeStatisticsProvider() {}
33
34 virtual void StartLoadingMachineStatistics(
achuithb 2014/02/10 22:19:07 Shouldn't the rest of these be private?
michaelpg 2014/02/10 23:38:26 The point of this fake StatisticsProvider is to be
achuithb 2014/02/11 00:02:19 It's passed around and used via the base class poi
michaelpg 2014/02/11 00:45:31 Oh right, my mistake, private would work. It would
35 const scoped_refptr<base::TaskRunner>& file_task_runner,
36 bool load_oem_manifest) OVERRIDE {
37 }
38
39 // Populates the named machine statistic.
achuithb 2014/02/10 22:19:07 Let's make this comment more verbose and say that
michaelpg 2014/02/10 23:38:26 Done.
40 virtual bool GetMachineStatistic(const std::string& name,
41 std::string* result) OVERRIDE {
42 if (name == "initial_locale")
43 *result = initial_locale_;
44 else if (name == "keyboard_layout")
45 *result = keyboard_layout_;
46 else
47 return false;
48
49 return true;
50 }
51
52 virtual bool GetMachineFlag(const std::string& name, bool* result) OVERRIDE {
53 return false;
54 }
55
56 virtual void Shutdown() OVERRIDE {
57 }
58
59 void set_locale(const std::string& locale) {
60 initial_locale_ = locale;
61 }
62
63 void set_keyboard_layout(const std::string& keyboard_layout) {
64 keyboard_layout_ = keyboard_layout;
65 }
66
67 private:
68 std::string initial_locale_;
69 std::string keyboard_layout_;
70 };
71
72 } // namespace system
73
74 namespace {
achuithb 2014/02/10 22:19:07 newline after this I believe? I think it's better
michaelpg 2014/02/10 23:38:26 Done.
75 // OOBE constants.
76 const char* kLocaleSelect = "language-select";
77 const char* kKeyboardSelect = "keyboard-select";
78 const char* kUSLayout = "xkb:us::eng";
achuithb 2014/02/10 22:19:07 newline after this I believe?
michaelpg 2014/02/10 23:38:26 Done.
79 }
80
81 class OobeLocalizationTest : public InProcessBrowserTest {
achuithb 2014/02/10 22:19:07 Please de-inline this class too.
michaelpg 2014/02/10 23:38:26 Done.
82 public:
83 OobeLocalizationTest() {
84 statistics_provider_.reset(new system::FakeStatisticsProvider());
85 // Set the instance returned by GetInstance() for testing.
86 system::StatisticsProvider::SetTestProvider(statistics_provider_.get());
87 }
88
89 void JsExpect(const std::string& expression) {
achuithb 2014/02/10 22:19:07 I believe it's better for the caller of this funct
michaelpg 2014/02/10 23:38:26 Done.
90 bool result;
91 chromeos::LoginDisplayHostImpl* display_host =
92 static_cast<chromeos::LoginDisplayHostImpl*>(
93 chromeos::LoginDisplayHostImpl::default_host());
94 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
95 display_host->GetOobeUI()->web_ui()->GetWebContents(),
96 "window.domAutomationController.send(!!(" + expression + "));",
97 &result));
98 ASSERT_TRUE(result) << expression;
99 }
100
101 void VerifySelectedOption(const char* select_id, const char* value) {
102 JsExpect(base::StringPrintf(
103 "(function () {\n"
104 " var select = document.querySelector('#%s');\n"
105 " if (!select)\n"
106 " return false;\n"
107 " return select.options[select.selectedIndex].value == '%s';\n"
108 "})()", select_id, value));
109 }
110
111 void VerifyOptionExists(const char* select_id, const char* value) {
112 JsExpect(base::StringPrintf(
113 "(function () {\n"
114 " var select = document.querySelector('#%s');\n"
115 " if (!select)\n"
116 " return false;\n"
117 " for (var i = 0; i < select.options.length; i++) {\n"
118 " if (select.options[i].value == '%s')\n"
119 " return true;\n"
120 " }\n"
121 " return false;\n"
122 "})()", select_id, value));
123 }
124
125 protected:
126 // Runs the test for the given locale and keyboard layout.
127 void RunLocalizationTest(const std::string& initial_locale,
128 const std::string& keyboard_layout,
129 const std::string& expected_locale,
130 const std::string& expected_keyboard_layout) {
131 statistics_provider()->set_locale(initial_locale);
132 statistics_provider()->set_keyboard_layout(keyboard_layout);
133
134 // Initialize StartupCustomizationDocument with fake statistics provider
135 StartupCustomizationDocument::GetInstance()->Init(statistics_provider());
136
137 // Bring up the OOBE network screen
138 chromeos::ShowLoginWizard(chromeos::WizardController::kNetworkScreenName);
139 content::WindowedNotificationObserver(
140 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
141 content::NotificationService::AllSources()).Wait();
142
143 VerifySelectedOption(kLocaleSelect, expected_locale.c_str());
144 VerifySelectedOption(kKeyboardSelect, expected_keyboard_layout.c_str());
145
146 // Make sure we have a fallback keyboard.
147 VerifyOptionExists(kKeyboardSelect, kUSLayout);
148
149 // Shut down the display host.
150 chromeos::LoginDisplayHostImpl::default_host()->Finalize();
151 base::MessageLoopForUI::current()->RunUntilIdle();
152
153 // Clear the locale pref so the statistics provider is pinged next time.
154 g_browser_process->local_state()->SetString(prefs::kApplicationLocale,
155 std::string());
156 }
157
158 system::FakeStatisticsProvider* statistics_provider() {
achuithb 2014/02/10 22:19:07 This function seems unnecessary - why not just use
michaelpg 2014/02/10 23:38:26 Done (this was vestigial, thanks for catching)
159 return statistics_provider_.get();
160 }
161
162 private:
163 scoped_ptr<system::FakeStatisticsProvider> statistics_provider_;
achuithb 2014/02/10 22:19:07 Should this be StatisticsProvider instead of FakeS
michaelpg 2014/02/10 23:38:26 It can't be -- StatisticsProvider::~StatisticsProv
achuithb 2014/02/11 00:02:19 Ok
164
165 DISALLOW_COPY_AND_ASSIGN(OobeLocalizationTest);
166 };
167
168 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreen) {
169 // For a non-Latin keyboard layout like Russian, we expect to see the US
170 // keyboard.
171 RunLocalizationTest("ru", "xkb:ru::rus",
achuithb 2014/02/10 22:19:07 If there's a danger of running into the time limit
172 "ru", kUSLayout);
173
174 // IMEs do not load at OOBE, so we just expect to see the (Latin) Japanese
175 // keyboard.
176 RunLocalizationTest("ja", "xkb:jp::jpn",
177 "ja", "xkb:jp::jpn");
178
179 // We don't use the Icelandic locale but the Icelandic keyboard layout
180 // should still be selected when specified as the default.
181 RunLocalizationTest("en-US", "xkb:is::ice",
182 "en-US", "xkb:is::ice");
183
184 // French Swiss keyboard.
185 RunLocalizationTest("fr", "xkb:ch:fr:fra",
186 "fr", "xkb:ch:fr:fra");
187
188 // German Swiss keyboard.
189 RunLocalizationTest("de", "xkb:ch::ger",
190 "de", "xkb:ch::ger");
191 }
192
193 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/customization_document.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698