1 // Copyright 2015 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 "chrome/browser/chromeos/policy/login_policy_test_base.h"
7 #include "base/values.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
10 #include "chrome/browser/chromeos/login/wizard_controller.h"
11 #include "chrome/browser/chromeos/policy/user_policy_test_helper.h"
12 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
13 #include "content/public/browser/notification_service.h"
14 #include "content/public/test/test_utils.h"
15 #include "google_apis/gaia/fake_gaia.h"
16 #include "google_apis/gaia/gaia_constants.h"
17 #include "google_apis/gaia/gaia_urls.h"
18 #include "testing/gtest/include/gtest/gtest.h"
24 const char kTestAuthCode
[] = "fake-auth-code";
25 const char kTestGaiaUberToken
[] = "fake-uber-token";
26 const char kTestAuthLoginAccessToken
[] = "fake-access-token";
27 const char kTestRefreshToken
[] = "fake-refresh-token";
28 const char kTestAuthSIDCookie
[] = "fake-auth-SID-cookie";
29 const char kTestAuthLSIDCookie
[] = "fake-auth-LSID-cookie";
30 const char kTestSessionSIDCookie
[] = "fake-session-SID-cookie";
31 const char kTestSessionLSIDCookie
[] = "fake-session-LSID-cookie";
32 const char kTestUserinfoToken
[] = "fake-userinfo-token";
36 const char LoginPolicyTestBase::kAccountPassword
[] = "letmein";
37 const char LoginPolicyTestBase::kAccountId
[] = "user@example.com";
39 LoginPolicyTestBase::LoginPolicyTestBase() {
40 set_open_about_blank_on_browser_launch(false);
43 LoginPolicyTestBase::~LoginPolicyTestBase() {
46 void LoginPolicyTestBase::SetUp() {
47 base::DictionaryValue mandatory
;
48 GetMandatoryPoliciesValue(&mandatory
);
49 base::DictionaryValue recommended
;
50 GetRecommendedPoliciesValue(&recommended
);
51 user_policy_helper_
.reset(new UserPolicyTestHelper(kAccountId
));
52 user_policy_helper_
->Init(mandatory
, recommended
);
53 OobeBaseTest::SetUp();
56 void LoginPolicyTestBase::SetUpCommandLine(base::CommandLine
* command_line
) {
57 user_policy_helper_
->UpdateCommandLine(command_line
);
58 OobeBaseTest::SetUpCommandLine(command_line
);
61 void LoginPolicyTestBase::SetUpOnMainThread() {
62 SetMergeSessionParams();
63 SetUpGaiaServerWithAccessTokens();
64 OobeBaseTest::SetUpOnMainThread();
67 void LoginPolicyTestBase::GetMandatoryPoliciesValue(
68 base::DictionaryValue
* policy
) const {
71 void LoginPolicyTestBase::GetRecommendedPoliciesValue(
72 base::DictionaryValue
* policy
) const {
75 void LoginPolicyTestBase::SetUpGaiaServerWithAccessTokens() {
76 FakeGaia::AccessTokenInfo token_info
;
77 token_info
.token
= kTestUserinfoToken
;
78 token_info
.scopes
.insert(GaiaConstants::kDeviceManagementServiceOAuth
);
79 token_info
.scopes
.insert(GaiaConstants::kOAuthWrapBridgeUserInfoScope
);
80 token_info
.audience
= GaiaUrls::GetInstance()->oauth2_chrome_client_id();
81 token_info
.email
= kAccountId
;
82 fake_gaia_
->IssueOAuthToken(kTestRefreshToken
, token_info
);
85 void LoginPolicyTestBase::SetMergeSessionParams() {
86 FakeGaia::MergeSessionParams params
;
87 params
.auth_sid_cookie
= kTestAuthSIDCookie
;
88 params
.auth_lsid_cookie
= kTestAuthLSIDCookie
;
89 params
.auth_code
= kTestAuthCode
;
90 params
.refresh_token
= kTestRefreshToken
;
91 params
.access_token
= kTestAuthLoginAccessToken
;
92 params
.gaia_uber_token
= kTestGaiaUberToken
;
93 params
.session_sid_cookie
= kTestSessionSIDCookie
;
94 params
.session_lsid_cookie
= kTestSessionLSIDCookie
;
95 params
.email
= kAccountId
;
96 fake_gaia_
->SetMergeSessionParams(params
);
99 void LoginPolicyTestBase::SkipToLoginScreen() {
100 chromeos::WizardController::SkipPostLoginScreensForTesting();
101 chromeos::WizardController
* const wizard_controller
=
102 chromeos::WizardController::default_controller();
103 ASSERT_TRUE(wizard_controller
);
104 wizard_controller
->SkipToLoginForTesting(chromeos::LoginScreenContext());
106 content::WindowedNotificationObserver(
107 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE
,
108 content::NotificationService::AllSources()).Wait();
111 void LoginPolicyTestBase::LogIn(const std::string
& user_id
,
112 const std::string
& password
) {
113 GetLoginDisplay()->ShowSigninScreenForCreds(user_id
, password
);
115 content::WindowedNotificationObserver(
116 chrome::NOTIFICATION_SESSION_STARTED
,
117 content::NotificationService::AllSources()).Wait();
120 } // namespace policy