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 14 matching lines...) Expand all Loading... |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 | 26 |
27 using content::URLFetcher; | 27 using content::URLFetcher; |
28 using content::URLFetcherDelegate; | 28 using content::URLFetcherDelegate; |
29 using content::URLFetcherFactory; | 29 using content::URLFetcherFactory; |
30 using net::URLRequestStatus; | 30 using net::URLRequestStatus; |
31 using testing::_; | 31 using testing::_; |
32 using testing::Return; | 32 using testing::Return; |
33 | 33 |
34 namespace { | 34 namespace { |
| 35 |
35 static GURL CreateApiUrl() { | 36 static GURL CreateApiUrl() { |
36 return GURL("https://www.googleapis.com/someapi"); | 37 return GURL("https://www.googleapis.com/someapi"); |
37 } | 38 } |
38 | 39 |
39 static std::vector<std::string> CreateTestScopes() { | 40 static std::vector<std::string> CreateTestScopes() { |
40 std::vector<std::string> scopes; | 41 std::vector<std::string> scopes; |
41 scopes.push_back("scope1"); | 42 scopes.push_back("scope1"); |
42 scopes.push_back("scope2"); | 43 scopes.push_back("scope2"); |
43 return scopes; | 44 return scopes; |
44 } | 45 } |
45 } | 46 |
| 47 } // namespace |
46 | 48 |
47 class MockUrlFetcherFactory : public ScopedURLFetcherFactory, | 49 class MockUrlFetcherFactory : public ScopedURLFetcherFactory, |
48 public URLFetcherFactory { | 50 public URLFetcherFactory { |
49 public: | 51 public: |
50 MockUrlFetcherFactory() | 52 MockUrlFetcherFactory() |
51 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 53 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
52 } | 54 } |
53 virtual ~MockUrlFetcherFactory() {} | 55 virtual ~MockUrlFetcherFactory() {} |
54 | 56 |
55 MOCK_METHOD4( | 57 MOCK_METHOD4( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 MOCK_METHOD0(CreateApiCallBody, std::string ()); | 89 MOCK_METHOD0(CreateApiCallBody, std::string ()); |
88 MOCK_METHOD1(ProcessApiCallSuccess, | 90 MOCK_METHOD1(ProcessApiCallSuccess, |
89 void (const content::URLFetcher* source)); | 91 void (const content::URLFetcher* source)); |
90 MOCK_METHOD1(ProcessApiCallFailure, | 92 MOCK_METHOD1(ProcessApiCallFailure, |
91 void (const content::URLFetcher* source)); | 93 void (const content::URLFetcher* source)); |
92 MOCK_METHOD1(ProcessNewAccessToken, | 94 MOCK_METHOD1(ProcessNewAccessToken, |
93 void (const std::string& access_token)); | 95 void (const std::string& access_token)); |
94 MOCK_METHOD1(ProcessMintAccessTokenFailure, | 96 MOCK_METHOD1(ProcessMintAccessTokenFailure, |
95 void (const GoogleServiceAuthError& error)); | 97 void (const GoogleServiceAuthError& error)); |
96 MOCK_METHOD0(CreateAccessTokenFetcher, OAuth2AccessTokenFetcher* ()); | 98 MOCK_METHOD0(CreateAccessTokenFetcher, OAuth2AccessTokenFetcher* ()); |
97 // MOCK_METHOD0(CreateURLFetcher, URLFetcher* ()); | |
98 }; | 99 }; |
99 | 100 |
100 class OAuth2ApiCallFlowTest : public testing::Test { | 101 class OAuth2ApiCallFlowTest : public testing::Test { |
101 public: | 102 public: |
102 OAuth2ApiCallFlowTest() {} | 103 OAuth2ApiCallFlowTest() {} |
103 virtual ~OAuth2ApiCallFlowTest() {} | 104 virtual ~OAuth2ApiCallFlowTest() {} |
104 | 105 |
105 protected: | 106 protected: |
106 void SetupAccessTokenFetcher( | 107 void SetupAccessTokenFetcher( |
107 const std::string& rt, const std::vector<std::string>& scopes) { | 108 const std::string& rt, const std::vector<std::string>& scopes) { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 std::vector<std::string> scopes(CreateTestScopes()); | 255 std::vector<std::string> scopes(CreateTestScopes()); |
255 | 256 |
256 CreateFlow(rt, "", scopes); | 257 CreateFlow(rt, "", scopes); |
257 SetupAccessTokenFetcher(rt, scopes); | 258 SetupAccessTokenFetcher(rt, scopes); |
258 GoogleServiceAuthError error( | 259 GoogleServiceAuthError error( |
259 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 260 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
260 EXPECT_CALL(*flow_, ProcessMintAccessTokenFailure(error)); | 261 EXPECT_CALL(*flow_, ProcessMintAccessTokenFailure(error)); |
261 flow_->Start(); | 262 flow_->Start(); |
262 flow_->OnGetTokenFailure(error); | 263 flow_->OnGetTokenFailure(error); |
263 } | 264 } |
OLD | NEW |