OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "base/stringprintf.h" | 5 #include "base/stringprintf.h" |
6 #include "chrome/browser/signin/oauth2_token_service.h" | 6 #include "chrome/browser/signin/oauth2_token_service.h" |
7 #include "chrome/browser/signin/oauth2_token_service_factory.h" | 7 #include "chrome/browser/signin/oauth2_token_service_factory.h" |
8 #include "chrome/browser/signin/token_service_factory.h" | 8 #include "chrome/browser/signin/token_service_factory.h" |
9 #include "chrome/browser/signin/token_service_unittest.h" | 9 #include "chrome/browser/signin/token_service_unittest.h" |
10 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 std::string last_token_; | 55 std::string last_token_; |
56 int number_of_correct_tokens_; | 56 int number_of_correct_tokens_; |
57 GoogleServiceAuthError last_error_; | 57 GoogleServiceAuthError last_error_; |
58 int number_of_errors_; | 58 int number_of_errors_; |
59 }; | 59 }; |
60 | 60 |
61 // A testing consumer that retries on error. | 61 // A testing consumer that retries on error. |
62 class RetryingTestingOAuth2TokenServiceConsumer | 62 class RetryingTestingOAuth2TokenServiceConsumer |
63 : public OAuth2TokenService::Consumer { | 63 : public OAuth2TokenService::Consumer { |
64 public: | 64 public: |
65 RetryingTestingOAuth2TokenServiceConsumer( | 65 explicit RetryingTestingOAuth2TokenServiceConsumer( |
66 OAuth2TokenService* oauth2_service) | 66 OAuth2TokenService* oauth2_service) |
67 : oauth2_service_(oauth2_service), | 67 : oauth2_service_(oauth2_service), |
68 number_of_correct_tokens_(0), | 68 number_of_correct_tokens_(0), |
69 last_error_(GoogleServiceAuthError::None()), | 69 last_error_(GoogleServiceAuthError::None()), |
70 number_of_errors_(0) {} | 70 number_of_errors_(0) {} |
71 virtual ~RetryingTestingOAuth2TokenServiceConsumer() {} | 71 virtual ~RetryingTestingOAuth2TokenServiceConsumer() {} |
72 | 72 |
73 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 73 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
74 const std::string& token, | 74 const std::string& token, |
75 const base::Time& expiration_date) OVERRIDE { | 75 const base::Time& expiration_date) OVERRIDE { |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 EXPECT_EQ(1, consumer.number_of_errors_); | 492 EXPECT_EQ(1, consumer.number_of_errors_); |
493 | 493 |
494 fetcher = factory_.GetFetcherByID(0); | 494 fetcher = factory_.GetFetcherByID(0); |
495 EXPECT_TRUE(fetcher); | 495 EXPECT_TRUE(fetcher); |
496 fetcher->set_response_code(net::HTTP_UNAUTHORIZED); | 496 fetcher->set_response_code(net::HTTP_UNAUTHORIZED); |
497 fetcher->SetResponseString(""); | 497 fetcher->SetResponseString(""); |
498 fetcher->delegate()->OnURLFetchComplete(fetcher); | 498 fetcher->delegate()->OnURLFetchComplete(fetcher); |
499 EXPECT_EQ(0, consumer.number_of_correct_tokens_); | 499 EXPECT_EQ(0, consumer.number_of_correct_tokens_); |
500 EXPECT_EQ(2, consumer.number_of_errors_); | 500 EXPECT_EQ(2, consumer.number_of_errors_); |
501 } | 501 } |
OLD | NEW |