OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 OAuth2AccessTokenFetcherImpl. | 5 // A complete set of unit tests for OAuth2AccessTokenFetcherImpl. |
6 | 6 |
| 7 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h" |
| 8 |
| 9 #include <memory> |
7 #include <string> | 10 #include <string> |
8 | 11 |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
11 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
13 #include "google_apis/gaia/gaia_urls.h" | 15 #include "google_apis/gaia/gaia_urls.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_consumer.h" | 17 #include "google_apis/gaia/oauth2_access_token_consumer.h" |
16 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h" | |
17 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
18 #include "net/http/http_status_code.h" | 19 #include "net/http/http_status_code.h" |
19 #include "net/url_request/test_url_fetcher_factory.h" | 20 #include "net/url_request/test_url_fetcher_factory.h" |
20 #include "net/url_request/url_fetcher.h" | 21 #include "net/url_request/url_fetcher.h" |
21 #include "net/url_request/url_fetcher_delegate.h" | 22 #include "net/url_request/url_fetcher_delegate.h" |
22 #include "net/url_request/url_fetcher_factory.h" | 23 #include "net/url_request/url_fetcher_factory.h" |
23 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
24 #include "net/url_request/url_request_status.h" | 25 #include "net/url_request/url_request_status.h" |
25 #include "net/url_request/url_request_test_util.h" | 26 #include "net/url_request/url_request_test_util.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 public: | 64 public: |
64 MockUrlFetcherFactory() : ScopedURLFetcherFactory(this) {} | 65 MockUrlFetcherFactory() : ScopedURLFetcherFactory(this) {} |
65 virtual ~MockUrlFetcherFactory() {} | 66 virtual ~MockUrlFetcherFactory() {} |
66 | 67 |
67 MOCK_METHOD4(CreateURLFetcherMock, | 68 MOCK_METHOD4(CreateURLFetcherMock, |
68 URLFetcher*(int id, | 69 URLFetcher*(int id, |
69 const GURL& url, | 70 const GURL& url, |
70 URLFetcher::RequestType request_type, | 71 URLFetcher::RequestType request_type, |
71 URLFetcherDelegate* d)); | 72 URLFetcherDelegate* d)); |
72 | 73 |
73 scoped_ptr<URLFetcher> CreateURLFetcher(int id, | 74 std::unique_ptr<URLFetcher> CreateURLFetcher( |
74 const GURL& url, | 75 int id, |
75 URLFetcher::RequestType request_type, | 76 const GURL& url, |
76 URLFetcherDelegate* d) override { | 77 URLFetcher::RequestType request_type, |
77 return scoped_ptr<URLFetcher>( | 78 URLFetcherDelegate* d) override { |
| 79 return std::unique_ptr<URLFetcher>( |
78 CreateURLFetcherMock(id, url, request_type, d)); | 80 CreateURLFetcherMock(id, url, request_type, d)); |
79 } | 81 } |
80 }; | 82 }; |
81 | 83 |
82 class MockOAuth2AccessTokenConsumer : public OAuth2AccessTokenConsumer { | 84 class MockOAuth2AccessTokenConsumer : public OAuth2AccessTokenConsumer { |
83 public: | 85 public: |
84 MockOAuth2AccessTokenConsumer() {} | 86 MockOAuth2AccessTokenConsumer() {} |
85 ~MockOAuth2AccessTokenConsumer() {} | 87 ~MockOAuth2AccessTokenConsumer() {} |
86 | 88 |
87 MOCK_METHOD2(OnGetTokenSuccess, | 89 MOCK_METHOD2(OnGetTokenSuccess, |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 TestURLFetcher url_fetcher(0, GURL("http://www.google.com"), NULL); | 268 TestURLFetcher url_fetcher(0, GURL("http://www.google.com"), NULL); |
267 url_fetcher.SetResponseString(kValidFailureTokenResponse); | 269 url_fetcher.SetResponseString(kValidFailureTokenResponse); |
268 | 270 |
269 std::string error; | 271 std::string error; |
270 EXPECT_TRUE( | 272 EXPECT_TRUE( |
271 OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse( | 273 OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse( |
272 &url_fetcher, &error)); | 274 &url_fetcher, &error)); |
273 EXPECT_EQ("invalid_grant", error); | 275 EXPECT_EQ("invalid_grant", error); |
274 } | 276 } |
275 } | 277 } |
OLD | NEW |