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

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

Issue 1873663002: Convert //google_apis from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 (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 // A complete set of unit tests for OAuth2MintTokenFlow. 5 // A complete set of unit tests for OAuth2MintTokenFlow.
6 6
7 #include "google_apis/gaia/oauth2_mint_token_flow.h"
8
9 #include <memory>
7 #include <string> 10 #include <string>
8 #include <vector> 11 #include <vector>
9 12
10 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 15 #include "base/values.h"
14 #include "google_apis/gaia/google_service_auth_error.h" 16 #include "google_apis/gaia/google_service_auth_error.h"
15 #include "google_apis/gaia/oauth2_access_token_fetcher.h" 17 #include "google_apis/gaia/oauth2_access_token_fetcher.h"
16 #include "google_apis/gaia/oauth2_mint_token_flow.h"
17 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
18 #include "net/url_request/test_url_fetcher_factory.h" 19 #include "net/url_request/test_url_fetcher_factory.h"
19 #include "net/url_request/url_request_status.h" 20 #include "net/url_request/url_request_status.h"
20 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 using net::TestURLFetcher; 24 using net::TestURLFetcher;
24 using net::URLFetcher; 25 using net::URLFetcher;
25 using net::URLRequestStatus; 26 using net::URLRequestStatus;
26 using testing::_; 27 using testing::_;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 std::string ext_id = "ext1"; 171 std::string ext_id = "ext1";
171 std::string client_id = "client1"; 172 std::string client_id = "client1";
172 std::vector<std::string> scopes(CreateTestScopes()); 173 std::vector<std::string> scopes(CreateTestScopes());
173 flow_.reset(new MockMintTokenFlow( 174 flow_.reset(new MockMintTokenFlow(
174 delegate, OAuth2MintTokenFlow::Parameters(ext_id, client_id, scopes, 175 delegate, OAuth2MintTokenFlow::Parameters(ext_id, client_id, scopes,
175 device_id, mode))); 176 device_id, mode)));
176 } 177 }
177 178
178 // Helper to parse the given string to DictionaryValue. 179 // Helper to parse the given string to DictionaryValue.
179 static base::DictionaryValue* ParseJson(const std::string& str) { 180 static base::DictionaryValue* ParseJson(const std::string& str) {
180 scoped_ptr<base::Value> value = base::JSONReader::Read(str); 181 std::unique_ptr<base::Value> value = base::JSONReader::Read(str);
181 EXPECT_TRUE(value.get()); 182 EXPECT_TRUE(value.get());
182 EXPECT_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); 183 EXPECT_EQ(base::Value::TYPE_DICTIONARY, value->GetType());
183 return static_cast<base::DictionaryValue*>(value.release()); 184 return static_cast<base::DictionaryValue*>(value.release());
184 } 185 }
185 186
186 scoped_ptr<MockMintTokenFlow> flow_; 187 std::unique_ptr<MockMintTokenFlow> flow_;
187 StrictMock<MockDelegate> delegate_; 188 StrictMock<MockDelegate> delegate_;
188 }; 189 };
189 190
190 TEST_F(OAuth2MintTokenFlowTest, CreateApiCallBody) { 191 TEST_F(OAuth2MintTokenFlowTest, CreateApiCallBody) {
191 { // Issue advice mode. 192 { // Issue advice mode.
192 CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE); 193 CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE);
193 std::string body = flow_->CreateApiCallBody(); 194 std::string body = flow_->CreateApiCallBody();
194 std::string expected_body( 195 std::string expected_body(
195 "force=false" 196 "force=false"
196 "&response_type=none" 197 "&response_type=none"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 "&origin=ext1" 244 "&origin=ext1"
244 "&device_id=device_id1" 245 "&device_id=device_id1"
245 "&device_type=chrome" 246 "&device_type=chrome"
246 "&lib_ver=extension"); 247 "&lib_ver=extension");
247 EXPECT_EQ(expected_body, body); 248 EXPECT_EQ(expected_body, body);
248 } 249 }
249 } 250 }
250 251
251 TEST_F(OAuth2MintTokenFlowTest, ParseMintTokenResponse) { 252 TEST_F(OAuth2MintTokenFlowTest, ParseMintTokenResponse) {
252 { // Access token missing. 253 { // Access token missing.
253 scoped_ptr<base::DictionaryValue> json( 254 std::unique_ptr<base::DictionaryValue> json(
254 ParseJson(kTokenResponseNoAccessToken)); 255 ParseJson(kTokenResponseNoAccessToken));
255 std::string at; 256 std::string at;
256 int ttl; 257 int ttl;
257 EXPECT_FALSE(OAuth2MintTokenFlow::ParseMintTokenResponse(json.get(), &at, 258 EXPECT_FALSE(OAuth2MintTokenFlow::ParseMintTokenResponse(json.get(), &at,
258 &ttl)); 259 &ttl));
259 EXPECT_TRUE(at.empty()); 260 EXPECT_TRUE(at.empty());
260 } 261 }
261 { // All good. 262 { // All good.
262 scoped_ptr<base::DictionaryValue> json(ParseJson(kValidTokenResponse)); 263 std::unique_ptr<base::DictionaryValue> json(ParseJson(kValidTokenResponse));
263 std::string at; 264 std::string at;
264 int ttl; 265 int ttl;
265 EXPECT_TRUE(OAuth2MintTokenFlow::ParseMintTokenResponse(json.get(), &at, 266 EXPECT_TRUE(OAuth2MintTokenFlow::ParseMintTokenResponse(json.get(), &at,
266 &ttl)); 267 &ttl));
267 EXPECT_EQ("at1", at); 268 EXPECT_EQ("at1", at);
268 EXPECT_EQ(3600, ttl); 269 EXPECT_EQ(3600, ttl);
269 } 270 }
270 } 271 }
271 272
272 TEST_F(OAuth2MintTokenFlowTest, ParseIssueAdviceResponse) { 273 TEST_F(OAuth2MintTokenFlowTest, ParseIssueAdviceResponse) {
273 { // Description missing. 274 { // Description missing.
274 scoped_ptr<base::DictionaryValue> json( 275 std::unique_ptr<base::DictionaryValue> json(
275 ParseJson(kIssueAdviceResponseNoDescription)); 276 ParseJson(kIssueAdviceResponseNoDescription));
276 IssueAdviceInfo ia; 277 IssueAdviceInfo ia;
277 EXPECT_FALSE(OAuth2MintTokenFlow::ParseIssueAdviceResponse( 278 EXPECT_FALSE(OAuth2MintTokenFlow::ParseIssueAdviceResponse(
278 json.get(), &ia)); 279 json.get(), &ia));
279 EXPECT_TRUE(ia.empty()); 280 EXPECT_TRUE(ia.empty());
280 } 281 }
281 { // Detail missing. 282 { // Detail missing.
282 scoped_ptr<base::DictionaryValue> json( 283 std::unique_ptr<base::DictionaryValue> json(
283 ParseJson(kIssueAdviceResponseNoDetail)); 284 ParseJson(kIssueAdviceResponseNoDetail));
284 IssueAdviceInfo ia; 285 IssueAdviceInfo ia;
285 EXPECT_FALSE(OAuth2MintTokenFlow::ParseIssueAdviceResponse( 286 EXPECT_FALSE(OAuth2MintTokenFlow::ParseIssueAdviceResponse(
286 json.get(), &ia)); 287 json.get(), &ia));
287 EXPECT_TRUE(ia.empty()); 288 EXPECT_TRUE(ia.empty());
288 } 289 }
289 { // All good. 290 { // All good.
290 scoped_ptr<base::DictionaryValue> json( 291 std::unique_ptr<base::DictionaryValue> json(
291 ParseJson(kValidIssueAdviceResponse)); 292 ParseJson(kValidIssueAdviceResponse));
292 IssueAdviceInfo ia; 293 IssueAdviceInfo ia;
293 EXPECT_TRUE(OAuth2MintTokenFlow::ParseIssueAdviceResponse( 294 EXPECT_TRUE(OAuth2MintTokenFlow::ParseIssueAdviceResponse(
294 json.get(), &ia)); 295 json.get(), &ia));
295 IssueAdviceInfo ia_expected(CreateIssueAdvice()); 296 IssueAdviceInfo ia_expected(CreateIssueAdvice());
296 EXPECT_EQ(ia_expected, ia); 297 EXPECT_EQ(ia_expected, ia);
297 } 298 }
298 } 299 }
299 300
300 TEST_F(OAuth2MintTokenFlowTest, ProcessApiCallSuccess) { 301 TEST_F(OAuth2MintTokenFlowTest, ProcessApiCallSuccess) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 } 360 }
360 361
361 { // Non-null delegate. 362 { // Non-null delegate.
362 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL); 363 TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL);
363 url_fetcher.set_status(URLRequestStatus::FromError(net::ERR_FAILED)); 364 url_fetcher.set_status(URLRequestStatus::FromError(net::ERR_FAILED));
364 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); 365 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE);
365 EXPECT_CALL(delegate_, OnMintTokenFailure(_)); 366 EXPECT_CALL(delegate_, OnMintTokenFailure(_));
366 flow_->ProcessApiCallFailure(&url_fetcher); 367 flow_->ProcessApiCallFailure(&url_fetcher);
367 } 368 }
368 } 369 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698