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 GaiaOAuthClient. | 5 // A complete set of unit tests for GaiaOAuthClient. |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "chrome/common/net/gaia/gaia_oauth_client.h" | 12 #include "chrome/common/net/gaia/gaia_oauth_client.h" |
13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
14 #include "content/public/common/url_fetcher_delegate.h" | |
15 #include "content/test/test_url_fetcher_factory.h" | 14 #include "content/test/test_url_fetcher_factory.h" |
16 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
17 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
18 #include "net/http/http_status_code.h" | 17 #include "net/http/http_status_code.h" |
| 18 #include "net/url_request/url_fetcher_delegate.h" |
19 #include "net/url_request/url_request_status.h" | 19 #include "net/url_request/url_request_status.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 using ::testing::_; | 23 using ::testing::_; |
24 | 24 |
25 namespace { | 25 namespace { |
26 // Responds as though OAuth returned from the server. | 26 // Responds as though OAuth returned from the server. |
27 class MockOAuthFetcher : public TestURLFetcher { | 27 class MockOAuthFetcher : public TestURLFetcher { |
28 public: | 28 public: |
29 MockOAuthFetcher(int response_code, | 29 MockOAuthFetcher(int response_code, |
30 int max_failure_count, | 30 int max_failure_count, |
31 const GURL& url, | 31 const GURL& url, |
32 const std::string& results, | 32 const std::string& results, |
33 content::URLFetcher::RequestType request_type, | 33 content::URLFetcher::RequestType request_type, |
34 content::URLFetcherDelegate* d) | 34 net::URLFetcherDelegate* d) |
35 : TestURLFetcher(0, url, d), | 35 : TestURLFetcher(0, url, d), |
36 max_failure_count_(max_failure_count), | 36 max_failure_count_(max_failure_count), |
37 current_failure_count_(0) { | 37 current_failure_count_(0) { |
38 set_url(url); | 38 set_url(url); |
39 set_response_code(response_code); | 39 set_response_code(response_code); |
40 SetResponseString(results); | 40 SetResponseString(results); |
41 } | 41 } |
42 | 42 |
43 virtual ~MockOAuthFetcher() { } | 43 virtual ~MockOAuthFetcher() { } |
44 | 44 |
(...skipping 24 matching lines...) Expand all Loading... |
69 public: | 69 public: |
70 MockOAuthFetcherFactory() | 70 MockOAuthFetcherFactory() |
71 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 71 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
72 response_code_(net::HTTP_OK) { | 72 response_code_(net::HTTP_OK) { |
73 } | 73 } |
74 ~MockOAuthFetcherFactory() {} | 74 ~MockOAuthFetcherFactory() {} |
75 virtual content::URLFetcher* CreateURLFetcher( | 75 virtual content::URLFetcher* CreateURLFetcher( |
76 int id, | 76 int id, |
77 const GURL& url, | 77 const GURL& url, |
78 content::URLFetcher::RequestType request_type, | 78 content::URLFetcher::RequestType request_type, |
79 content::URLFetcherDelegate* d) { | 79 net::URLFetcherDelegate* d) { |
80 return new MockOAuthFetcher( | 80 return new MockOAuthFetcher( |
81 response_code_, | 81 response_code_, |
82 max_failure_count_, | 82 max_failure_count_, |
83 url, | 83 url, |
84 results_, | 84 results_, |
85 request_type, | 85 request_type, |
86 d); | 86 d); |
87 } | 87 } |
88 void set_response_code(int response_code) { | 88 void set_response_code(int response_code) { |
89 response_code_ = response_code; | 89 response_code_ = response_code; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 factory.set_results(kDummyRefreshTokenResult); | 234 factory.set_results(kDummyRefreshTokenResult); |
235 | 235 |
236 OAuthClientInfo client_info; | 236 OAuthClientInfo client_info; |
237 client_info.client_id = "test_client_id"; | 237 client_info.client_id = "test_client_id"; |
238 client_info.client_secret = "test_client_secret"; | 238 client_info.client_secret = "test_client_secret"; |
239 GaiaOAuthClient auth(kGaiaOAuth2Url, | 239 GaiaOAuthClient auth(kGaiaOAuth2Url, |
240 profile_.GetRequestContext()); | 240 profile_.GetRequestContext()); |
241 auth.GetTokensFromAuthCode(client_info, "auth_code", -1, &delegate); | 241 auth.GetTokensFromAuthCode(client_info, "auth_code", -1, &delegate); |
242 } | 242 } |
243 } // namespace gaia | 243 } // namespace gaia |
OLD | NEW |