| 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 collection of classes that are useful when testing things that use a | 5 // A collection of classes that are useful when testing things that use a |
| 6 // GaiaAuthFetcher. | 6 // GaiaAuthFetcher. |
| 7 | 7 |
| 8 #ifndef GOOGLE_APIS_GAIA_MOCK_URL_FETCHER_FACTORY_H_ | 8 #ifndef GOOGLE_APIS_GAIA_MOCK_URL_FETCHER_FACTORY_H_ |
| 9 #define GOOGLE_APIS_GAIA_MOCK_URL_FETCHER_FACTORY_H_ | 9 #define GOOGLE_APIS_GAIA_MOCK_URL_FETCHER_FACTORY_H_ |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "google_apis/gaia/gaia_auth_fetcher.h" | 14 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 15 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 15 #include "net/url_request/test_url_fetcher_factory.h" | 16 #include "net/url_request/test_url_fetcher_factory.h" |
| 16 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
| 17 | 18 |
| 18 // Responds as though ClientLogin returned from the server. | 19 // Responds as though ClientLogin returned from the server. |
| 19 class MockFetcher : public net::TestURLFetcher { | 20 class MockFetcher : public net::TestURLFetcher { |
| 20 public: | 21 public: |
| 21 MockFetcher(bool success, | 22 MockFetcher(bool success, |
| 22 const GURL& url, | 23 const GURL& url, |
| 23 const std::string& results, | 24 const std::string& results, |
| 24 net::URLFetcher::RequestType request_type, | 25 net::URLFetcher::RequestType request_type, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 45 public: | 46 public: |
| 46 MockURLFetcherFactory() | 47 MockURLFetcherFactory() |
| 47 : net::ScopedURLFetcherFactory(this), | 48 : net::ScopedURLFetcherFactory(this), |
| 48 success_(true) { | 49 success_(true) { |
| 49 } | 50 } |
| 50 ~MockURLFetcherFactory() {} | 51 ~MockURLFetcherFactory() {} |
| 51 std::unique_ptr<net::URLFetcher> CreateURLFetcher( | 52 std::unique_ptr<net::URLFetcher> CreateURLFetcher( |
| 52 int id, | 53 int id, |
| 53 const GURL& url, | 54 const GURL& url, |
| 54 net::URLFetcher::RequestType request_type, | 55 net::URLFetcher::RequestType request_type, |
| 55 net::URLFetcherDelegate* d) override { | 56 net::URLFetcherDelegate* d, |
| 57 net::NetworkTrafficAnnotationTag traffic_annotation) override { |
| 56 return std::unique_ptr<net::URLFetcher>( | 58 return std::unique_ptr<net::URLFetcher>( |
| 57 new T(success_, url, results_, request_type, d)); | 59 new T(success_, url, results_, request_type, d)); |
| 58 } | 60 } |
| 59 void set_success(bool success) { | 61 void set_success(bool success) { |
| 60 success_ = success; | 62 success_ = success; |
| 61 } | 63 } |
| 62 void set_results(const std::string& results) { | 64 void set_results(const std::string& results) { |
| 63 results_ = results; | 65 results_ = results; |
| 64 } | 66 } |
| 65 private: | 67 private: |
| 66 bool success_; | 68 bool success_; |
| 67 std::string results_; | 69 std::string results_; |
| 68 DISALLOW_COPY_AND_ASSIGN(MockURLFetcherFactory); | 70 DISALLOW_COPY_AND_ASSIGN(MockURLFetcherFactory); |
| 69 }; | 71 }; |
| 70 | 72 |
| 71 #endif // GOOGLE_APIS_GAIA_MOCK_URL_FETCHER_FACTORY_H_ | 73 #endif // GOOGLE_APIS_GAIA_MOCK_URL_FETCHER_FACTORY_H_ |
| OLD | NEW |