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

Side by Side Diff: google_apis/gaia/ubertoken_fetcher_unittest.cc

Issue 597003002: UbertokenFecther should invalidate access token if it's invalid. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@z359700
Patch Set: Refactor init Created 6 years, 2 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
« no previous file with comments | « google_apis/gaia/ubertoken_fetcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "google_apis/gaia/ubertoken_fetcher.h" 5 #include "google_apis/gaia/ubertoken_fetcher.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "google_apis/gaia/fake_oauth2_token_service.h" 10 #include "google_apis/gaia/fake_oauth2_token_service.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 TEST_F(UbertokenFetcherTest, FailureToGetAccessToken) { 93 TEST_F(UbertokenFetcherTest, FailureToGetAccessToken) {
94 fetcher_->StartFetchingToken(kTestAccountId); 94 fetcher_->StartFetchingToken(kTestAccountId);
95 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); 95 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP);
96 fetcher_->OnGetTokenFailure(NULL, error); 96 fetcher_->OnGetTokenFailure(NULL, error);
97 97
98 EXPECT_EQ(1, consumer_.nb_error_); 98 EXPECT_EQ(1, consumer_.nb_error_);
99 EXPECT_EQ(0, consumer_.nb_correct_token_); 99 EXPECT_EQ(0, consumer_.nb_correct_token_);
100 EXPECT_EQ("", consumer_.last_token_); 100 EXPECT_EQ("", consumer_.last_token_);
101 } 101 }
102 102
103 TEST_F(UbertokenFetcherTest, FailureToGetUberToken) { 103 TEST_F(UbertokenFetcherTest, TransientFailureEventualFailure) {
104 fetcher_->StartFetchingToken(kTestAccountId); 104 fetcher_->StartFetchingToken(kTestAccountId);
105 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); 105 GoogleServiceAuthError error(GoogleServiceAuthError::CONNECTION_FAILED);
106 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time()); 106 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time());
107
108 for (int i = 0; i < UbertokenFetcher::kMaxRetries; ++i) {
109 fetcher_->OnUberAuthTokenFailure(error);
110 EXPECT_EQ(0, consumer_.nb_error_);
111 EXPECT_EQ(0, consumer_.nb_correct_token_);
112 EXPECT_EQ("", consumer_.last_token_);
113 }
114
107 fetcher_->OnUberAuthTokenFailure(error); 115 fetcher_->OnUberAuthTokenFailure(error);
108
109 EXPECT_EQ(1, consumer_.nb_error_); 116 EXPECT_EQ(1, consumer_.nb_error_);
110 EXPECT_EQ(0, consumer_.nb_correct_token_); 117 EXPECT_EQ(0, consumer_.nb_correct_token_);
111 EXPECT_EQ("", consumer_.last_token_); 118 EXPECT_EQ("", consumer_.last_token_);
112 } 119 }
120
121 TEST_F(UbertokenFetcherTest, TransientFailureEventualSuccess) {
122 fetcher_->StartFetchingToken(kTestAccountId);
123 GoogleServiceAuthError error(GoogleServiceAuthError::CONNECTION_FAILED);
124 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time());
125
126 for (int i = 0; i < UbertokenFetcher::kMaxRetries; ++i) {
127 fetcher_->OnUberAuthTokenFailure(error);
128 EXPECT_EQ(0, consumer_.nb_error_);
129 EXPECT_EQ(0, consumer_.nb_correct_token_);
130 EXPECT_EQ("", consumer_.last_token_);
131 }
132
133 fetcher_->OnUberAuthTokenSuccess("uberToken");
134 EXPECT_EQ(0, consumer_.nb_error_);
135 EXPECT_EQ(1, consumer_.nb_correct_token_);
136 EXPECT_EQ("uberToken", consumer_.last_token_);
137 }
138
139 TEST_F(UbertokenFetcherTest, PermanentFailureEventualFailure) {
140 fetcher_->StartFetchingToken(kTestAccountId);
141 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time());
142
143 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP);
144 fetcher_->OnUberAuthTokenFailure(error);
145 EXPECT_EQ(0, consumer_.nb_error_);
146 EXPECT_EQ(0, consumer_.nb_correct_token_);
147 EXPECT_EQ("", consumer_.last_token_);
148
149 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time());
150 fetcher_->OnUberAuthTokenFailure(error);
151 EXPECT_EQ(1, consumer_.nb_error_);
152 EXPECT_EQ(0, consumer_.nb_correct_token_);
153 EXPECT_EQ("", consumer_.last_token_);
154 }
155
156 TEST_F(UbertokenFetcherTest, PermanentFailureEventualSuccess) {
157 fetcher_->StartFetchingToken(kTestAccountId);
158 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP);
159 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time());
160
161 fetcher_->OnUberAuthTokenFailure(error);
162 EXPECT_EQ(0, consumer_.nb_error_);
163 EXPECT_EQ(0, consumer_.nb_correct_token_);
164 EXPECT_EQ("", consumer_.last_token_);
165
166 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time());
167 fetcher_->OnUberAuthTokenSuccess("uberToken");
168 EXPECT_EQ(0, consumer_.nb_error_);
169 EXPECT_EQ(1, consumer_.nb_correct_token_);
170 EXPECT_EQ("uberToken", consumer_.last_token_);
171 }
OLDNEW
« no previous file with comments | « google_apis/gaia/ubertoken_fetcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698