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

Side by Side Diff: chrome/browser/local_discovery/privet_confirm_api_flow_unittest.cc

Issue 23382008: Making OAuth2TokenService multi-login aware, updating callers, minor fixes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updates to AndroidPO2TS and removing the DCHECK(signin_manager) from GetPrimaryAccountId Created 7 years, 3 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
OLDNEW
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "chrome/browser/local_discovery/privet_confirm_api_flow.h" 7 #include "chrome/browser/local_discovery/privet_confirm_api_flow.h"
8 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
8 #include "content/public/test/test_browser_thread.h" 9 #include "content/public/test/test_browser_thread.h"
9 #include "google_apis/gaia/google_service_auth_error.h" 10 #include "google_apis/gaia/google_service_auth_error.h"
10 #include "net/base/host_port_pair.h" 11 #include "net/base/host_port_pair.h"
11 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
12 #include "net/http/http_request_headers.h" 13 #include "net/http/http_request_headers.h"
13 #include "net/url_request/test_url_fetcher_factory.h" 14 #include "net/url_request/test_url_fetcher_factory.h"
14 #include "net/url_request/url_request_test_util.h" 15 #include "net/url_request/url_request_test_util.h"
15 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
(...skipping 14 matching lines...) Expand all
32 const char kFailedConfirmResponseBadJson[] = "[" 33 const char kFailedConfirmResponseBadJson[] = "["
33 " \"success\"" 34 " \"success\""
34 "]"; 35 "]";
35 36
36 class TestOAuth2TokenService : public OAuth2TokenService { 37 class TestOAuth2TokenService : public OAuth2TokenService {
37 public: 38 public:
38 explicit TestOAuth2TokenService(net::URLRequestContextGetter* request_context) 39 explicit TestOAuth2TokenService(net::URLRequestContextGetter* request_context)
39 : request_context_(request_context) { 40 : request_context_(request_context) {
40 } 41 }
41 protected: 42 protected:
42 virtual std::string GetRefreshToken() OVERRIDE { 43 virtual std::string GetRefreshToken(const std::string& account_id) OVERRIDE {
43 return "SampleToken"; 44 return "SampleToken";
44 } 45 }
45 46
46 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE { 47 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE {
47 return request_context_.get(); 48 return request_context_.get();
48 } 49 }
49 50
50 private: 51 private:
51 scoped_refptr<net::URLRequestContextGetter> request_context_; 52 scoped_refptr<net::URLRequestContextGetter> request_context_;
52 }; 53 };
(...skipping 27 matching lines...) Expand all
80 content::TestBrowserThread ui_thread_; 81 content::TestBrowserThread ui_thread_;
81 scoped_refptr<net::TestURLRequestContextGetter> request_context_; 82 scoped_refptr<net::TestURLRequestContextGetter> request_context_;
82 net::TestURLFetcherFactory fetcher_factory_; 83 net::TestURLFetcherFactory fetcher_factory_;
83 TestOAuth2TokenService token_service_; 84 TestOAuth2TokenService token_service_;
84 MockableConfirmCallback callback_; 85 MockableConfirmCallback callback_;
85 }; 86 };
86 87
87 TEST_F(PrivetConfirmApiFlowTest, SuccessOAuth2) { 88 TEST_F(PrivetConfirmApiFlowTest, SuccessOAuth2) {
88 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(), 89 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(),
89 &token_service_, 90 &token_service_,
91 std::string(),
Andrew T Wilson (Slow) 2013/09/03 14:04:24 This is fine - I just wonder if perhaps we want to
fgorski 2013/09/03 20:50:40 Done. I agree with you. Roger mentioned a potentia
90 GURL("http://SoMeUrL.com"), 92 GURL("http://SoMeUrL.com"),
91 callback_.callback()); 93 callback_.callback());
92 94
93 confirm_flow.Start(); 95 confirm_flow.Start();
94 96
95 confirm_flow.OnGetTokenSuccess(NULL, "SomeToken", base::Time()); 97 confirm_flow.OnGetTokenSuccess(NULL, "SomeToken", base::Time());
96 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); 98 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
97 99
98 EXPECT_EQ(GURL("http://SoMeUrL.com"), fetcher->GetOriginalURL()); 100 EXPECT_EQ(GURL("http://SoMeUrL.com"), fetcher->GetOriginalURL());
99 101
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 fetcher->set_response_code(200); 144 fetcher->set_response_code(200);
143 145
144 EXPECT_CALL(callback_, ConfirmCallback(PrivetConfirmApiCallFlow::SUCCESS)); 146 EXPECT_CALL(callback_, ConfirmCallback(PrivetConfirmApiCallFlow::SUCCESS));
145 147
146 fetcher->delegate()->OnURLFetchComplete(fetcher); 148 fetcher->delegate()->OnURLFetchComplete(fetcher);
147 } 149 }
148 150
149 TEST_F(PrivetConfirmApiFlowTest, BadToken) { 151 TEST_F(PrivetConfirmApiFlowTest, BadToken) {
150 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(), 152 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(),
151 &token_service_, 153 &token_service_,
154 std::string(),
152 GURL("http://SoMeUrL.com"), 155 GURL("http://SoMeUrL.com"),
153 callback_.callback()); 156 callback_.callback());
154 157
155 confirm_flow.Start(); 158 confirm_flow.Start();
156 159
157 EXPECT_CALL(callback_, 160 EXPECT_CALL(callback_,
158 ConfirmCallback(PrivetConfirmApiCallFlow::ERROR_TOKEN)); 161 ConfirmCallback(PrivetConfirmApiCallFlow::ERROR_TOKEN));
159 confirm_flow.OnGetTokenFailure(NULL, GoogleServiceAuthError( 162 confirm_flow.OnGetTokenFailure(NULL, GoogleServiceAuthError(
160 GoogleServiceAuthError::USER_NOT_SIGNED_UP)); 163 GoogleServiceAuthError::USER_NOT_SIGNED_UP));
161 } 164 }
162 165
163 TEST_F(PrivetConfirmApiFlowTest, ServerFailure) { 166 TEST_F(PrivetConfirmApiFlowTest, ServerFailure) {
164 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(), 167 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(),
165 &token_service_, 168 &token_service_,
169 std::string(),
166 GURL("http://SoMeUrL.com"), 170 GURL("http://SoMeUrL.com"),
167 callback_.callback()); 171 callback_.callback());
168 172
169 confirm_flow.Start(); 173 confirm_flow.Start();
170 174
171 confirm_flow.OnGetTokenSuccess(NULL, "SomeToken", base::Time()); 175 confirm_flow.OnGetTokenSuccess(NULL, "SomeToken", base::Time());
172 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); 176 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
173 177
174 EXPECT_EQ(GURL("http://SoMeUrL.com"), fetcher->GetOriginalURL()); 178 EXPECT_EQ(GURL("http://SoMeUrL.com"), fetcher->GetOriginalURL());
175 179
176 fetcher->SetResponseString(kFailedConfirmResponse); 180 fetcher->SetResponseString(kFailedConfirmResponse);
177 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 181 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS,
178 net::OK)); 182 net::OK));
179 fetcher->set_response_code(200); 183 fetcher->set_response_code(200);
180 184
181 EXPECT_CALL(callback_, 185 EXPECT_CALL(callback_,
182 ConfirmCallback(PrivetConfirmApiCallFlow::ERROR_FROM_SERVER)); 186 ConfirmCallback(PrivetConfirmApiCallFlow::ERROR_FROM_SERVER));
183 187
184 fetcher->delegate()->OnURLFetchComplete(fetcher); 188 fetcher->delegate()->OnURLFetchComplete(fetcher);
185 } 189 }
186 190
187 TEST_F(PrivetConfirmApiFlowTest, BadJson) { 191 TEST_F(PrivetConfirmApiFlowTest, BadJson) {
188 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(), 192 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(),
189 &token_service_, 193 &token_service_,
194 std::string(),
190 GURL("http://SoMeUrL.com"), 195 GURL("http://SoMeUrL.com"),
191 callback_.callback()); 196 callback_.callback());
192 197
193 confirm_flow.Start(); 198 confirm_flow.Start();
194 199
195 confirm_flow.OnGetTokenSuccess(NULL, "SomeToken", base::Time()); 200 confirm_flow.OnGetTokenSuccess(NULL, "SomeToken", base::Time());
196 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); 201 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
197 202
198 EXPECT_EQ(GURL("http://SoMeUrL.com"), fetcher->GetOriginalURL()); 203 EXPECT_EQ(GURL("http://SoMeUrL.com"), fetcher->GetOriginalURL());
199 204
200 fetcher->SetResponseString(kFailedConfirmResponseBadJson); 205 fetcher->SetResponseString(kFailedConfirmResponseBadJson);
201 fetcher->set_status(net::URLRequestStatus( 206 fetcher->set_status(net::URLRequestStatus(
202 net::URLRequestStatus::SUCCESS, 207 net::URLRequestStatus::SUCCESS,
203 net::OK)); 208 net::OK));
204 fetcher->set_response_code(200); 209 fetcher->set_response_code(200);
205 210
206 EXPECT_CALL(callback_, ConfirmCallback 211 EXPECT_CALL(callback_, ConfirmCallback
207 (PrivetConfirmApiCallFlow::ERROR_MALFORMED_RESPONSE)); 212 (PrivetConfirmApiCallFlow::ERROR_MALFORMED_RESPONSE));
208 213
209 fetcher->delegate()->OnURLFetchComplete(fetcher); 214 fetcher->delegate()->OnURLFetchComplete(fetcher);
210 } 215 }
211 216
212 } // namespace 217 } // namespace
213 218
214 } // namespace local_discovery 219 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698