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

Side by Side Diff: chrome/browser/chromeos/settings/device_oauth2_token_service_unittest.cc

Issue 23382008: Making OAuth2TokenService multi-login aware, updating callers, minor fixes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updates to AndroidPO2TS and removing the DCHECK(signin_manager) from GetPrimaryAccountId Created 7 years, 3 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 5 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/prefs/testing_pref_service.h" 8 #include "base/prefs/testing_pref_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Local State (if the value is an empty string, it will be ignored). 72 // Local State (if the value is an empty string, it will be ignored).
73 void SetUpDefaultValues() { 73 void SetUpDefaultValues() {
74 cryptohome_library_.reset(chromeos::CryptohomeLibrary::GetTestImpl()); 74 cryptohome_library_.reset(chromeos::CryptohomeLibrary::GetTestImpl());
75 chromeos::CryptohomeLibrary::SetForTest(cryptohome_library_.get()); 75 chromeos::CryptohomeLibrary::SetForTest(cryptohome_library_.get());
76 SetDeviceRefreshTokenInLocalState("device_refresh_token_4_test"); 76 SetDeviceRefreshTokenInLocalState("device_refresh_token_4_test");
77 oauth2_service_.SetRobotAccountIdPolicyValue("service_acct@g.com"); 77 oauth2_service_.SetRobotAccountIdPolicyValue("service_acct@g.com");
78 AssertConsumerTokensAndErrors(0, 0); 78 AssertConsumerTokensAndErrors(0, 0);
79 } 79 }
80 80
81 scoped_ptr<OAuth2TokenService::Request> StartTokenRequest() { 81 scoped_ptr<OAuth2TokenService::Request> StartTokenRequest() {
82 return oauth2_service_.StartRequest(std::set<std::string>(), &consumer_); 82 return oauth2_service_.StartRequest(oauth2_service_.GetDeviceAccountId(),
83 std::set<std::string>(),
84 &consumer_);
83 } 85 }
84 86
85 virtual void TearDown() OVERRIDE { 87 virtual void TearDown() OVERRIDE {
86 CryptohomeLibrary::SetForTest(NULL); 88 CryptohomeLibrary::SetForTest(NULL);
87 base::RunLoop().RunUntilIdle(); 89 base::RunLoop().RunUntilIdle();
88 } 90 }
89 91
90 // Utility method to set a value in Local State for the device refresh token 92 // Utility method to set a value in Local State for the device refresh token
91 // (it must have a non-empty value or it won't be used). 93 // (it must have a non-empty value or it won't be used).
92 void SetDeviceRefreshTokenInLocalState(const std::string& refresh_token) { 94 void SetDeviceRefreshTokenInLocalState(const std::string& refresh_token) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 .WillOnce(Return("")); 157 .WillOnce(Return(""));
156 EXPECT_CALL(mock_cryptohome_library, 158 EXPECT_CALL(mock_cryptohome_library,
157 EncryptWithSystemSalt(StrEq("test-token"))) 159 EncryptWithSystemSalt(StrEq("test-token")))
158 .Times(1) 160 .Times(1)
159 .WillOnce(Return("encrypted")); 161 .WillOnce(Return("encrypted"));
160 EXPECT_CALL(mock_cryptohome_library, 162 EXPECT_CALL(mock_cryptohome_library,
161 DecryptWithSystemSalt(StrEq("encrypted"))) 163 DecryptWithSystemSalt(StrEq("encrypted")))
162 .Times(1) 164 .Times(1)
163 .WillOnce(Return("test-token")); 165 .WillOnce(Return("test-token"));
164 166
165 ASSERT_EQ("", oauth2_service_.GetRefreshToken()); 167 ASSERT_EQ("", oauth2_service_.GetRefreshToken(
168 oauth2_service_.GetDeviceAccountId()));
166 oauth2_service_.SetAndSaveRefreshToken("test-token"); 169 oauth2_service_.SetAndSaveRefreshToken("test-token");
167 ASSERT_EQ("test-token", oauth2_service_.GetRefreshToken()); 170 ASSERT_EQ("test-token", oauth2_service_.GetRefreshToken(
171 oauth2_service_.GetDeviceAccountId()));
168 172
169 // This call won't invoke decrypt again, since the value is cached. 173 // This call won't invoke decrypt again, since the value is cached.
170 ASSERT_EQ("test-token", oauth2_service_.GetRefreshToken()); 174 ASSERT_EQ("test-token", oauth2_service_.GetRefreshToken(
175 oauth2_service_.GetDeviceAccountId()));
171 } 176 }
172 177
173 TEST_F(DeviceOAuth2TokenServiceTest, RefreshTokenValidation_Success) { 178 TEST_F(DeviceOAuth2TokenServiceTest, RefreshTokenValidation_Success) {
174 SetUpDefaultValues(); 179 SetUpDefaultValues();
175 scoped_ptr<OAuth2TokenService::Request> request = StartTokenRequest(); 180 scoped_ptr<OAuth2TokenService::Request> request = StartTokenRequest();
176 181
177 ReturnOAuthUrlFetchResults( 182 ReturnOAuthUrlFetchResults(
178 kValidatorUrlFetcherId, 183 kValidatorUrlFetcherId,
179 net::HTTP_OK, 184 net::HTTP_OK,
180 GetValidTokenResponse("tokeninfo_access_token", 3600)); 185 GetValidTokenResponse("tokeninfo_access_token", 3600));
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 kValidatorUrlFetcherId, 364 kValidatorUrlFetcherId,
360 net::HTTP_OK, 365 net::HTTP_OK,
361 GetValidTokenInfoResponse("service_acct@g.com")); 366 GetValidTokenInfoResponse("service_acct@g.com"));
362 367
363 // All fetches were successful, but consumer still given error since 368 // All fetches were successful, but consumer still given error since
364 // the token owner doesn't match the policy value. 369 // the token owner doesn't match the policy value.
365 AssertConsumerTokensAndErrors(0, 1); 370 AssertConsumerTokensAndErrors(0, 1);
366 } 371 }
367 372
368 } // namespace chromeos 373 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698