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

Unified Diff: google_apis/gaia/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: Fixing a unit test, addressing comments from courage@ 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 side-by-side diff with in-line comments
Download patch
Index: google_apis/gaia/oauth2_token_service_unittest.cc
diff --git a/google_apis/gaia/oauth2_token_service_unittest.cc b/google_apis/gaia/oauth2_token_service_unittest.cc
index 9937268bde2cf433bc1d21a2d6966d31ced9a9f5..18f10dcbda1e05502939ca75ac863e9dae357f29 100644
--- a/google_apis/gaia/oauth2_token_service_unittest.cc
+++ b/google_apis/gaia/oauth2_token_service_unittest.cc
@@ -22,18 +22,21 @@ class RetryingTestingOAuth2TokenServiceConsumer
: public TestingOAuth2TokenServiceConsumer {
public:
RetryingTestingOAuth2TokenServiceConsumer(
- OAuth2TokenService* oauth2_service)
- : oauth2_service_(oauth2_service) {}
+ OAuth2TokenService* oauth2_service,
+ const std::string& account_id)
+ : oauth2_service_(oauth2_service),
+ account_id_(account_id) {}
virtual ~RetryingTestingOAuth2TokenServiceConsumer() {}
virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) OVERRIDE {
TestingOAuth2TokenServiceConsumer::OnGetTokenFailure(request, error);
request_.reset(oauth2_service_->StartRequest(
- std::set<std::string>(), this).release());
+ account_id_, OAuth2TokenService::ScopeSet(), this).release());
}
OAuth2TokenService* oauth2_service_;
+ std::string account_id_;
scoped_ptr<OAuth2TokenService::Request> request_;
};
@@ -55,7 +58,10 @@ class TestOAuth2TokenService : public OAuth2TokenService {
}
protected:
- virtual std::string GetRefreshToken() OVERRIDE { return refresh_token_; }
+ virtual std::string GetRefreshToken(const std::string& account_id) OVERRIDE {
+ // account_id explicitly ignored.
+ return refresh_token_;
+ }
private:
// OAuth2TokenService implementation.
@@ -73,6 +79,7 @@ class OAuth2TokenServiceTest : public testing::Test {
oauth2_service_.reset(
new TestOAuth2TokenService(new net::TestURLRequestContextGetter(
message_loop_.message_loop_proxy())));
+ account_id_ = "test_user@gmail.com";
}
virtual void TearDown() OVERRIDE {
@@ -84,12 +91,14 @@ class OAuth2TokenServiceTest : public testing::Test {
base::MessageLoopForIO message_loop_; // net:: stuff needs IO message loop.
net::TestURLFetcherFactory factory_;
scoped_ptr<TestOAuth2TokenService> oauth2_service_;
+ std::string account_id_;
TestingOAuth2TokenServiceConsumer consumer_;
};
TEST_F(OAuth2TokenServiceTest, NoOAuth2RefreshToken) {
scoped_ptr<OAuth2TokenService::Request> request(
- oauth2_service_->StartRequest(std::set<std::string>(), &consumer_));
+ oauth2_service_->StartRequest(account_id_, OAuth2TokenService::ScopeSet(),
+ &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
@@ -99,7 +108,8 @@ TEST_F(OAuth2TokenServiceTest, NoOAuth2RefreshToken) {
TEST_F(OAuth2TokenServiceTest, FailureShouldNotRetry) {
oauth2_service_->set_refresh_token("refreshToken");
scoped_ptr<OAuth2TokenService::Request> request(
- oauth2_service_->StartRequest(std::set<std::string>(), &consumer_));
+ oauth2_service_->StartRequest(account_id_, OAuth2TokenService::ScopeSet(),
+ &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
@@ -117,7 +127,8 @@ TEST_F(OAuth2TokenServiceTest, FailureShouldNotRetry) {
TEST_F(OAuth2TokenServiceTest, SuccessWithoutCaching) {
oauth2_service_->set_refresh_token("refreshToken");
scoped_ptr<OAuth2TokenService::Request> request(
- oauth2_service_->StartRequest(std::set<std::string>(), &consumer_));
+ oauth2_service_->StartRequest(account_id_, OAuth2TokenService::ScopeSet(),
+ &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
@@ -133,20 +144,20 @@ TEST_F(OAuth2TokenServiceTest, SuccessWithoutCaching) {
}
TEST_F(OAuth2TokenServiceTest, SuccessWithCaching) {
- std::set<std::string> scopes1;
+ OAuth2TokenService::ScopeSet scopes1;
scopes1.insert("s1");
scopes1.insert("s2");
- std::set<std::string> scopes1_same;
+ OAuth2TokenService::ScopeSet scopes1_same;
scopes1_same.insert("s2");
scopes1_same.insert("s1");
- std::set<std::string> scopes2;
+ OAuth2TokenService::ScopeSet scopes2;
scopes2.insert("s3");
oauth2_service_->set_refresh_token("refreshToken");
// First request.
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
- scopes1, &consumer_));
+ account_id_, scopes1, &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
@@ -163,7 +174,7 @@ TEST_F(OAuth2TokenServiceTest, SuccessWithCaching) {
// Second request to the same set of scopes, should return the same token
// without needing a network request.
scoped_ptr<OAuth2TokenService::Request> request2(
- oauth2_service_->StartRequest(scopes1_same, &consumer_));
+ oauth2_service_->StartRequest(account_id_, scopes1_same, &consumer_));
base::RunLoop().RunUntilIdle();
// No new network fetcher.
@@ -174,7 +185,7 @@ TEST_F(OAuth2TokenServiceTest, SuccessWithCaching) {
// Third request to a new set of scopes, should return another token.
scoped_ptr<OAuth2TokenService::Request> request3(
- oauth2_service_->StartRequest(scopes2, &consumer_));
+ oauth2_service_->StartRequest(account_id_, scopes2, &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(2, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -193,7 +204,7 @@ TEST_F(OAuth2TokenServiceTest, SuccessAndExpirationAndFailure) {
// First request.
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
- std::set<std::string>(), &consumer_));
+ account_id_, OAuth2TokenService::ScopeSet(), &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -208,7 +219,8 @@ TEST_F(OAuth2TokenServiceTest, SuccessAndExpirationAndFailure) {
// Second request must try to access the network as the token has expired.
scoped_ptr<OAuth2TokenService::Request> request2(
- oauth2_service_->StartRequest(std::set<std::string>(), &consumer_));
+ oauth2_service_->StartRequest(account_id_, OAuth2TokenService::ScopeSet(),
+ &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -228,7 +240,7 @@ TEST_F(OAuth2TokenServiceTest, SuccessAndExpirationAndSuccess) {
// First request.
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
- std::set<std::string>(), &consumer_));
+ account_id_, OAuth2TokenService::ScopeSet(), &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -243,7 +255,8 @@ TEST_F(OAuth2TokenServiceTest, SuccessAndExpirationAndSuccess) {
// Second request must try to access the network as the token has expired.
scoped_ptr<OAuth2TokenService::Request> request2(
- oauth2_service_->StartRequest(std::set<std::string>(), &consumer_));
+ oauth2_service_->StartRequest(account_id_, OAuth2TokenService::ScopeSet(),
+ &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -262,7 +275,7 @@ TEST_F(OAuth2TokenServiceTest, RequestDeletedBeforeCompletion) {
oauth2_service_->set_refresh_token("refreshToken");
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
- std::set<std::string>(), &consumer_));
+ account_id_, OAuth2TokenService::ScopeSet(), &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -282,7 +295,7 @@ TEST_F(OAuth2TokenServiceTest, RequestDeletedAfterCompletion) {
oauth2_service_->set_refresh_token("refreshToken");
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
- std::set<std::string>(), &consumer_));
+ account_id_, OAuth2TokenService::ScopeSet(), &consumer_));
base::RunLoop().RunUntilIdle();
net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
fetcher->set_response_code(net::HTTP_OK);
@@ -303,10 +316,11 @@ TEST_F(OAuth2TokenServiceTest, MultipleRequestsForTheSameScopesWithOneDeleted) {
oauth2_service_->set_refresh_token("refreshToken");
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
- std::set<std::string>(), &consumer_));
+ account_id_, OAuth2TokenService::ScopeSet(), &consumer_));
base::RunLoop().RunUntilIdle();
scoped_ptr<OAuth2TokenService::Request> request2(
- oauth2_service_->StartRequest(std::set<std::string>(), &consumer_));
+ oauth2_service_->StartRequest(account_id_, OAuth2TokenService::ScopeSet(),
+ &consumer_));
base::RunLoop().RunUntilIdle();
request.reset();
@@ -323,7 +337,7 @@ TEST_F(OAuth2TokenServiceTest, ClearedRefreshTokenFailsSubsequentRequests) {
// We have a valid refresh token; the first request is successful.
oauth2_service_->set_refresh_token("refreshToken");
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
- std::set<std::string>(), &consumer_));
+ account_id_, OAuth2TokenService::ScopeSet(), &consumer_));
base::RunLoop().RunUntilIdle();
net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
fetcher->set_response_code(net::HTTP_OK);
@@ -335,7 +349,8 @@ TEST_F(OAuth2TokenServiceTest, ClearedRefreshTokenFailsSubsequentRequests) {
// The refresh token is no longer available; subsequent requests fail.
oauth2_service_->set_refresh_token("");
- request = oauth2_service_->StartRequest(std::set<std::string>(), &consumer_);
+ request = oauth2_service_->StartRequest(account_id_,
+ OAuth2TokenService::ScopeSet(), &consumer_);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(fetcher, factory_.GetFetcherByID(0));
EXPECT_EQ(1, consumer_.number_of_successful_tokens_);
@@ -345,12 +360,12 @@ TEST_F(OAuth2TokenServiceTest, ClearedRefreshTokenFailsSubsequentRequests) {
TEST_F(OAuth2TokenServiceTest,
ChangedRefreshTokenDoesNotAffectInFlightRequests) {
oauth2_service_->set_refresh_token("first refreshToken");
- std::set<std::string> scopes;
+ OAuth2TokenService::ScopeSet scopes;
scopes.insert("s1");
scopes.insert("s2");
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
- scopes, &consumer_));
+ account_id_, scopes, &consumer_));
base::RunLoop().RunUntilIdle();
net::TestURLFetcher* fetcher1 = factory_.GetFetcherByID(0);
@@ -361,7 +376,7 @@ TEST_F(OAuth2TokenServiceTest,
// while the 1st request is in flight is successful.
TestingOAuth2TokenServiceConsumer consumer2;
scoped_ptr<OAuth2TokenService::Request> request2(
- oauth2_service_->StartRequest(scopes, &consumer2));
+ oauth2_service_->StartRequest(account_id_, scopes, &consumer2));
base::RunLoop().RunUntilIdle();
net::TestURLFetcher* fetcher2 = factory_.GetFetcherByID(0);
@@ -383,7 +398,7 @@ TEST_F(OAuth2TokenServiceTest,
TEST_F(OAuth2TokenServiceTest, ServiceShutDownBeforeFetchComplete) {
oauth2_service_->set_refresh_token("refreshToken");
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
- std::set<std::string>(), &consumer_));
+ account_id_, OAuth2TokenService::ScopeSet(), &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -397,9 +412,10 @@ TEST_F(OAuth2TokenServiceTest, ServiceShutDownBeforeFetchComplete) {
TEST_F(OAuth2TokenServiceTest, RetryingConsumer) {
oauth2_service_->set_refresh_token("refreshToken");
- RetryingTestingOAuth2TokenServiceConsumer consumer(oauth2_service_.get());
+ RetryingTestingOAuth2TokenServiceConsumer consumer(oauth2_service_.get(),
+ account_id_);
scoped_ptr<OAuth2TokenService::Request> request(oauth2_service_->StartRequest(
- std::set<std::string>(), &consumer));
+ account_id_, OAuth2TokenService::ScopeSet(), &consumer));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer.number_of_successful_tokens_);
EXPECT_EQ(0, consumer.number_of_errors_);
@@ -422,12 +438,12 @@ TEST_F(OAuth2TokenServiceTest, RetryingConsumer) {
}
TEST_F(OAuth2TokenServiceTest, InvalidateToken) {
- std::set<std::string> scopes;
+ OAuth2TokenService::ScopeSet scopes;
oauth2_service_->set_refresh_token("refreshToken");
// First request.
scoped_ptr<OAuth2TokenService::Request> request(
- oauth2_service_->StartRequest(scopes, &consumer_));
+ oauth2_service_->StartRequest(account_id_, scopes, &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
@@ -444,7 +460,7 @@ TEST_F(OAuth2TokenServiceTest, InvalidateToken) {
// Second request, should return the same token without needing a network
// request.
scoped_ptr<OAuth2TokenService::Request> request2(
- oauth2_service_->StartRequest(scopes, &consumer_));
+ oauth2_service_->StartRequest(account_id_, scopes, &consumer_));
base::RunLoop().RunUntilIdle();
// No new network fetcher.
@@ -456,7 +472,7 @@ TEST_F(OAuth2TokenServiceTest, InvalidateToken) {
// Invalidating the token should return a new token on the next request.
oauth2_service_->InvalidateToken(scopes, consumer_.last_token_);
scoped_ptr<OAuth2TokenService::Request> request3(
- oauth2_service_->StartRequest(scopes, &consumer_));
+ oauth2_service_->StartRequest(account_id_, scopes, &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(2, consumer_.number_of_successful_tokens_);
EXPECT_EQ(0, consumer_.number_of_errors_);
@@ -473,11 +489,13 @@ TEST_F(OAuth2TokenServiceTest, InvalidateToken) {
TEST_F(OAuth2TokenServiceTest, CancelAllRequests) {
oauth2_service_->set_refresh_token("refreshToken");
scoped_ptr<OAuth2TokenService::Request> request(
- oauth2_service_->StartRequest(std::set<std::string>(), &consumer_));
+ oauth2_service_->StartRequest(account_id_, OAuth2TokenService::ScopeSet(),
+ &consumer_));
oauth2_service_->set_refresh_token("refreshToken2");
scoped_ptr<OAuth2TokenService::Request> request2(
- oauth2_service_->StartRequest(std::set<std::string>(), &consumer_));
+ oauth2_service_->StartRequest(account_id_, OAuth2TokenService::ScopeSet(),
+ &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);
@@ -490,21 +508,22 @@ TEST_F(OAuth2TokenServiceTest, CancelAllRequests) {
}
TEST_F(OAuth2TokenServiceTest, CancelRequestsForToken) {
- std::set<std::string> scope_set_1;
+ OAuth2TokenService::ScopeSet scope_set_1;
scope_set_1.insert("scope1");
scope_set_1.insert("scope2");
- std::set<std::string> scope_set_2(scope_set_1.begin(), scope_set_1.end());
+ OAuth2TokenService::ScopeSet scope_set_2(scope_set_1.begin(),
+ scope_set_1.end());
scope_set_2.insert("scope3");
oauth2_service_->set_refresh_token("refreshToken");
scoped_ptr<OAuth2TokenService::Request> request1(
- oauth2_service_->StartRequest(scope_set_1, &consumer_));
+ oauth2_service_->StartRequest(account_id_, scope_set_1, &consumer_));
scoped_ptr<OAuth2TokenService::Request> request2(
- oauth2_service_->StartRequest(scope_set_2, &consumer_));
+ oauth2_service_->StartRequest(account_id_, scope_set_2, &consumer_));
oauth2_service_->set_refresh_token("refreshToken2");
scoped_ptr<OAuth2TokenService::Request> request3(
- oauth2_service_->StartRequest(scope_set_1, &consumer_));
+ oauth2_service_->StartRequest(account_id_, scope_set_1, &consumer_));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, consumer_.number_of_successful_tokens_);

Powered by Google App Engine
This is Rietveld 408576698