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 // TODO(nkostylev): Fix this test harness for webview. http://crbug.com/477402
41 set_use_webview(false);
42 set_open_about_blank_on_browser_launch(false);
45 LoginPolicyTestBase::~LoginPolicyTestBase() {
48 void LoginPolicyTestBase::SetUp() {
49 base::DictionaryValue mandatory
;
50 GetMandatoryPoliciesValue(&mandatory
);
51 base::DictionaryValue recommended
;
52 GetRecommendedPoliciesValue(&recommended
);
53 user_policy_helper_
.reset(new UserPolicyTestHelper(kAccountId
));
54 user_policy_helper_
->Init(mandatory
, recommended
);
55 OobeBaseTest::SetUp();
58 void LoginPolicyTestBase::SetUpCommandLine(base::CommandLine
* command_line
) {
59 user_policy_helper_
->UpdateCommandLine(command_line
);
60 OobeBaseTest::SetUpCommandLine(command_line
);
63 void LoginPolicyTestBase::SetUpOnMainThread() {
64 SetMergeSessionParams();
65 SetUpGaiaServerWithAccessTokens();
66 OobeBaseTest::SetUpOnMainThread();
69 void LoginPolicyTestBase::GetMandatoryPoliciesValue(
70 base::DictionaryValue
* policy
) const {
73 void LoginPolicyTestBase::GetRecommendedPoliciesValue(
74 base::DictionaryValue
* policy
) const {
77 void LoginPolicyTestBase::SetUpGaiaServerWithAccessTokens() {
78 FakeGaia::AccessTokenInfo token_info
;
79 token_info
.token
= kTestUserinfoToken
;
80 token_info
.scopes
.insert(GaiaConstants::kDeviceManagementServiceOAuth
);
81 token_info
.scopes
.insert(GaiaConstants::kOAuthWrapBridgeUserInfoScope
);
82 token_info
.audience
= GaiaUrls::GetInstance()->oauth2_chrome_client_id();
83 token_info
.email
= kAccountId
;
84 fake_gaia_
->IssueOAuthToken(kTestRefreshToken
, token_info
);
87 void LoginPolicyTestBase::SetMergeSessionParams() {
88 FakeGaia::MergeSessionParams params
;
89 params
.auth_sid_cookie
= kTestAuthSIDCookie
;
90 params
.auth_lsid_cookie
= kTestAuthLSIDCookie
;
91 params
.auth_code
= kTestAuthCode
;
92 params
.refresh_token
= kTestRefreshToken
;
93 params
.access_token
= kTestAuthLoginAccessToken
;
94 params
.gaia_uber_token
= kTestGaiaUberToken
;
95 params
.session_sid_cookie
= kTestSessionSIDCookie
;
96 params
.session_lsid_cookie
= kTestSessionLSIDCookie
;
97 params
.email
= kAccountId
;
98 fake_gaia_
->SetMergeSessionParams(params
);
101 void LoginPolicyTestBase::SkipToLoginScreen() {
102 chromeos::WizardController::SkipPostLoginScreensForTesting();
103 chromeos::WizardController
* const wizard_controller
=
104 chromeos::WizardController::default_controller();
105 ASSERT_TRUE(wizard_controller
);
106 wizard_controller
->SkipToLoginForTesting(chromeos::LoginScreenContext());
108 content::WindowedNotificationObserver(
109 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE
,
110 content::NotificationService::AllSources()).Wait();
113 void LoginPolicyTestBase::LogIn(const std::string
& user_id
,
114 const std::string
& password
) {
115 GetLoginDisplay()->ShowSigninScreenForCreds(user_id
, password
);
117 content::WindowedNotificationObserver(
118 chrome::NOTIFICATION_SESSION_STARTED
,
119 content::NotificationService::AllSources()).Wait();
122 } // namespace policy