Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: chrome/browser/chromeos/policy/login_policy_test_base.cc

Issue 964503002: Implemented ForceMaximizeBrowserWindowOnFirstRun policy, added unit test and browser test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix after review Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "base/command_line.h"
6 #include "base/files/file_path.h"
bartfab (slow) 2015/04/01 14:22:42 Nit: Move this to the header file.
peletskyi 2015/04/01 18:55:46 Why?
bartfab (slow) 2015/04/02 08:44:28 Because I thought that you needed the full type in
7 #include "base/files/file_util.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/login_policy_test_base.h"
12 #include "chrome/browser/policy/test/local_policy_test_server.h"
13 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
14 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
15 #include "components/policy/core/common/policy_switches.h"
16 #include "content/public/browser/notification_service.h"
17 #include "content/public/test/test_utils.h"
18 #include "google_apis/gaia/fake_gaia.h"
19 #include "google_apis/gaia/gaia_constants.h"
20 #include "google_apis/gaia/gaia_urls.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "url/gurl.h"
23
24 namespace policy {
25
26 namespace {
27
28 const char kTestAuthCode[] = "fake-auth-code";
29 const char kTestGaiaUberToken[] = "fake-uber-token";
30 const char kTestAuthLoginAccessToken[] = "fake-access-token";
31 const char kTestRefreshToken[] = "fake-refresh-token";
32 const char kTestAuthSIDCookie[] = "fake-auth-SID-cookie";
33 const char kTestAuthLSIDCookie[] = "fake-auth-LSID-cookie";
34 const char kTestSessionSIDCookie[] = "fake-session-SID-cookie";
35 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie";
36 const char kTestUserinfoToken[] = "fake-userinfo-token";
37
38 std::string GetPolicy(const std::string& mandatory,
39 const std::string& recommended,
40 const std::string& policyType,
41 const std::string& account) {
42 std::string ret =
bartfab (slow) 2015/04/01 14:22:42 1: Construct a base::DictionaryValue and use base:
peletskyi 2015/04/01 18:55:46 2,3 Done. 1. I think the code will be rather compl
bartfab (slow) 2015/04/02 08:44:28 Re 1: Why would it be complicated? You could even
peletskyi 2015/04/02 12:53:29 Done.
43 "{"
44 " \"" +
45 policyType +
46 "\": {"
47 " \"mandatory\": {" +
48 mandatory +
49 "},"
50 " \"recommended\": {" +
51 recommended +
52 "}"
53 " },"
54 " \"managed_users\": [ \"*\" ],"
55 " \"policy_user\": \"" +
56 account +
57 "\","
58 " \"current_key_index\": 0"
59 "}";
60 return ret;
61 }
62
63 } // namespace
64
65 const char LoginPolicyTestBase::kAccountPassword[] = "letmein";
66 const char LoginPolicyTestBase::kAccountId[] = "dla1@example.com";
67
68 LoginPolicyTestBase::LoginPolicyTestBase() {
69 set_open_about_blank_on_browser_launch(false);
70 }
71
72 LoginPolicyTestBase::~LoginPolicyTestBase() {
73 }
74
75 void LoginPolicyTestBase::SetUp() {
76 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
77 SetServerPolicy();
78
79 test_server_.reset(new LocalPolicyTestServer(PolicyFilePath()));
80 ASSERT_TRUE(test_server_->Start());
81
82 OobeBaseTest::SetUp();
83 }
84
85 void LoginPolicyTestBase::SetUpCommandLine(base::CommandLine* command_line) {
86 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl,
87 test_server_->GetServiceURL().spec());
88 OobeBaseTest::SetUpCommandLine(command_line);
89 }
90
91 void LoginPolicyTestBase::SetUpOnMainThread() {
92 SetMergeSessionParams(kAccountId);
93 SetUpGaiaServerWithAccessTokens();
94 OobeBaseTest::SetUpOnMainThread();
95 }
96
97 std::string LoginPolicyTestBase::GetMandatoryPolicies() const {
98 return "";
99 }
100
101 std::string LoginPolicyTestBase::GetRecommendedPolicies() const {
102 return "";
103 }
104
105 void LoginPolicyTestBase::SetUpGaiaServerWithAccessTokens() {
106 FakeGaia::AccessTokenInfo token_info;
107 token_info.token = kTestUserinfoToken;
108 token_info.scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth);
109 token_info.scopes.insert(GaiaConstants::kOAuthWrapBridgeUserInfoScope);
110 token_info.audience = GaiaUrls::GetInstance()->oauth2_chrome_client_id();
111 token_info.email = kAccountId;
112 fake_gaia_->IssueOAuthToken(kTestRefreshToken, token_info);
113 }
114
115 void LoginPolicyTestBase::SetMergeSessionParams(const std::string& email) {
116 FakeGaia::MergeSessionParams params;
117 params.auth_sid_cookie = kTestAuthSIDCookie;
118 params.auth_lsid_cookie = kTestAuthLSIDCookie;
119 params.auth_code = kTestAuthCode;
120 params.refresh_token = kTestRefreshToken;
121 params.access_token = kTestAuthLoginAccessToken;
122 params.gaia_uber_token = kTestGaiaUberToken;
123 params.session_sid_cookie = kTestSessionSIDCookie;
124 params.session_lsid_cookie = kTestSessionLSIDCookie;
125 params.email = email;
126 fake_gaia_->SetMergeSessionParams(params);
127 }
128
129 void LoginPolicyTestBase::SkipToLoginScreen() {
130 chromeos::WizardController::SkipPostLoginScreensForTesting();
131 chromeos::WizardController* wizard_controller =
132 chromeos::WizardController::default_controller();
133 ASSERT_TRUE(wizard_controller);
134 wizard_controller->SkipToLoginForTesting(chromeos::LoginScreenContext());
135
136 content::WindowedNotificationObserver(
137 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
138 content::NotificationService::AllSources()).Wait();
139 }
140
141 void LoginPolicyTestBase::LogIn(const std::string& user_id,
142 const std::string& password) {
143 GetLoginDisplay()->ShowSigninScreenForCreds(user_id, password);
144
145 content::WindowedNotificationObserver(
146 chrome::NOTIFICATION_SESSION_STARTED,
147 content::NotificationService::AllSources()).Wait();
148 }
149
150 void LoginPolicyTestBase::SetServerPolicy() {
151 const std::string policy =
152 GetPolicy(GetMandatoryPolicies(), GetRecommendedPolicies(),
153 dm_protocol::kChromeUserPolicyType, kAccountId);
154
155 const int bytes_written =
156 base::WriteFile(PolicyFilePath(), policy.data(), policy.size());
157 ASSERT_EQ(static_cast<int>(policy.size()), bytes_written);
158 }
159
160 base::FilePath LoginPolicyTestBase::PolicyFilePath() const {
161 return temp_dir_.path().AppendASCII("policy.json");
162 }
163
164 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698