| OLD | NEW |
| 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" |
| 11 #include "google_apis/gaia/gaia_constants.h" | 11 #include "google_apis/gaia/gaia_constants.h" |
| 12 #include "net/url_request/test_url_fetcher_factory.h" | 12 #include "net/url_request/test_url_fetcher_factory.h" |
| 13 #include "net/url_request/url_request_test_util.h" | 13 #include "net/url_request/url_request_test_util.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const char kTestAccountId[] = "test@gmail.com"; | 18 const char kTestAccountId[] = "test@gmail.com"; |
| 19 | 19 |
| 20 class MockUbertokenConsumer : public UbertokenConsumer { | 20 class MockUbertokenConsumer : public UbertokenConsumer { |
| 21 public: | 21 public: |
| 22 MockUbertokenConsumer() | 22 MockUbertokenConsumer() |
| 23 : nb_correct_token_(0), | 23 : nb_correct_token_(0), |
| 24 last_error_(GoogleServiceAuthError::AuthErrorNone()), | 24 last_error_(GoogleServiceAuthError::AuthErrorNone()), |
| 25 nb_error_(0) { | 25 nb_error_(0) { |
| 26 } | 26 } |
| 27 virtual ~MockUbertokenConsumer() {} | 27 ~MockUbertokenConsumer() override {} |
| 28 | 28 |
| 29 virtual void OnUbertokenSuccess(const std::string& token) override { | 29 void OnUbertokenSuccess(const std::string& token) override { |
| 30 last_token_ = token; | 30 last_token_ = token; |
| 31 ++ nb_correct_token_; | 31 ++ nb_correct_token_; |
| 32 } | 32 } |
| 33 | 33 |
| 34 virtual void OnUbertokenFailure(const GoogleServiceAuthError& error) | 34 void OnUbertokenFailure(const GoogleServiceAuthError& error) override { |
| 35 override { | |
| 36 last_error_ = error; | 35 last_error_ = error; |
| 37 ++nb_error_; | 36 ++nb_error_; |
| 38 } | 37 } |
| 39 | 38 |
| 40 std::string last_token_; | 39 std::string last_token_; |
| 41 int nb_correct_token_; | 40 int nb_correct_token_; |
| 42 GoogleServiceAuthError last_error_; | 41 GoogleServiceAuthError last_error_; |
| 43 int nb_error_; | 42 int nb_error_; |
| 44 }; | 43 }; |
| 45 | 44 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 EXPECT_EQ(0, consumer_.nb_error_); | 162 EXPECT_EQ(0, consumer_.nb_error_); |
| 164 EXPECT_EQ(0, consumer_.nb_correct_token_); | 163 EXPECT_EQ(0, consumer_.nb_correct_token_); |
| 165 EXPECT_EQ("", consumer_.last_token_); | 164 EXPECT_EQ("", consumer_.last_token_); |
| 166 | 165 |
| 167 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time()); | 166 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time()); |
| 168 fetcher_->OnUberAuthTokenSuccess("uberToken"); | 167 fetcher_->OnUberAuthTokenSuccess("uberToken"); |
| 169 EXPECT_EQ(0, consumer_.nb_error_); | 168 EXPECT_EQ(0, consumer_.nb_error_); |
| 170 EXPECT_EQ(1, consumer_.nb_correct_token_); | 169 EXPECT_EQ(1, consumer_.nb_correct_token_); |
| 171 EXPECT_EQ("uberToken", consumer_.last_token_); | 170 EXPECT_EQ("uberToken", consumer_.last_token_); |
| 172 } | 171 } |
| OLD | NEW |