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

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: Created 7 years, 4 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 "content/public/test/test_browser_thread.h" 8 #include "content/public/test/test_browser_thread.h"
9 #include "google_apis/gaia/google_service_auth_error.h" 9 #include "google_apis/gaia/google_service_auth_error.h"
10 #include "net/base/host_port_pair.h" 10 #include "net/base/host_port_pair.h"
(...skipping 22 matching lines...) Expand all
33 const char kFailedConfirmResponseBadJson[] = "[" 33 const char kFailedConfirmResponseBadJson[] = "["
34 " \"success\"" 34 " \"success\""
35 "]"; 35 "]";
36 36
37 class TestOAuth2TokenService : public OAuth2TokenService { 37 class TestOAuth2TokenService : public OAuth2TokenService {
38 public: 38 public:
39 explicit TestOAuth2TokenService(net::URLRequestContextGetter* request_context) 39 explicit TestOAuth2TokenService(net::URLRequestContextGetter* request_context)
40 : request_context_(request_context) { 40 : request_context_(request_context) {
41 } 41 }
42 protected: 42 protected:
43 virtual std::string GetRefreshToken() OVERRIDE { 43 virtual std::string GetRefreshToken(const std::string& account_id) OVERRIDE {
44 return "SampleToken"; 44 return "SampleToken";
45 } 45 }
46 46
47 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE { 47 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE {
48 return request_context_.get(); 48 return request_context_.get();
49 } 49 }
50 50
51 private: 51 private:
52 scoped_refptr<net::URLRequestContextGetter> request_context_; 52 scoped_refptr<net::URLRequestContextGetter> request_context_;
53 }; 53 };
(...skipping 27 matching lines...) Expand all
81 content::TestBrowserThread ui_thread_; 81 content::TestBrowserThread ui_thread_;
82 scoped_refptr<net::TestURLRequestContextGetter> request_context_; 82 scoped_refptr<net::TestURLRequestContextGetter> request_context_;
83 net::TestURLFetcherFactory fetcher_factory_; 83 net::TestURLFetcherFactory fetcher_factory_;
84 TestOAuth2TokenService token_service_; 84 TestOAuth2TokenService token_service_;
85 MockableConfirmCallback callback_; 85 MockableConfirmCallback callback_;
86 }; 86 };
87 87
88 TEST_F(PrivetConfirmApiFlowTest, Success) { 88 TEST_F(PrivetConfirmApiFlowTest, Success) {
89 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(), 89 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(),
90 &token_service_, 90 &token_service_,
91 std::string(),
91 GURL("http://SoMeUrL.com"), 92 GURL("http://SoMeUrL.com"),
92 callback_.callback()); 93 callback_.callback());
93 94
94 confirm_flow.OnGetTokenSuccess(NULL, "SomeToken", base::Time()); 95 confirm_flow.OnGetTokenSuccess(NULL, "SomeToken", base::Time());
95 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); 96 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
96 97
97 EXPECT_EQ(GURL("http://SoMeUrL.com"), fetcher->GetOriginalURL()); 98 EXPECT_EQ(GURL("http://SoMeUrL.com"), fetcher->GetOriginalURL());
98 99
99 net::HttpRequestHeaders headers; 100 net::HttpRequestHeaders headers;
100 fetcher->GetExtraRequestHeaders(&headers); 101 fetcher->GetExtraRequestHeaders(&headers);
(...skipping 10 matching lines...) Expand all
111 fetcher->set_response_code(200); 112 fetcher->set_response_code(200);
112 113
113 EXPECT_CALL(callback_, ConfirmCallback(PrivetConfirmApiCallFlow::SUCCESS)); 114 EXPECT_CALL(callback_, ConfirmCallback(PrivetConfirmApiCallFlow::SUCCESS));
114 115
115 fetcher->delegate()->OnURLFetchComplete(fetcher); 116 fetcher->delegate()->OnURLFetchComplete(fetcher);
116 } 117 }
117 118
118 TEST_F(PrivetConfirmApiFlowTest, BadToken) { 119 TEST_F(PrivetConfirmApiFlowTest, BadToken) {
119 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(), 120 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(),
120 &token_service_, 121 &token_service_,
122 std::string(),
121 GURL("http://SoMeUrL.com"), 123 GURL("http://SoMeUrL.com"),
122 callback_.callback()); 124 callback_.callback());
123 125
124 EXPECT_CALL(callback_, 126 EXPECT_CALL(callback_,
125 ConfirmCallback(PrivetConfirmApiCallFlow::ERROR_TOKEN)); 127 ConfirmCallback(PrivetConfirmApiCallFlow::ERROR_TOKEN));
126 confirm_flow.OnGetTokenFailure(NULL, GoogleServiceAuthError( 128 confirm_flow.OnGetTokenFailure(NULL, GoogleServiceAuthError(
127 GoogleServiceAuthError::USER_NOT_SIGNED_UP)); 129 GoogleServiceAuthError::USER_NOT_SIGNED_UP));
128 } 130 }
129 131
130 TEST_F(PrivetConfirmApiFlowTest, ServerFailure) { 132 TEST_F(PrivetConfirmApiFlowTest, ServerFailure) {
131 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(), 133 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(),
132 &token_service_, 134 &token_service_,
135 std::string(),
133 GURL("http://SoMeUrL.com"), 136 GURL("http://SoMeUrL.com"),
134 callback_.callback()); 137 callback_.callback());
135 138
136 confirm_flow.OnGetTokenSuccess(NULL, "SomeToken", base::Time()); 139 confirm_flow.OnGetTokenSuccess(NULL, "SomeToken", base::Time());
137 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); 140 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
138 141
139 EXPECT_EQ(GURL("http://SoMeUrL.com"), fetcher->GetOriginalURL()); 142 EXPECT_EQ(GURL("http://SoMeUrL.com"), fetcher->GetOriginalURL());
140 143
141 fetcher->SetResponseString(kFailedConfirmResponse); 144 fetcher->SetResponseString(kFailedConfirmResponse);
142 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 145 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS,
143 net::OK)); 146 net::OK));
144 fetcher->set_response_code(200); 147 fetcher->set_response_code(200);
145 148
146 EXPECT_CALL(callback_, 149 EXPECT_CALL(callback_,
147 ConfirmCallback(PrivetConfirmApiCallFlow::ERROR_FROM_SERVER)); 150 ConfirmCallback(PrivetConfirmApiCallFlow::ERROR_FROM_SERVER));
148 151
149 fetcher->delegate()->OnURLFetchComplete(fetcher); 152 fetcher->delegate()->OnURLFetchComplete(fetcher);
150 } 153 }
151 154
152 TEST_F(PrivetConfirmApiFlowTest, BadJson) { 155 TEST_F(PrivetConfirmApiFlowTest, BadJson) {
153 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(), 156 PrivetConfirmApiCallFlow confirm_flow(request_context_.get(),
154 &token_service_, 157 &token_service_,
158 std::string(),
155 GURL("http://SoMeUrL.com"), 159 GURL("http://SoMeUrL.com"),
156 callback_.callback()); 160 callback_.callback());
157 161
158 confirm_flow.OnGetTokenSuccess(NULL, "SomeToken", base::Time()); 162 confirm_flow.OnGetTokenSuccess(NULL, "SomeToken", base::Time());
159 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); 163 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
160 164
161 EXPECT_EQ(GURL("http://SoMeUrL.com"), fetcher->GetOriginalURL()); 165 EXPECT_EQ(GURL("http://SoMeUrL.com"), fetcher->GetOriginalURL());
162 166
163 fetcher->SetResponseString(kFailedConfirmResponseBadJson); 167 fetcher->SetResponseString(kFailedConfirmResponseBadJson);
164 fetcher->set_status(net::URLRequestStatus( 168 fetcher->set_status(net::URLRequestStatus(
165 net::URLRequestStatus::SUCCESS, 169 net::URLRequestStatus::SUCCESS,
166 net::OK)); 170 net::OK));
167 fetcher->set_response_code(200); 171 fetcher->set_response_code(200);
168 172
169 EXPECT_CALL(callback_, ConfirmCallback 173 EXPECT_CALL(callback_, ConfirmCallback
170 (PrivetConfirmApiCallFlow::ERROR_MALFORMED_RESPONSE)); 174 (PrivetConfirmApiCallFlow::ERROR_MALFORMED_RESPONSE));
171 175
172 fetcher->delegate()->OnURLFetchComplete(fetcher); 176 fetcher->delegate()->OnURLFetchComplete(fetcher);
173 } 177 }
174 178
175 } // namespace 179 } // namespace
176 180
177 } // namespace local_discovery 181 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698