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.
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/test/oobe_base_test.h"
15 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
16 #include "chrome/browser/chromeos/login/wizard_controller.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"
30 #if defined(ENABLE_RLZ)
31 #include "components/rlz/rlz_tracker.h"
38 #if defined(ENABLE_RLZ)
39 void GetAccessPointRlzInBackgroundThread(rlz_lib::AccessPoint point
,
40 base::string16
* rlz
) {
41 ASSERT_FALSE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI
));
42 ASSERT_TRUE(rlz::RLZTracker::GetAccessPointRlz(point
, rlz
));
48 class LoginUtilsTest
: public OobeBaseTest
{
53 base::RunLoop().RunUntilIdle();
56 PrefService
* local_state() {
57 return g_browser_process
->local_state();
60 void Login(const std::string
& username
) {
61 content::WindowedNotificationObserver
session_started_observer(
62 chrome::NOTIFICATION_SESSION_STARTED
,
63 content::NotificationService::AllSources());
65 ExistingUserController
* controller
=
66 ExistingUserController::current_controller();
67 ASSERT_TRUE(controller
);
68 WebUILoginDisplay
* login_display
=
69 static_cast<WebUILoginDisplay
*>(controller
->login_display());
70 ASSERT_TRUE(login_display
);
72 login_display
->ShowSigninScreenForCreds(username
, "password");
74 // Wait for the session to start after submitting the credentials. This
75 // will wait until all the background requests are done.
76 session_started_observer
.Wait();
80 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest
);
83 #if defined(ENABLE_RLZ)
84 IN_PROC_BROWSER_TEST_F(LoginUtilsTest
, RlzInitialized
) {
85 WaitForSigninScreen();
87 // No RLZ brand code set initially.
88 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kRLZBrand
));
90 // Wait for blocking RLZ tasks to complete.
93 PrefChangeRegistrar registrar
;
94 registrar
.Init(local_state());
95 registrar
.Add(prefs::kRLZBrand
, loop
.QuitClosure());
100 // RLZ brand code has been set to empty string.
101 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kRLZBrand
));
102 EXPECT_EQ(std::string(), local_state()->GetString(prefs::kRLZBrand
));
104 // RLZ value for homepage access point should have been initialized.
105 // This value must be obtained in a background thread.
108 base::string16 rlz_string
;
109 content::BrowserThread::PostBlockingPoolTaskAndReply(
110 FROM_HERE
, base::Bind(&GetAccessPointRlzInBackgroundThread
,
111 rlz::RLZTracker::ChromeHomePage(), &rlz_string
),
114 EXPECT_EQ(base::string16(), rlz_string
);
119 } // namespace chromeos