| OLD | NEW |
| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 account_id_, OAuth2TokenService::ScopeSet(), this).release()); | 40 account_id_, OAuth2TokenService::ScopeSet(), this).release()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 OAuth2TokenService* oauth2_service_; | 43 OAuth2TokenService* oauth2_service_; |
| 44 std::string account_id_; | 44 std::string account_id_; |
| 45 std::unique_ptr<OAuth2TokenService::Request> request_; | 45 std::unique_ptr<OAuth2TokenService::Request> request_; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 class TestOAuth2TokenService : public OAuth2TokenService { | 48 class TestOAuth2TokenService : public OAuth2TokenService { |
| 49 public: | 49 public: |
| 50 explicit TestOAuth2TokenService(FakeOAuth2TokenServiceDelegate* delegate) | 50 explicit TestOAuth2TokenService( |
| 51 : OAuth2TokenService(delegate) {} | 51 std::unique_ptr<FakeOAuth2TokenServiceDelegate> delegate) |
| 52 : OAuth2TokenService(std::move(delegate)) {} |
| 52 | 53 |
| 53 void CancelAllRequestsForTest() { CancelAllRequests(); } | 54 void CancelAllRequestsForTest() { CancelAllRequests(); } |
| 54 | 55 |
| 55 void CancelRequestsForAccountForTest(const std::string& account_id) { | 56 void CancelRequestsForAccountForTest(const std::string& account_id) { |
| 56 CancelRequestsForAccount(account_id); | 57 CancelRequestsForAccount(account_id); |
| 57 } | 58 } |
| 58 | 59 |
| 59 FakeOAuth2TokenServiceDelegate* GetFakeOAuth2TokenServiceDelegate() { | 60 FakeOAuth2TokenServiceDelegate* GetFakeOAuth2TokenServiceDelegate() { |
| 60 return static_cast<FakeOAuth2TokenServiceDelegate*>(GetDelegate()); | 61 return static_cast<FakeOAuth2TokenServiceDelegate*>(GetDelegate()); |
| 61 } | 62 } |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 class OAuth2TokenServiceTest : public testing::Test { | 65 class OAuth2TokenServiceTest : public testing::Test { |
| 65 public: | 66 public: |
| 66 void SetUp() override { | 67 void SetUp() override { |
| 67 oauth2_service_.reset(new TestOAuth2TokenService( | 68 oauth2_service_.reset(new TestOAuth2TokenService( |
| 68 new FakeOAuth2TokenServiceDelegate(new net::TestURLRequestContextGetter( | 69 base::MakeUnique<FakeOAuth2TokenServiceDelegate>( |
| 69 message_loop_.task_runner())))); | 70 new net::TestURLRequestContextGetter( |
| 71 message_loop_.task_runner())))); |
| 70 account_id_ = "test_user@gmail.com"; | 72 account_id_ = "test_user@gmail.com"; |
| 71 } | 73 } |
| 72 | 74 |
| 73 void TearDown() override { | 75 void TearDown() override { |
| 74 // Makes sure that all the clean up tasks are run. | 76 // Makes sure that all the clean up tasks are run. |
| 75 base::RunLoop().RunUntilIdle(); | 77 base::RunLoop().RunUntilIdle(); |
| 76 } | 78 } |
| 77 | 79 |
| 78 protected: | 80 protected: |
| 79 base::MessageLoopForIO message_loop_; // net:: stuff needs IO message loop. | 81 base::MessageLoopForIO message_loop_; // net:: stuff needs IO message loop. |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 fetcher = factory_.GetFetcherByID(0); | 662 fetcher = factory_.GetFetcherByID(0); |
| 661 // ASSERT_TRUE(fetcher); | 663 // ASSERT_TRUE(fetcher); |
| 662 fetcher->set_response_code(net::HTTP_OK); | 664 fetcher->set_response_code(net::HTTP_OK); |
| 663 fetcher->SetResponseString(GetValidTokenResponse("another token", 3600)); | 665 fetcher->SetResponseString(GetValidTokenResponse("another token", 3600)); |
| 664 fetcher->delegate()->OnURLFetchComplete(fetcher); | 666 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 665 EXPECT_EQ(2, consumer_.number_of_successful_tokens_); | 667 EXPECT_EQ(2, consumer_.number_of_successful_tokens_); |
| 666 EXPECT_EQ(0, consumer_.number_of_errors_); | 668 EXPECT_EQ(0, consumer_.number_of_errors_); |
| 667 EXPECT_EQ("another token", consumer_.last_token_); | 669 EXPECT_EQ("another token", consumer_.last_token_); |
| 668 EXPECT_EQ(1, (int)oauth2_service_->token_cache_.size()); | 670 EXPECT_EQ(1, (int)oauth2_service_->token_cache_.size()); |
| 669 } | 671 } |
| OLD | NEW |