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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/login_policy_test_base.cc
diff --git a/chrome/browser/chromeos/policy/login_policy_test_base.cc b/chrome/browser/chromeos/policy/login_policy_test_base.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c9ebd4ce217354b491c078b95b5c1dfb0226d8e8
--- /dev/null
+++ b/chrome/browser/chromeos/policy/login_policy_test_base.cc
@@ -0,0 +1,164 @@
+// Copyright 2015 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 "base/command_line.h"
+#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
+#include "base/files/file_util.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/chromeos/login/ui/webui_login_display.h"
+#include "chrome/browser/chromeos/login/wizard_controller.h"
+#include "chrome/browser/chromeos/policy/login_policy_test_base.h"
+#include "chrome/browser/policy/test/local_policy_test_server.h"
+#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
+#include "components/policy/core/common/cloud/cloud_policy_constants.h"
+#include "components/policy/core/common/policy_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_constants.h"
+#include "google_apis/gaia/gaia_urls.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+namespace policy {
+
+namespace {
+
+const char kTestAuthCode[] = "fake-auth-code";
+const char kTestGaiaUberToken[] = "fake-uber-token";
+const char kTestAuthLoginAccessToken[] = "fake-access-token";
+const char kTestRefreshToken[] = "fake-refresh-token";
+const char kTestAuthSIDCookie[] = "fake-auth-SID-cookie";
+const char kTestAuthLSIDCookie[] = "fake-auth-LSID-cookie";
+const char kTestSessionSIDCookie[] = "fake-session-SID-cookie";
+const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie";
+const char kTestUserinfoToken[] = "fake-userinfo-token";
+
+std::string GetPolicy(const std::string& mandatory,
+ const std::string& recommended,
+ const std::string& policyType,
+ const std::string& account) {
+ 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.
+ "{"
+ " \"" +
+ policyType +
+ "\": {"
+ " \"mandatory\": {" +
+ mandatory +
+ "},"
+ " \"recommended\": {" +
+ recommended +
+ "}"
+ " },"
+ " \"managed_users\": [ \"*\" ],"
+ " \"policy_user\": \"" +
+ account +
+ "\","
+ " \"current_key_index\": 0"
+ "}";
+ return ret;
+}
+
+} // namespace
+
+const char LoginPolicyTestBase::kAccountPassword[] = "letmein";
+const char LoginPolicyTestBase::kAccountId[] = "dla1@example.com";
+
+LoginPolicyTestBase::LoginPolicyTestBase() {
+ set_open_about_blank_on_browser_launch(false);
+}
+
+LoginPolicyTestBase::~LoginPolicyTestBase() {
+}
+
+void LoginPolicyTestBase::SetUp() {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ SetServerPolicy();
+
+ test_server_.reset(new LocalPolicyTestServer(PolicyFilePath()));
+ ASSERT_TRUE(test_server_->Start());
+
+ OobeBaseTest::SetUp();
+}
+
+void LoginPolicyTestBase::SetUpCommandLine(base::CommandLine* command_line) {
+ command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl,
+ test_server_->GetServiceURL().spec());
+ OobeBaseTest::SetUpCommandLine(command_line);
+}
+
+void LoginPolicyTestBase::SetUpOnMainThread() {
+ SetMergeSessionParams(kAccountId);
+ SetUpGaiaServerWithAccessTokens();
+ OobeBaseTest::SetUpOnMainThread();
+}
+
+std::string LoginPolicyTestBase::GetMandatoryPolicies() const {
+ return "";
+}
+
+std::string LoginPolicyTestBase::GetRecommendedPolicies() const {
+ return "";
+}
+
+void LoginPolicyTestBase::SetUpGaiaServerWithAccessTokens() {
+ FakeGaia::AccessTokenInfo token_info;
+ token_info.token = kTestUserinfoToken;
+ token_info.scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth);
+ token_info.scopes.insert(GaiaConstants::kOAuthWrapBridgeUserInfoScope);
+ token_info.audience = GaiaUrls::GetInstance()->oauth2_chrome_client_id();
+ token_info.email = kAccountId;
+ fake_gaia_->IssueOAuthToken(kTestRefreshToken, token_info);
+}
+
+void LoginPolicyTestBase::SetMergeSessionParams(const std::string& email) {
+ FakeGaia::MergeSessionParams params;
+ params.auth_sid_cookie = kTestAuthSIDCookie;
+ params.auth_lsid_cookie = kTestAuthLSIDCookie;
+ params.auth_code = kTestAuthCode;
+ params.refresh_token = kTestRefreshToken;
+ params.access_token = kTestAuthLoginAccessToken;
+ params.gaia_uber_token = kTestGaiaUberToken;
+ params.session_sid_cookie = kTestSessionSIDCookie;
+ params.session_lsid_cookie = kTestSessionLSIDCookie;
+ params.email = email;
+ fake_gaia_->SetMergeSessionParams(params);
+}
+
+void LoginPolicyTestBase::SkipToLoginScreen() {
+ chromeos::WizardController::SkipPostLoginScreensForTesting();
+ chromeos::WizardController* wizard_controller =
+ chromeos::WizardController::default_controller();
+ ASSERT_TRUE(wizard_controller);
+ wizard_controller->SkipToLoginForTesting(chromeos::LoginScreenContext());
+
+ content::WindowedNotificationObserver(
+ chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
+ content::NotificationService::AllSources()).Wait();
+}
+
+void LoginPolicyTestBase::LogIn(const std::string& user_id,
+ const std::string& password) {
+ GetLoginDisplay()->ShowSigninScreenForCreds(user_id, password);
+
+ content::WindowedNotificationObserver(
+ chrome::NOTIFICATION_SESSION_STARTED,
+ content::NotificationService::AllSources()).Wait();
+}
+
+void LoginPolicyTestBase::SetServerPolicy() {
+ const std::string policy =
+ GetPolicy(GetMandatoryPolicies(), GetRecommendedPolicies(),
+ dm_protocol::kChromeUserPolicyType, kAccountId);
+
+ const int bytes_written =
+ base::WriteFile(PolicyFilePath(), policy.data(), policy.size());
+ ASSERT_EQ(static_cast<int>(policy.size()), bytes_written);
+}
+
+base::FilePath LoginPolicyTestBase::PolicyFilePath() const {
+ return temp_dir_.path().AppendASCII("policy.json");
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698