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

Side by Side Diff: google_apis/gaia/ubertoken_fetcher_unittest.cc

Issue 136723009: Move UbertokenFetcher from //chrome to //google_apis. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months 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 "google_apis/gaia/ubertoken_fetcher.h"
6 6
7 #include "base/memory/ref_counted.h"
7 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 9 #include "base/message_loop/message_loop.h"
9 #include "chrome/browser/signin/fake_signin_manager.h" 10 #include "google_apis/gaia/fake_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"
12 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "google_apis/gaia/gaia_constants.h" 11 #include "google_apis/gaia/gaia_constants.h"
15 #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"
16 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
17 15
18 namespace { 16 namespace {
19 17
20 const char kTestAccountId[] = "test@gmail.com"; 18 const char kTestAccountId[] = "test@gmail.com";
21 19
22 class MockUbertokenConsumer : public UbertokenConsumer { 20 class MockUbertokenConsumer : public UbertokenConsumer {
23 public: 21 public:
24 MockUbertokenConsumer() 22 MockUbertokenConsumer()
25 : nb_correct_token_(0), 23 : nb_correct_token_(0),
(...skipping 17 matching lines...) Expand all
43 int nb_correct_token_; 41 int nb_correct_token_;
44 GoogleServiceAuthError last_error_; 42 GoogleServiceAuthError last_error_;
45 int nb_error_; 43 int nb_error_;
46 }; 44 };
47 45
48 } // namespace 46 } // namespace
49 47
50 class UbertokenFetcherTest : public testing::Test { 48 class UbertokenFetcherTest : public testing::Test {
51 public: 49 public:
52 virtual void SetUp() OVERRIDE { 50 virtual void SetUp() OVERRIDE {
53 profile_ = CreateProfile(); 51 OAuth2TokenService* token_service = new FakeOAuth2TokenService();
54 fetcher_.reset(new UbertokenFetcher(profile(), &consumer_)); 52 request_context_getter_ = new net::TestURLRequestContextGetter(
55 } 53 base::MessageLoopProxy::current());
56 54 fetcher_.reset(new UbertokenFetcher(token_service,
57 scoped_ptr<TestingProfile> CreateProfile() { 55 &consumer_,
58 TestingProfile::Builder builder; 56 request_context_getter_.get()));
59 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
60 &FakeProfileOAuth2TokenService::Build);
61 return builder.Build().Pass();
62 } 57 }
63 58
64 virtual void TearDown() OVERRIDE { 59 virtual void TearDown() OVERRIDE {
65 fetcher_.reset(); 60 fetcher_.reset();
66 } 61 }
67 62
68 TestingProfile* profile() { return profile_.get(); }
69
70 protected: 63 protected:
71 content::TestBrowserThreadBundle thread_bundle_; 64 base::MessageLoop message_loop_;
72 scoped_ptr<TestingProfile> profile_;
73 net::TestURLFetcherFactory factory_; 65 net::TestURLFetcherFactory factory_;
66 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
74 MockUbertokenConsumer consumer_; 67 MockUbertokenConsumer consumer_;
75 scoped_ptr<UbertokenFetcher> fetcher_; 68 scoped_ptr<UbertokenFetcher> fetcher_;
76 }; 69 };
77 70
78 TEST_F(UbertokenFetcherTest, Basic) { 71 TEST_F(UbertokenFetcherTest, Basic) {
79 } 72 }
80 73
81 TEST_F(UbertokenFetcherTest, Success) { 74 TEST_F(UbertokenFetcherTest, Success) {
82 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())->
blundell 2014/01/15 12:09:51 These calls were no longer necessary once the acco
83 UpdateCredentials(kTestAccountId, "refreshToken");
84 fetcher_->StartFetchingToken(kTestAccountId); 75 fetcher_->StartFetchingToken(kTestAccountId);
85 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time()); 76 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time());
86 fetcher_->OnUberAuthTokenSuccess("uberToken"); 77 fetcher_->OnUberAuthTokenSuccess("uberToken");
78
87 EXPECT_EQ(0, consumer_.nb_error_); 79 EXPECT_EQ(0, consumer_.nb_error_);
88 EXPECT_EQ(1, consumer_.nb_correct_token_); 80 EXPECT_EQ(1, consumer_.nb_correct_token_);
89 EXPECT_EQ("uberToken", consumer_.last_token_); 81 EXPECT_EQ("uberToken", consumer_.last_token_);
90 } 82 }
91 83
92 TEST_F(UbertokenFetcherTest, NoRefreshToken) { 84 TEST_F(UbertokenFetcherTest, NoRefreshToken) {
93 fetcher_->StartFetchingToken(kTestAccountId); 85 fetcher_->StartFetchingToken(kTestAccountId);
94 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); 86 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP);
95 fetcher_->OnGetTokenFailure(NULL, error); 87 fetcher_->OnGetTokenFailure(NULL, error);
88
96 EXPECT_EQ(1, consumer_.nb_error_); 89 EXPECT_EQ(1, consumer_.nb_error_);
97 EXPECT_EQ(0, consumer_.nb_correct_token_); 90 EXPECT_EQ(0, consumer_.nb_correct_token_);
98 } 91 }
99 92
100 TEST_F(UbertokenFetcherTest, FailureToGetAccessToken) { 93 TEST_F(UbertokenFetcherTest, FailureToGetAccessToken) {
94 fetcher_->StartFetchingToken(kTestAccountId);
101 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); 95 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP);
102
103 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())->
104 UpdateCredentials(kTestAccountId, "refreshToken");
105 fetcher_->StartFetchingToken(kTestAccountId);
106 fetcher_->OnGetTokenFailure(NULL, error); 96 fetcher_->OnGetTokenFailure(NULL, error);
107 97
108 EXPECT_EQ(1, consumer_.nb_error_); 98 EXPECT_EQ(1, consumer_.nb_error_);
109 EXPECT_EQ(0, consumer_.nb_correct_token_); 99 EXPECT_EQ(0, consumer_.nb_correct_token_);
110 EXPECT_EQ("", consumer_.last_token_); 100 EXPECT_EQ("", consumer_.last_token_);
111 } 101 }
112 102
113 TEST_F(UbertokenFetcherTest, FailureToGetUberToken) { 103 TEST_F(UbertokenFetcherTest, FailureToGetUberToken) {
104 fetcher_->StartFetchingToken(kTestAccountId);
114 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); 105 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP);
115
116 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())->
117 UpdateCredentials(kTestAccountId, "refreshToken");
118 fetcher_->StartFetchingToken(kTestAccountId);
119 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time()); 106 fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time());
120 fetcher_->OnUberAuthTokenFailure(error); 107 fetcher_->OnUberAuthTokenFailure(error);
121 108
122 EXPECT_EQ(1, consumer_.nb_error_); 109 EXPECT_EQ(1, consumer_.nb_error_);
123 EXPECT_EQ(0, consumer_.nb_correct_token_); 110 EXPECT_EQ(0, consumer_.nb_correct_token_);
124 EXPECT_EQ("", consumer_.last_token_); 111 EXPECT_EQ("", consumer_.last_token_);
125 } 112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698