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

Side by Side Diff: chrome/browser/signin/ubertoken_fetcher_unittest.cc

Issue 71723002: This is the second CL of several that will eventually replace TokenService with (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Undo change to SigninTracker Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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_factory.h" 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
11 #include "chrome/browser/signin/signin_manager_factory.h" 12 #include "chrome/browser/signin/signin_manager_factory.h"
12 #include "chrome/browser/signin/token_service_unittest.h" 13 #include "chrome/browser/signin/token_service_unittest.h"
fgorski 2013/11/13 20:36:48 Is this include still needed?
Roger Tawa OOO till Jul 10th 2013/11/13 20:56:12 Done.
14 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "google_apis/gaia/gaia_constants.h" 16 #include "google_apis/gaia/gaia_constants.h"
14 #include "net/url_request/test_url_fetcher_factory.h" 17 #include "net/url_request/test_url_fetcher_factory.h"
15 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
16 19
17 namespace { 20 namespace {
18 21
22 const char kTestAccountId[] = "test@gmail.com";
23
19 class MockUbertokenConsumer : public UbertokenConsumer { 24 class MockUbertokenConsumer : public UbertokenConsumer {
20 public: 25 public:
21 MockUbertokenConsumer() 26 MockUbertokenConsumer()
22 : nb_correct_token_(0), 27 : nb_correct_token_(0),
23 last_error_(GoogleServiceAuthError::AuthErrorNone()), 28 last_error_(GoogleServiceAuthError::AuthErrorNone()),
24 nb_error_(0) { 29 nb_error_(0) {
25 } 30 }
26 virtual ~MockUbertokenConsumer() {} 31 virtual ~MockUbertokenConsumer() {}
27 32
28 virtual void OnUbertokenSuccess(const std::string& token) OVERRIDE { 33 virtual void OnUbertokenSuccess(const std::string& token) OVERRIDE {
29 last_token_ = token; 34 last_token_ = token;
30 ++ nb_correct_token_; 35 ++ nb_correct_token_;
31 } 36 }
32 37
33 virtual void OnUbertokenFailure(const GoogleServiceAuthError& error) 38 virtual void OnUbertokenFailure(const GoogleServiceAuthError& error)
34 OVERRIDE { 39 OVERRIDE {
35 last_error_ = error; 40 last_error_ = error;
36 ++nb_error_; 41 ++nb_error_;
37 } 42 }
38 43
39 std::string last_token_; 44 std::string last_token_;
40 int nb_correct_token_; 45 int nb_correct_token_;
41 GoogleServiceAuthError last_error_; 46 GoogleServiceAuthError last_error_;
42 int nb_error_; 47 int nb_error_;
43 }; 48 };
44 49
45 } // namespace 50 } // namespace
46 51
47 class UbertokenFetcherTest : public TokenServiceTestHarness { 52 class UbertokenFetcherTest : public testing::Test {
48 public: 53 public:
49 virtual void SetUp() OVERRIDE { 54 virtual void SetUp() OVERRIDE {
50 TokenServiceTestHarness::SetUp(); 55 profile_.reset(new TestingProfile());
51 UpdateCredentialsOnService();
52 fetcher_.reset(new UbertokenFetcher(profile(), &consumer_)); 56 fetcher_.reset(new UbertokenFetcher(profile(), &consumer_));
53 CreateSigninManager("test@gmail.com");
54 } 57 }
55 58
56 virtual scoped_ptr<TestingProfile> CreateProfile() OVERRIDE { 59 scoped_ptr<TestingProfile> CreateProfile() {
57 TestingProfile::Builder builder; 60 TestingProfile::Builder builder;
58 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), 61 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
59 &FakeProfileOAuth2TokenService::Build); 62 &FakeProfileOAuth2TokenService::Build);
60 return builder.Build().Pass(); 63 return builder.Build().Pass();
61 } 64 }
62 65
63 virtual void TearDown() OVERRIDE { 66 virtual void TearDown() OVERRIDE {
64 fetcher_.reset(); 67 fetcher_.reset();
65 TokenServiceTestHarness::TearDown();
66 } 68 }
67 69
70 TestingProfile* profile() { return profile_.get(); }
71
68 protected: 72 protected:
73 content::TestBrowserThreadBundle thread_bundle_;
74 scoped_ptr<TestingProfile> profile_;
69 net::TestURLFetcherFactory factory_; 75 net::TestURLFetcherFactory factory_;
70 MockUbertokenConsumer consumer_; 76 MockUbertokenConsumer consumer_;
71 scoped_ptr<UbertokenFetcher> fetcher_; 77 scoped_ptr<UbertokenFetcher> fetcher_;
72 }; 78 };
73 79
74 TEST_F(UbertokenFetcherTest, Basic) { 80 TEST_F(UbertokenFetcherTest, Basic) {
75 } 81 }
76 82
77 TEST_F(UbertokenFetcherTest, Success) { 83 TEST_F(UbertokenFetcherTest, Success) {
78 service()->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken, 84 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())->
79 "refreshToken"); 85 UpdateCredentials(kTestAccountId, "refreshToken");
80 fetcher_->StartFetchingToken(); 86 fetcher_->StartFetchingToken();
81 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time()); 87 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time());
82 fetcher_->OnUberAuthTokenSuccess("uberToken"); 88 fetcher_->OnUberAuthTokenSuccess("uberToken");
83 EXPECT_EQ(0, consumer_.nb_error_); 89 EXPECT_EQ(0, consumer_.nb_error_);
84 EXPECT_EQ(1, consumer_.nb_correct_token_); 90 EXPECT_EQ(1, consumer_.nb_correct_token_);
85 EXPECT_EQ("uberToken", consumer_.last_token_); 91 EXPECT_EQ("uberToken", consumer_.last_token_);
86 } 92 }
87 93
88 TEST_F(UbertokenFetcherTest, NoRefreshToken) { 94 TEST_F(UbertokenFetcherTest, NoRefreshToken) {
89 fetcher_->StartFetchingToken(); 95 fetcher_->StartFetchingToken();
90 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); 96 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP);
91 fetcher_->OnGetTokenFailure(NULL, error); 97 fetcher_->OnGetTokenFailure(NULL, error);
92 EXPECT_EQ(1, consumer_.nb_error_); 98 EXPECT_EQ(1, consumer_.nb_error_);
93 EXPECT_EQ(0, consumer_.nb_correct_token_); 99 EXPECT_EQ(0, consumer_.nb_correct_token_);
94 } 100 }
95 101
96 TEST_F(UbertokenFetcherTest, FailureToGetAccessToken) { 102 TEST_F(UbertokenFetcherTest, FailureToGetAccessToken) {
97 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); 103 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP);
98 104
99 service()->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken, 105 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())->
100 "refreshToken"); 106 UpdateCredentials(kTestAccountId, "refreshToken");
101 fetcher_->StartFetchingToken(); 107 fetcher_->StartFetchingToken();
102 fetcher_->OnGetTokenFailure(NULL, error); 108 fetcher_->OnGetTokenFailure(NULL, error);
103 109
104 EXPECT_EQ(1, consumer_.nb_error_); 110 EXPECT_EQ(1, consumer_.nb_error_);
105 EXPECT_EQ(0, consumer_.nb_correct_token_); 111 EXPECT_EQ(0, consumer_.nb_correct_token_);
106 EXPECT_EQ("", consumer_.last_token_); 112 EXPECT_EQ("", consumer_.last_token_);
107 } 113 }
108 114
109 TEST_F(UbertokenFetcherTest, FailureToGetUberToken) { 115 TEST_F(UbertokenFetcherTest, FailureToGetUberToken) {
110 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); 116 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP);
111 117
112 service()->IssueAuthTokenForTest(GaiaConstants::kGaiaOAuth2LoginRefreshToken, 118 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())->
113 "refreshToken"); 119 UpdateCredentials(kTestAccountId, "refreshToken");
114 fetcher_->StartFetchingToken(); 120 fetcher_->StartFetchingToken();
115 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time()); 121 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time());
116 fetcher_->OnUberAuthTokenFailure(error); 122 fetcher_->OnUberAuthTokenFailure(error);
117 123
118 EXPECT_EQ(1, consumer_.nb_error_); 124 EXPECT_EQ(1, consumer_.nb_error_);
119 EXPECT_EQ(0, consumer_.nb_correct_token_); 125 EXPECT_EQ(0, consumer_.nb_correct_token_);
120 EXPECT_EQ("", consumer_.last_token_); 126 EXPECT_EQ("", consumer_.last_token_);
121 } 127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698