ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / login / login_utils_browsertest.cc
blob09eb71e7ae31eb4a59facd9f803b29e6a0394c96
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 <string>
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/prefs/pref_service.h"
10 #include "base/run_loop.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/chromeos/login/existing_user_controller.h"
14 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
15 #include "chrome/browser/chromeos/login/wizard_controller.h"
16 #include "chrome/browser/rlz/rlz.h"
17 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/pref_names.h"
20 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chromeos/chromeos_switches.h"
22 #include "content/public/browser/notification_service.h"
23 #include "content/public/test/test_utils.h"
24 #include "google_apis/gaia/fake_gaia.h"
25 #include "google_apis/gaia/gaia_switches.h"
26 #include "google_apis/gaia/gaia_urls.h"
27 #include "net/test/embedded_test_server/embedded_test_server.h"
28 #include "net/test/embedded_test_server/http_response.h"
29 #include "testing/gtest/include/gtest/gtest.h"
31 namespace chromeos {
33 namespace {
35 #if defined(ENABLE_RLZ)
36 void GetAccessPointRlzInBackgroundThread(rlz_lib::AccessPoint point,
37 base::string16* rlz) {
38 ASSERT_FALSE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
39 ASSERT_TRUE(RLZTracker::GetAccessPointRlz(point, rlz));
41 #endif
43 } // namespace
45 class LoginUtilsTest : public InProcessBrowserTest {
46 public:
47 LoginUtilsTest() {}
49 void SetUpCommandLine(base::CommandLine* command_line) override {
50 // Initialize the test server early, so that we can use its base url for
51 // the command line flags.
52 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
54 // Use the login manager screens and the gaia auth extension.
55 command_line->AppendSwitch(switches::kLoginManager);
56 command_line->AppendSwitch(switches::kForceLoginManagerInTests);
57 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
58 command_line->AppendSwitchASCII(::switches::kAuthExtensionPath,
59 "gaia_auth");
61 // Redirect requests to gaia and the policy server to the test server.
62 command_line->AppendSwitchASCII(::switches::kGaiaUrl,
63 embedded_test_server()->base_url().spec());
64 command_line->AppendSwitchASCII(::switches::kLsoUrl,
65 embedded_test_server()->base_url().spec());
68 void SetUpOnMainThread() override {
69 fake_gaia_.Initialize();
70 embedded_test_server()->RegisterRequestHandler(
71 base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_)));
74 void TearDownOnMainThread() override {
75 RunUntilIdle();
76 EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete());
79 void RunUntilIdle() {
80 base::RunLoop().RunUntilIdle();
83 PrefService* local_state() {
84 return g_browser_process->local_state();
87 void Login(const std::string& username) {
88 content::WindowedNotificationObserver session_started_observer(
89 chrome::NOTIFICATION_SESSION_STARTED,
90 content::NotificationService::AllSources());
92 ExistingUserController* controller =
93 ExistingUserController::current_controller();
94 ASSERT_TRUE(controller);
95 WebUILoginDisplay* login_display =
96 static_cast<WebUILoginDisplay*>(controller->login_display());
97 ASSERT_TRUE(login_display);
99 login_display->ShowSigninScreenForCreds(username, "password");
101 // Wait for the session to start after submitting the credentials. This
102 // will wait until all the background requests are done.
103 session_started_observer.Wait();
106 private:
107 FakeGaia fake_gaia_;
109 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest);
112 #if defined(ENABLE_RLZ)
113 IN_PROC_BROWSER_TEST_F(LoginUtilsTest, RlzInitialized) {
114 // Skip to the signin screen.
115 WizardController::SkipPostLoginScreensForTesting();
116 WizardController* wizard_controller = WizardController::default_controller();
117 ASSERT_TRUE(wizard_controller);
118 wizard_controller->SkipToLoginForTesting(LoginScreenContext());
120 content::WindowedNotificationObserver(
121 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
122 content::NotificationService::AllSources()).Wait();
123 RunUntilIdle();
125 // No RLZ brand code set initially.
126 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kRLZBrand));
128 // Wait for blocking RLZ tasks to complete.
130 base::RunLoop loop;
131 PrefChangeRegistrar registrar;
132 registrar.Init(local_state());
133 registrar.Add(prefs::kRLZBrand, loop.QuitClosure());
134 Login("username");
135 loop.Run();
138 // RLZ brand code has been set to empty string.
139 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kRLZBrand));
140 EXPECT_EQ(std::string(), local_state()->GetString(prefs::kRLZBrand));
142 // RLZ value for homepage access point should have been initialized.
143 // This value must be obtained in a background thread.
145 base::RunLoop loop;
146 base::string16 rlz_string;
147 content::BrowserThread::PostBlockingPoolTaskAndReply(
148 FROM_HERE,
149 base::Bind(&GetAccessPointRlzInBackgroundThread,
150 RLZTracker::ChromeHomePage(),
151 &rlz_string),
152 loop.QuitClosure());
153 loop.Run();
154 EXPECT_EQ(base::string16(), rlz_string);
157 #endif
159 } // namespace chromeos