OLD | NEW |
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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 using content::URLFetcher; | 28 using content::URLFetcher; |
29 using content::URLFetcherDelegate; | 29 using content::URLFetcherDelegate; |
30 using content::URLFetcherFactory; | 30 using content::URLFetcherFactory; |
31 using net::HttpRequestHeaders; | 31 using net::HttpRequestHeaders; |
32 using net::URLRequestStatus; | 32 using net::URLRequestStatus; |
33 using testing::_; | 33 using testing::_; |
34 using testing::Return; | 34 using testing::Return; |
35 | 35 |
36 namespace { | 36 namespace { |
| 37 |
37 static std::string CreateBody() { | 38 static std::string CreateBody() { |
38 return "some body"; | 39 return "some body"; |
39 } | 40 } |
40 | 41 |
41 static GURL CreateApiUrl() { | 42 static GURL CreateApiUrl() { |
42 return GURL("https://www.googleapis.com/someapi"); | 43 return GURL("https://www.googleapis.com/someapi"); |
43 } | 44 } |
44 | 45 |
45 static std::vector<std::string> CreateTestScopes() { | 46 static std::vector<std::string> CreateTestScopes() { |
46 std::vector<std::string> scopes; | 47 std::vector<std::string> scopes; |
47 scopes.push_back("scope1"); | 48 scopes.push_back("scope1"); |
48 scopes.push_back("scope2"); | 49 scopes.push_back("scope2"); |
49 return scopes; | 50 return scopes; |
50 } | 51 } |
51 | 52 |
52 } // namespace | |
53 | |
54 class MockUrlFetcherFactory : public ScopedURLFetcherFactory, | 53 class MockUrlFetcherFactory : public ScopedURLFetcherFactory, |
55 public URLFetcherFactory { | 54 public URLFetcherFactory { |
56 public: | 55 public: |
57 MockUrlFetcherFactory() | 56 MockUrlFetcherFactory() |
58 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 57 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
59 } | 58 } |
60 virtual ~MockUrlFetcherFactory() {} | 59 virtual ~MockUrlFetcherFactory() {} |
61 | 60 |
62 MOCK_METHOD4( | 61 MOCK_METHOD4( |
63 CreateURLFetcher, | 62 CreateURLFetcher, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 void (const net::URLFetcher* source)); | 95 void (const net::URLFetcher* source)); |
97 MOCK_METHOD1(ProcessApiCallFailure, | 96 MOCK_METHOD1(ProcessApiCallFailure, |
98 void (const net::URLFetcher* source)); | 97 void (const net::URLFetcher* source)); |
99 MOCK_METHOD1(ProcessNewAccessToken, | 98 MOCK_METHOD1(ProcessNewAccessToken, |
100 void (const std::string& access_token)); | 99 void (const std::string& access_token)); |
101 MOCK_METHOD1(ProcessMintAccessTokenFailure, | 100 MOCK_METHOD1(ProcessMintAccessTokenFailure, |
102 void (const GoogleServiceAuthError& error)); | 101 void (const GoogleServiceAuthError& error)); |
103 MOCK_METHOD0(CreateAccessTokenFetcher, OAuth2AccessTokenFetcher* ()); | 102 MOCK_METHOD0(CreateAccessTokenFetcher, OAuth2AccessTokenFetcher* ()); |
104 }; | 103 }; |
105 | 104 |
| 105 } // namespace |
| 106 |
106 class OAuth2ApiCallFlowTest : public testing::Test { | 107 class OAuth2ApiCallFlowTest : public testing::Test { |
107 public: | 108 public: |
108 OAuth2ApiCallFlowTest() {} | 109 OAuth2ApiCallFlowTest() {} |
109 virtual ~OAuth2ApiCallFlowTest() {} | 110 virtual ~OAuth2ApiCallFlowTest() {} |
110 | 111 |
111 protected: | 112 protected: |
112 void SetupAccessTokenFetcher( | 113 void SetupAccessTokenFetcher( |
113 const std::string& rt, const std::vector<std::string>& scopes) { | 114 const std::string& rt, const std::vector<std::string>& scopes) { |
114 EXPECT_CALL(*access_token_fetcher_, | 115 EXPECT_CALL(*access_token_fetcher_, |
115 Start(GaiaUrls::GetInstance()->oauth2_chrome_client_id(), | 116 Start(GaiaUrls::GetInstance()->oauth2_chrome_client_id(), |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 scoped_ptr<TestURLFetcher> url_fetcher(SetupApiCall(true, net::HTTP_OK)); | 281 scoped_ptr<TestURLFetcher> url_fetcher(SetupApiCall(true, net::HTTP_OK)); |
281 flow_->CreateURLFetcher(); | 282 flow_->CreateURLFetcher(); |
282 HttpRequestHeaders headers; | 283 HttpRequestHeaders headers; |
283 url_fetcher->GetExtraRequestHeaders(&headers); | 284 url_fetcher->GetExtraRequestHeaders(&headers); |
284 std::string auth_header; | 285 std::string auth_header; |
285 EXPECT_TRUE(headers.GetHeader("Authorization", &auth_header)); | 286 EXPECT_TRUE(headers.GetHeader("Authorization", &auth_header)); |
286 EXPECT_EQ("Bearer access_token", auth_header); | 287 EXPECT_EQ("Bearer access_token", auth_header); |
287 EXPECT_EQ(url, url_fetcher->GetOriginalURL()); | 288 EXPECT_EQ(url, url_fetcher->GetOriginalURL()); |
288 EXPECT_EQ(body, url_fetcher->upload_data()); | 289 EXPECT_EQ(body, url_fetcher->upload_data()); |
289 } | 290 } |
OLD | NEW |