Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/signin/ubertoken_fetcher.h" | 5 #include "chrome/browser/signin/ubertoken_fetcher.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 8 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
| 9 #include "chrome/browser/signin/fake_signin_manager.h" | 9 #include "chrome/browser/signin/fake_signin_manager.h" |
| 10 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 10 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 12 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 13 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 14 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "google_apis/gaia/gaia_constants.h" | 14 #include "google_apis/gaia/gaia_constants.h" |
| 16 #include "net/url_request/test_url_fetcher_factory.h" | 15 #include "net/url_request/test_url_fetcher_factory.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 const char kTestAccountId[] = "test@gmail.com"; | 20 const char kTestAccountId[] = "test@gmail.com"; |
| 22 | 21 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 } | 62 } |
| 64 | 63 |
| 65 virtual void TearDown() OVERRIDE { | 64 virtual void TearDown() OVERRIDE { |
| 66 fetcher_.reset(); | 65 fetcher_.reset(); |
| 67 } | 66 } |
| 68 | 67 |
| 69 TestingProfile* profile() { return profile_.get(); } | 68 TestingProfile* profile() { return profile_.get(); } |
| 70 | 69 |
| 71 protected: | 70 protected: |
| 72 content::TestBrowserThreadBundle thread_bundle_; | 71 content::TestBrowserThreadBundle thread_bundle_; |
| 73 scoped_ptr<TestingProfile> profile_; | 72 scoped_ptr<TestingProfile> profile_; |
|
Roger Tawa OOO till Jul 10th
2014/01/10 00:08:14
It would be good to get rid of Profile here. Its
blundell
2014/01/10 09:02:03
Mihai and I discussed this earlier yesterday and c
| |
| 74 net::TestURLFetcherFactory factory_; | 73 net::TestURLFetcherFactory factory_; |
| 75 MockUbertokenConsumer consumer_; | 74 MockUbertokenConsumer consumer_; |
| 76 scoped_ptr<UbertokenFetcher> fetcher_; | 75 scoped_ptr<UbertokenFetcher> fetcher_; |
| 77 }; | 76 }; |
| 78 | 77 |
| 79 TEST_F(UbertokenFetcherTest, Basic) { | 78 TEST_F(UbertokenFetcherTest, Basic) { |
| 80 } | 79 } |
| 81 | 80 |
| 82 TEST_F(UbertokenFetcherTest, Success) { | 81 TEST_F(UbertokenFetcherTest, Success) { |
| 83 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())-> | 82 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())-> |
| 84 UpdateCredentials(kTestAccountId, "refreshToken"); | 83 UpdateCredentials(kTestAccountId, "refreshToken"); |
| 85 fetcher_->StartFetchingToken(); | 84 fetcher_->StartFetchingToken(kTestAccountId); |
| 86 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time()); | 85 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time()); |
| 87 fetcher_->OnUberAuthTokenSuccess("uberToken"); | 86 fetcher_->OnUberAuthTokenSuccess("uberToken"); |
| 88 EXPECT_EQ(0, consumer_.nb_error_); | 87 EXPECT_EQ(0, consumer_.nb_error_); |
| 89 EXPECT_EQ(1, consumer_.nb_correct_token_); | 88 EXPECT_EQ(1, consumer_.nb_correct_token_); |
| 90 EXPECT_EQ("uberToken", consumer_.last_token_); | 89 EXPECT_EQ("uberToken", consumer_.last_token_); |
| 91 } | 90 } |
| 92 | 91 |
| 93 TEST_F(UbertokenFetcherTest, NoRefreshToken) { | 92 TEST_F(UbertokenFetcherTest, NoRefreshToken) { |
| 94 fetcher_->StartFetchingToken(); | 93 fetcher_->StartFetchingToken(kTestAccountId); |
| 95 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); | 94 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); |
| 96 fetcher_->OnGetTokenFailure(NULL, error); | 95 fetcher_->OnGetTokenFailure(NULL, error); |
| 97 EXPECT_EQ(1, consumer_.nb_error_); | 96 EXPECT_EQ(1, consumer_.nb_error_); |
| 98 EXPECT_EQ(0, consumer_.nb_correct_token_); | 97 EXPECT_EQ(0, consumer_.nb_correct_token_); |
| 99 } | 98 } |
| 100 | 99 |
| 101 TEST_F(UbertokenFetcherTest, FailureToGetAccessToken) { | 100 TEST_F(UbertokenFetcherTest, FailureToGetAccessToken) { |
| 102 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); | 101 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); |
| 103 | 102 |
| 104 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())-> | 103 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())-> |
| 105 UpdateCredentials(kTestAccountId, "refreshToken"); | 104 UpdateCredentials(kTestAccountId, "refreshToken"); |
| 106 fetcher_->StartFetchingToken(); | 105 fetcher_->StartFetchingToken(kTestAccountId); |
| 107 fetcher_->OnGetTokenFailure(NULL, error); | 106 fetcher_->OnGetTokenFailure(NULL, error); |
| 108 | 107 |
| 109 EXPECT_EQ(1, consumer_.nb_error_); | 108 EXPECT_EQ(1, consumer_.nb_error_); |
| 110 EXPECT_EQ(0, consumer_.nb_correct_token_); | 109 EXPECT_EQ(0, consumer_.nb_correct_token_); |
| 111 EXPECT_EQ("", consumer_.last_token_); | 110 EXPECT_EQ("", consumer_.last_token_); |
| 112 } | 111 } |
| 113 | 112 |
| 114 TEST_F(UbertokenFetcherTest, FailureToGetUberToken) { | 113 TEST_F(UbertokenFetcherTest, FailureToGetUberToken) { |
| 115 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); | 114 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); |
| 116 | 115 |
| 117 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())-> | 116 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())-> |
| 118 UpdateCredentials(kTestAccountId, "refreshToken"); | 117 UpdateCredentials(kTestAccountId, "refreshToken"); |
| 119 fetcher_->StartFetchingToken(); | 118 fetcher_->StartFetchingToken(kTestAccountId); |
| 120 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time()); | 119 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time()); |
| 121 fetcher_->OnUberAuthTokenFailure(error); | 120 fetcher_->OnUberAuthTokenFailure(error); |
| 122 | 121 |
| 123 EXPECT_EQ(1, consumer_.nb_error_); | 122 EXPECT_EQ(1, consumer_.nb_error_); |
| 124 EXPECT_EQ(0, consumer_.nb_correct_token_); | 123 EXPECT_EQ(0, consumer_.nb_correct_token_); |
| 125 EXPECT_EQ("", consumer_.last_token_); | 124 EXPECT_EQ("", consumer_.last_token_); |
| 126 } | 125 } |
| OLD | NEW |