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

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

Issue 131973004: Eliminate usage of PO2TS::GetPrimaryAccountID() in UbertokenFetcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile failure 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 "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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/ubertoken_fetcher.cc ('k') | chrome/browser/ui/auto_login_infobar_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698