| 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 #ifndef CHROME_BROWSER_POLICY_TESTING_POLICY_URL_FETCHER_FACTORY_H_ | 5 #ifndef CHROME_BROWSER_POLICY_TESTING_POLICY_URL_FETCHER_FACTORY_H_ |
| 6 #define CHROME_BROWSER_POLICY_TESTING_POLICY_URL_FETCHER_FACTORY_H_ | 6 #define CHROME_BROWSER_POLICY_TESTING_POLICY_URL_FETCHER_FACTORY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/browser/policy/logging_work_scheduler.h" | |
| 14 #include "content/common/net/url_fetcher.h" | 13 #include "content/common/net/url_fetcher.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" | |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 18 | 16 |
| 17 class GURL; |
| 18 |
| 19 namespace policy { | 19 namespace policy { |
| 20 | 20 |
| 21 class EventLogger; |
| 22 class LoggingWorkScheduler; |
| 21 class TestingPolicyURLFetcher; | 23 class TestingPolicyURLFetcher; |
| 22 | 24 |
| 23 struct TestURLResponse { | 25 struct TestURLResponse { |
| 24 std::string response_data; | 26 std::string response_data; |
| 25 int response_code; | 27 int response_code; |
| 26 }; | 28 }; |
| 27 | 29 |
| 28 // Creates mock URLFetchers whose behavior can be controlled in tests. To do so | 30 // Creates mock URLFetchers whose behavior can be controlled in tests. To do so |
| 29 // set mock expectations on the method |Intercept|. | 31 // set mock expectations on the method |Intercept|. |
| 30 class TestingPolicyURLFetcherFactory : public URLFetcher::Factory, | 32 class TestingPolicyURLFetcherFactory : public URLFetcher::Factory, |
| 31 public ScopedURLFetcherFactory { | 33 public ScopedURLFetcherFactory { |
| 32 public: | 34 public: |
| 33 explicit TestingPolicyURLFetcherFactory(EventLogger* logger); | 35 explicit TestingPolicyURLFetcherFactory(EventLogger* logger); |
| 34 virtual ~TestingPolicyURLFetcherFactory(); | 36 virtual ~TestingPolicyURLFetcherFactory(); |
| 35 | 37 |
| 36 virtual URLFetcher* CreateURLFetcher( | 38 virtual URLFetcher* CreateURLFetcher( |
| 37 int id, | 39 int id, |
| 38 const GURL& url, | 40 const GURL& url, |
| 39 URLFetcher::RequestType request_type, | 41 URLFetcher::RequestType request_type, |
| 40 URLFetcher::Delegate* delegate); | 42 URLFetcher::Delegate* delegate) OVERRIDE; |
| 41 | 43 |
| 42 LoggingWorkScheduler* scheduler(); | 44 LoggingWorkScheduler* scheduler(); |
| 43 | 45 |
| 44 // Called back by TestingPolicyURLFetcher objects. Uses |Intercept| to get | 46 // Called back by TestingPolicyURLFetcher objects. Uses |Intercept| to get |
| 45 // the response and notifies |logger_| of a network request event. | 47 // the response and notifies |logger_| of a network request event. |
| 46 void GetResponse(const std::string& auth_header, | 48 void GetResponse(const std::string& auth_header, |
| 47 const std::string& request_type, | 49 const std::string& request_type, |
| 48 TestURLResponse* response); | 50 TestURLResponse* response); |
| 49 | 51 |
| 50 // Place EXPECT_CALLs on this method to control the responses of the | 52 // Place EXPECT_CALLs on this method to control the responses of the |
| 51 // produced URLFetchers. The response data should be copied into |response|. | 53 // produced URLFetchers. The response data should be copied into |response|. |
| 52 MOCK_METHOD3(Intercept, void(const std::string& auth_header, | 54 MOCK_METHOD3(Intercept, void(const std::string& auth_header, |
| 53 const std::string& request_type, | 55 const std::string& request_type, |
| 54 TestURLResponse* response)); | 56 TestURLResponse* response)); |
| 55 | 57 |
| 56 private: | 58 private: |
| 57 EventLogger* logger_; | 59 EventLogger* logger_; |
| 58 scoped_ptr<LoggingWorkScheduler> scheduler_; | 60 scoped_ptr<LoggingWorkScheduler> scheduler_; |
| 59 | 61 |
| 60 base::WeakPtrFactory<TestingPolicyURLFetcherFactory> weak_ptr_factory_; | 62 base::WeakPtrFactory<TestingPolicyURLFetcherFactory> weak_ptr_factory_; |
| 61 | 63 |
| 62 DISALLOW_COPY_AND_ASSIGN(TestingPolicyURLFetcherFactory); | 64 DISALLOW_COPY_AND_ASSIGN(TestingPolicyURLFetcherFactory); |
| 63 }; | 65 }; |
| 64 | 66 |
| 65 } // namespace policy | 67 } // namespace policy |
| 66 | 68 |
| 67 #endif // CHROME_BROWSER_POLICY_TESTING_POLICY_URL_FETCHER_FACTORY_H_ | 69 #endif // CHROME_BROWSER_POLICY_TESTING_POLICY_URL_FETCHER_FACTORY_H_ |
| OLD | NEW |