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

Unified Diff: chrome/browser/chromeos/policy/login_policy_base_test.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: Fixed description Created 5 years, 10 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_base_test.cc
diff --git a/chrome/browser/chromeos/policy/login_policy_base_test.cc b/chrome/browser/chromeos/policy/login_policy_base_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4360d588fc20b32425654468133c65f26c66da46
--- /dev/null
+++ b/chrome/browser/chromeos/policy/login_policy_base_test.cc
@@ -0,0 +1,123 @@
+// 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 "login_policy_base_test.h"
bartfab (slow) 2015/03/12 11:54:46 Nit 1: Add the path to this file. Nit 2: Add a bla
peletskyi 2015/03/18 13:28:11 Done.
+#include "base/command_line.h"
+#include "base/strings/stringprintf.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 "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"
+
+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";
+
+} // namespace
+
+namespace policy {
bartfab (slow) 2015/03/12 11:54:46 Nit: Move this higher up so that the anonymous nam
peletskyi 2015/03/18 13:28:12 Done.
+
+const char LoginPolicyBaseTest::kAccountPassword[] = "letmein";
+const char LoginPolicyBaseTest::kAccountId[] = "dla1@example.com";
bartfab (slow) 2015/03/12 11:54:46 Nit: Why are you using "dla" here? Is this base me
peletskyi 2015/03/18 13:28:12 It was here before my changes, but in another file
bartfab (slow) 2015/04/01 14:22:41 Device-local accounts are public sessions and sing
peletskyi 2015/04/01 18:55:45 Done.
+
+LoginPolicyBaseTest::LoginPolicyBaseTest() {
+ set_open_about_blank_on_browser_launch(false);
+}
+
+LoginPolicyBaseTest::~LoginPolicyBaseTest() {
+}
+
+void LoginPolicyBaseTest::SetUp() {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ SetServerPolicy();
+
+ test_server_.reset(new LocalPolicyTestServer(policy_file_path()));
bartfab (slow) 2015/03/12 11:54:46 Nit: #include "chrome/browser/policy/test/local_po
peletskyi 2015/03/18 13:28:11 Done.
+ ASSERT_TRUE(test_server_->Start());
+
+ OobeBaseTest::SetUp();
+}
+
+void LoginPolicyBaseTest::SetUpCommandLine(base::CommandLine* command_line) {
+ command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl,
bartfab (slow) 2015/03/12 11:54:46 Nit: #include "components/policy/core/common/polic
peletskyi 2015/03/18 13:28:11 Done.
+ test_server_->GetServiceURL().spec());
bartfab (slow) 2015/03/12 11:54:46 Nit: #include "url/gurl.h"
peletskyi 2015/03/18 13:28:11 Done.
+ OobeBaseTest::SetUpCommandLine(command_line);
+}
+
+void LoginPolicyBaseTest::SetUpOnMainThread() {
+ SetMergeSessionParams(kAccountId);
+ SetupGaiaServerWithAccessTokens();
+ OobeBaseTest::SetUpOnMainThread();
+}
+
+void LoginPolicyBaseTest::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 LoginPolicyBaseTest::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 LoginPolicyBaseTest::SkipToLoginScreen() {
+ chromeos::WizardController::SkipPostLoginScreensForTesting();
bartfab (slow) 2015/03/12 11:54:46 Nit: #include "chrome/browser/chromeos/login/wizar
peletskyi 2015/03/18 13:28:11 Done.
+ chromeos::WizardController* wizard_controller =
bartfab (slow) 2015/03/12 11:54:46 Nit: const pointer.
peletskyi 2015/03/18 13:28:11 Done.
bartfab (slow) 2015/04/01 14:22:41 No, not done.
peletskyi 2015/04/01 18:55:45 Can not be done, because method SkipToLoginForTest
bartfab (slow) 2015/04/02 08:44:27 I asked for a const pointer, not a pointer to cons
peletskyi 2015/04/02 12:53:28 Done.
+ chromeos::WizardController::default_controller();
+ ASSERT_TRUE(wizard_controller);
+ wizard_controller->SkipToLoginForTesting(chromeos::LoginScreenContext());
bartfab (slow) 2015/03/12 11:54:46 Nit: #include "chrome/browser/ui/webui/chromeos/lo
peletskyi 2015/03/18 13:28:11 Done.
+
+ content::WindowedNotificationObserver(
bartfab (slow) 2015/03/12 11:54:46 Nit: #include "content/public/test/test_utils.h"
peletskyi 2015/03/18 13:28:11 Done.
+ chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
bartfab (slow) 2015/03/12 11:54:46 Nit: #include "chrome/browser/chrome_notification_
peletskyi 2015/03/18 13:28:11 Done.
+ content::NotificationService::AllSources()).Wait();
+}
+
+void LoginPolicyBaseTest::LogIn(const std::string& user_id,
+ const std::string& password) {
+ GetLoginDisplay()->ShowSigninScreenForCreds(user_id, password);
bartfab (slow) 2015/03/12 11:54:46 Nit: #include "chrome/browser/chromeos/login/ui/we
peletskyi 2015/03/18 13:28:12 Done.
peletskyi 2015/03/18 13:28:12 Done.
+
+ content::WindowedNotificationObserver(
+ chrome::NOTIFICATION_SESSION_STARTED,
+ content::NotificationService::AllSources()).Wait();
+}
+
+void LoginPolicyBaseTest::SetServerPolicy() {
+ std::string pol = GetPolicy();
bartfab (slow) 2015/03/12 11:54:46 Nit: Avoid abbreviations like |pol|. You can actua
peletskyi 2015/03/18 13:28:12 Done.
+ const std::string policy = base::StringPrintf(
bartfab (slow) 2015/03/12 11:54:46 You clearly have very specific requirements for th
peletskyi 2015/03/18 13:28:12 No need for this any longer
+ pol.c_str(), dm_protocol::kChromeUserPolicyType, kAccountId);
+
+ const int bytes_written =
+ base::WriteFile(policy_file_path(), policy.data(), policy.size());
bartfab (slow) 2015/03/12 11:54:46 Nit: #include "base/files/file_util.h"
peletskyi 2015/03/18 13:28:12 Done.
+ ASSERT_EQ(static_cast<int>(policy.size()), bytes_written);
+}
+
+base::FilePath LoginPolicyBaseTest::policy_file_path() const {
+ return temp_dir_.path().AppendASCII("policy.json");
bartfab (slow) 2015/03/12 11:54:46 Nit: #include "base/files/file_path.h"
peletskyi 2015/03/18 13:28:12 Done.
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698