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"
29 #include "testing/gtest/include/gtest/gtest.h"
31 #if defined(ENABLE_RLZ)
32 #include "components/rlz/rlz_tracker.h"
39 #if defined(ENABLE_RLZ)
40 void GetAccessPointRlzInBackgroundThread(rlz_lib::AccessPoint point
,
41 base::string16
* rlz
) {
42 ASSERT_FALSE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI
));
43 ASSERT_TRUE(rlz::RLZTracker::GetAccessPointRlz(point
, rlz
));
49 class LoginUtilsTest
: public OobeBaseTest
,
50 public testing::WithParamInterface
<bool> {
52 LoginUtilsTest() { set_use_webview(GetParam()); }
55 base::RunLoop().RunUntilIdle();
58 PrefService
* local_state() {
59 return g_browser_process
->local_state();
62 void Login(const std::string
& username
) {
63 content::WindowedNotificationObserver
session_started_observer(
64 chrome::NOTIFICATION_SESSION_STARTED
,
65 content::NotificationService::AllSources());
67 ExistingUserController
* controller
=
68 ExistingUserController::current_controller();
69 ASSERT_TRUE(controller
);
70 WebUILoginDisplay
* login_display
=
71 static_cast<WebUILoginDisplay
*>(controller
->login_display());
72 ASSERT_TRUE(login_display
);
74 login_display
->ShowSigninScreenForCreds(username
, "password");
76 // Wait for the session to start after submitting the credentials. This
77 // will wait until all the background requests are done.
78 session_started_observer
.Wait();
82 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest
);
85 #if defined(ENABLE_RLZ)
86 IN_PROC_BROWSER_TEST_P(LoginUtilsTest
, RlzInitialized
) {
87 WaitForSigninScreen();
89 // No RLZ brand code set initially.
90 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kRLZBrand
));
92 // Wait for blocking RLZ tasks to complete.
95 PrefChangeRegistrar registrar
;
96 registrar
.Init(local_state());
97 registrar
.Add(prefs::kRLZBrand
, loop
.QuitClosure());
102 // RLZ brand code has been set to empty string.
103 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kRLZBrand
));
104 EXPECT_EQ(std::string(), local_state()->GetString(prefs::kRLZBrand
));
106 // RLZ value for homepage access point should have been initialized.
107 // This value must be obtained in a background thread.
110 base::string16 rlz_string
;
111 content::BrowserThread::PostBlockingPoolTaskAndReply(
112 FROM_HERE
, base::Bind(&GetAccessPointRlzInBackgroundThread
,
113 rlz::RLZTracker::ChromeHomePage(), &rlz_string
),
116 EXPECT_EQ(base::string16(), rlz_string
);
120 INSTANTIATE_TEST_CASE_P(LoginUtilsTestSuite
, LoginUtilsTest
, testing::Bool());
124 } // namespace chromeos