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
|
// 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/test/oobe_base_test.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 OobeBaseTest,
public testing::WithParamInterface<bool> {
public:
LoginUtilsTest() { set_use_webview(GetParam()); }
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:
DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest);
};
#if defined(ENABLE_RLZ)
IN_PROC_BROWSER_TEST_P(LoginUtilsTest, RlzInitialized) {
WaitForSigninScreen();
// 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);
}
}
INSTANTIATE_TEST_CASE_P(LoginUtilsTestSuite, LoginUtilsTest, testing::Bool());
#endif
} // namespace chromeos
|