Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "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.
| |
| 6 #include "base/command_line.h" | |
| 7 #include "base/strings/stringprintf.h" | |
| 8 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | |
| 9 #include "components/policy/core/common/policy_switches.h" | |
| 10 #include "content/public/browser/notification_service.h" | |
| 11 #include "google_apis/gaia/fake_gaia.h" | |
| 12 #include "google_apis/gaia/gaia_constants.h" | |
| 13 #include "google_apis/gaia/gaia_urls.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 const char kTestAuthCode[] = "fake-auth-code"; | |
| 19 const char kTestGaiaUberToken[] = "fake-uber-token"; | |
| 20 const char kTestAuthLoginAccessToken[] = "fake-access-token"; | |
| 21 const char kTestRefreshToken[] = "fake-refresh-token"; | |
| 22 const char kTestAuthSIDCookie[] = "fake-auth-SID-cookie"; | |
| 23 const char kTestAuthLSIDCookie[] = "fake-auth-LSID-cookie"; | |
| 24 const char kTestSessionSIDCookie[] = "fake-session-SID-cookie"; | |
| 25 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie"; | |
| 26 const char kTestUserinfoToken[] = "fake-userinfo-token"; | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 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.
| |
| 31 | |
| 32 const char LoginPolicyBaseTest::kAccountPassword[] = "letmein"; | |
| 33 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.
| |
| 34 | |
| 35 LoginPolicyBaseTest::LoginPolicyBaseTest() { | |
| 36 set_open_about_blank_on_browser_launch(false); | |
| 37 } | |
| 38 | |
| 39 LoginPolicyBaseTest::~LoginPolicyBaseTest() { | |
| 40 } | |
| 41 | |
| 42 void LoginPolicyBaseTest::SetUp() { | |
| 43 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 44 SetServerPolicy(); | |
| 45 | |
| 46 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.
| |
| 47 ASSERT_TRUE(test_server_->Start()); | |
| 48 | |
| 49 OobeBaseTest::SetUp(); | |
| 50 } | |
| 51 | |
| 52 void LoginPolicyBaseTest::SetUpCommandLine(base::CommandLine* command_line) { | |
| 53 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.
| |
| 54 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.
| |
| 55 OobeBaseTest::SetUpCommandLine(command_line); | |
| 56 } | |
| 57 | |
| 58 void LoginPolicyBaseTest::SetUpOnMainThread() { | |
| 59 SetMergeSessionParams(kAccountId); | |
| 60 SetupGaiaServerWithAccessTokens(); | |
| 61 OobeBaseTest::SetUpOnMainThread(); | |
| 62 } | |
| 63 | |
| 64 void LoginPolicyBaseTest::SetupGaiaServerWithAccessTokens() { | |
| 65 FakeGaia::AccessTokenInfo token_info; | |
| 66 token_info.token = kTestUserinfoToken; | |
| 67 token_info.scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth); | |
| 68 token_info.scopes.insert(GaiaConstants::kOAuthWrapBridgeUserInfoScope); | |
| 69 token_info.audience = GaiaUrls::GetInstance()->oauth2_chrome_client_id(); | |
| 70 token_info.email = kAccountId; | |
| 71 fake_gaia_->IssueOAuthToken(kTestRefreshToken, token_info); | |
| 72 } | |
| 73 | |
| 74 void LoginPolicyBaseTest::SetMergeSessionParams(const std::string& email) { | |
| 75 FakeGaia::MergeSessionParams params; | |
| 76 params.auth_sid_cookie = kTestAuthSIDCookie; | |
| 77 params.auth_lsid_cookie = kTestAuthLSIDCookie; | |
| 78 params.auth_code = kTestAuthCode; | |
| 79 params.refresh_token = kTestRefreshToken; | |
| 80 params.access_token = kTestAuthLoginAccessToken; | |
| 81 params.gaia_uber_token = kTestGaiaUberToken; | |
| 82 params.session_sid_cookie = kTestSessionSIDCookie; | |
| 83 params.session_lsid_cookie = kTestSessionLSIDCookie; | |
| 84 params.email = email; | |
| 85 fake_gaia_->SetMergeSessionParams(params); | |
| 86 } | |
| 87 | |
| 88 void LoginPolicyBaseTest::SkipToLoginScreen() { | |
| 89 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.
| |
| 90 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.
| |
| 91 chromeos::WizardController::default_controller(); | |
| 92 ASSERT_TRUE(wizard_controller); | |
| 93 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.
| |
| 94 | |
| 95 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.
| |
| 96 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.
| |
| 97 content::NotificationService::AllSources()).Wait(); | |
| 98 } | |
| 99 | |
| 100 void LoginPolicyBaseTest::LogIn(const std::string& user_id, | |
| 101 const std::string& password) { | |
| 102 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.
| |
| 103 | |
| 104 content::WindowedNotificationObserver( | |
| 105 chrome::NOTIFICATION_SESSION_STARTED, | |
| 106 content::NotificationService::AllSources()).Wait(); | |
| 107 } | |
| 108 | |
| 109 void LoginPolicyBaseTest::SetServerPolicy() { | |
| 110 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.
| |
| 111 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
| |
| 112 pol.c_str(), dm_protocol::kChromeUserPolicyType, kAccountId); | |
| 113 | |
| 114 const int bytes_written = | |
| 115 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.
| |
| 116 ASSERT_EQ(static_cast<int>(policy.size()), bytes_written); | |
| 117 } | |
| 118 | |
| 119 base::FilePath LoginPolicyBaseTest::policy_file_path() const { | |
| 120 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.
| |
| 121 } | |
| 122 | |
| 123 } // namespace policy | |
| OLD | NEW |