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