1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/prefs/pref_service.h"
#include "base/run_loop.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/existing_user_controller.h"
#include "chrome/browser/chromeos/login/ui/webui_login_display.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/rlz/rlz.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chromeos/chromeos_switches.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"
#include "google_apis/gaia/fake_gaia.h"
#include "google_apis/gaia/gaia_switches.h"
#include "google_apis/gaia/gaia_urls.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_response.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace {
#if defined(ENABLE_RLZ)
void GetAccessPointRlzInBackgroundThread(rlz_lib::AccessPoint point,
base::string16* rlz) {
ASSERT_FALSE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
ASSERT_TRUE(RLZTracker::GetAccessPointRlz(point, rlz));
}
#endif
} // namespace
class LoginUtilsTest : public InProcessBrowserTest {
public:
LoginUtilsTest() {}
virtual void SetUpCommandLine(CommandLine* command_line) override {
// Initialize the test server early, so that we can use its base url for
// the command line flags.
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
// Use the login manager screens and the gaia auth extension.
command_line->AppendSwitch(switches::kLoginManager);
command_line->AppendSwitch(switches::kForceLoginManagerInTests);
command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
command_line->AppendSwitchASCII(::switches::kAuthExtensionPath,
"gaia_auth");
// Redirect requests to gaia and the policy server to the test server.
command_line->AppendSwitchASCII(::switches::kGaiaUrl,
embedded_test_server()->base_url().spec());
command_line->AppendSwitchASCII(::switches::kLsoUrl,
embedded_test_server()->base_url().spec());
}
virtual void SetUpOnMainThread() override {
fake_gaia_.Initialize();
embedded_test_server()->RegisterRequestHandler(
base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_)));
}
virtual void TearDownOnMainThread() override {
RunUntilIdle();
EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete());
}
void RunUntilIdle() {
base::RunLoop().RunUntilIdle();
}
PrefService* local_state() {
return g_browser_process->local_state();
}
void Login(const std::string& username) {
content::WindowedNotificationObserver session_started_observer(
chrome::NOTIFICATION_SESSION_STARTED,
content::NotificationService::AllSources());
ExistingUserController* controller =
ExistingUserController::current_controller();
ASSERT_TRUE(controller);
WebUILoginDisplay* login_display =
static_cast<WebUILoginDisplay*>(controller->login_display());
ASSERT_TRUE(login_display);
login_display->ShowSigninScreenForCreds(username, "password");
// Wait for the session to start after submitting the credentials. This
// will wait until all the background requests are done.
session_started_observer.Wait();
}
private:
FakeGaia fake_gaia_;
DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest);
};
#if defined(ENABLE_RLZ)
IN_PROC_BROWSER_TEST_F(LoginUtilsTest, RlzInitialized) {
// Skip to the signin screen.
WizardController::SkipPostLoginScreensForTesting();
WizardController* wizard_controller = WizardController::default_controller();
ASSERT_TRUE(wizard_controller);
wizard_controller->SkipToLoginForTesting(LoginScreenContext());
content::WindowedNotificationObserver(
chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
content::NotificationService::AllSources()).Wait();
RunUntilIdle();
// No RLZ brand code set initially.
EXPECT_FALSE(local_state()->HasPrefPath(prefs::kRLZBrand));
// Wait for blocking RLZ tasks to complete.
{
base::RunLoop loop;
PrefChangeRegistrar registrar;
registrar.Init(local_state());
registrar.Add(prefs::kRLZBrand, loop.QuitClosure());
Login("username");
loop.Run();
}
// RLZ brand code has been set to empty string.
EXPECT_TRUE(local_state()->HasPrefPath(prefs::kRLZBrand));
EXPECT_EQ(std::string(), local_state()->GetString(prefs::kRLZBrand));
// RLZ value for homepage access point should have been initialized.
// This value must be obtained in a background thread.
{
base::RunLoop loop;
base::string16 rlz_string;
content::BrowserThread::PostBlockingPoolTaskAndReply(
FROM_HERE,
base::Bind(&GetAccessPointRlzInBackgroundThread,
RLZTracker::ChromeHomePage(),
&rlz_string),
loop.QuitClosure());
loop.Run();
EXPECT_EQ(base::string16(), rlz_string);
}
}
#endif
} // namespace chromeos
|