| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_ | 8 #ifndef CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_ |
| 9 #define CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_ | 9 #define CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_ |
| 10 #pragma once | 10 #pragma once |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" | 14 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" |
| 15 #include "chrome/common/net/http_return.h" | 15 #include "chrome/common/net/http_return.h" |
| 16 #include "content/common/url_fetcher.h" | 16 #include "content/common/url_fetcher.h" |
| 17 #include "content/test/test_url_fetcher_factory.h" |
| 17 #include "net/url_request/url_request_status.h" | 18 #include "net/url_request/url_request_status.h" |
| 18 | 19 |
| 19 // Responds as though ClientLogin returned from the server. | 20 // Responds as though ClientLogin returned from the server. |
| 20 class MockFetcher : public URLFetcher { | 21 class MockFetcher : public URLFetcher { |
| 21 public: | 22 public: |
| 22 MockFetcher(bool success, | 23 MockFetcher(bool success, |
| 23 const GURL& url, | 24 const GURL& url, |
| 24 const std::string& results, | 25 const std::string& results, |
| 25 URLFetcher::RequestType request_type, | 26 URLFetcher::RequestType request_type, |
| 26 URLFetcher::Delegate* d); | 27 URLFetcher::Delegate* d); |
| 27 | 28 |
| 28 virtual ~MockFetcher(); | 29 virtual ~MockFetcher(); |
| 29 | 30 |
| 30 virtual void Start(); | 31 virtual void Start(); |
| 31 | 32 |
| 32 private: | 33 private: |
| 33 bool success_; | 34 bool success_; |
| 34 GURL url_; | 35 GURL url_; |
| 35 std::string results_; | 36 std::string results_; |
| 36 DISALLOW_COPY_AND_ASSIGN(MockFetcher); | 37 DISALLOW_COPY_AND_ASSIGN(MockFetcher); |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 template<typename T> | 40 template<typename T> |
| 40 class MockFactory : public URLFetcher::Factory { | 41 class MockFactory : public URLFetcher::Factory, |
| 42 public ScopedURLFetcherFactory { |
| 41 public: | 43 public: |
| 42 MockFactory() | 44 MockFactory() |
| 43 : success_(true) {} | 45 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 46 success_(true) { |
| 47 } |
| 44 ~MockFactory() {} | 48 ~MockFactory() {} |
| 45 URLFetcher* CreateURLFetcher(int id, | 49 URLFetcher* CreateURLFetcher(int id, |
| 46 const GURL& url, | 50 const GURL& url, |
| 47 URLFetcher::RequestType request_type, | 51 URLFetcher::RequestType request_type, |
| 48 URLFetcher::Delegate* d) { | 52 URLFetcher::Delegate* d) { |
| 49 return new T(success_, url, results_, request_type, d); | 53 return new T(success_, url, results_, request_type, d); |
| 50 } | 54 } |
| 51 void set_success(bool success) { | 55 void set_success(bool success) { |
| 52 success_ = success; | 56 success_ = success; |
| 53 } | 57 } |
| 54 void set_results(const std::string& results) { | 58 void set_results(const std::string& results) { |
| 55 results_ = results; | 59 results_ = results; |
| 56 } | 60 } |
| 57 private: | 61 private: |
| 58 bool success_; | 62 bool success_; |
| 59 std::string results_; | 63 std::string results_; |
| 60 DISALLOW_COPY_AND_ASSIGN(MockFactory); | 64 DISALLOW_COPY_AND_ASSIGN(MockFactory); |
| 61 }; | 65 }; |
| 62 | 66 |
| 63 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_ | 67 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_ |
| OLD | NEW |