OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ | 5 #ifndef CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ |
6 #define CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ | 6 #define CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 virtual void Start() {} | 46 virtual void Start() {} |
47 | 47 |
48 // URL we were created with. Because of how we're using URLFetcher url() | 48 // URL we were created with. Because of how we're using URLFetcher url() |
49 // always returns an empty URL. Chances are you'll want to use original_url() | 49 // always returns an empty URL. Chances are you'll want to use original_url() |
50 // in your tests. | 50 // in your tests. |
51 const GURL& original_url() const { return original_url_; } | 51 const GURL& original_url() const { return original_url_; } |
52 | 52 |
53 // Returns the data uploaded on this URLFetcher. | 53 // Returns the data uploaded on this URLFetcher. |
54 const std::string& upload_data() const { return URLFetcher::upload_data(); } | 54 const std::string& upload_data() const { return URLFetcher::upload_data(); } |
55 | 55 |
| 56 // Overriden to do nothing. URLFetcher implementation add reference |
| 57 // to request_context_getter in core_, but it might not be released |
| 58 // because we wouldn't call Core::CancelURLRequest. |
| 59 // Without this, we'll see leaks of URLRequestContext in test. |
| 60 virtual void set_requeset_context( |
| 61 URLRequestContextGetter* request_context_getter) {} |
| 62 |
56 private: | 63 private: |
57 const GURL original_url_; | 64 const GURL original_url_; |
58 | 65 |
59 DISALLOW_COPY_AND_ASSIGN(TestURLFetcher); | 66 DISALLOW_COPY_AND_ASSIGN(TestURLFetcher); |
60 }; | 67 }; |
61 | 68 |
62 // Simple URLFetcher::Factory method that creates TestURLFetchers. All fetchers | 69 // Simple URLFetcher::Factory method that creates TestURLFetchers. All fetchers |
63 // are registered in a map by the id passed to the create method. | 70 // are registered in a map by the id passed to the create method. |
64 class TestURLFetcherFactory : public URLFetcher::Factory { | 71 class TestURLFetcherFactory : public URLFetcher::Factory { |
65 public: | 72 public: |
66 TestURLFetcherFactory() {} | 73 TestURLFetcherFactory() {} |
67 | 74 |
68 virtual URLFetcher* CreateURLFetcher(int id, | 75 virtual URLFetcher* CreateURLFetcher(int id, |
69 const GURL& url, | 76 const GURL& url, |
70 URLFetcher::RequestType request_type, | 77 URLFetcher::RequestType request_type, |
71 URLFetcher::Delegate* d); | 78 URLFetcher::Delegate* d); |
72 | 79 |
73 TestURLFetcher* GetFetcherByID(int id) const; | 80 TestURLFetcher* GetFetcherByID(int id) const; |
74 | 81 |
75 private: | 82 private: |
76 // Maps from id passed to create to the returned URLFetcher. | 83 // Maps from id passed to create to the returned URLFetcher. |
77 typedef std::map<int, TestURLFetcher*> Fetchers; | 84 typedef std::map<int, TestURLFetcher*> Fetchers; |
78 Fetchers fetchers_; | 85 Fetchers fetchers_; |
79 | 86 |
80 DISALLOW_COPY_AND_ASSIGN(TestURLFetcherFactory); | 87 DISALLOW_COPY_AND_ASSIGN(TestURLFetcherFactory); |
81 }; | 88 }; |
82 | 89 |
83 #endif // CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ | 90 #endif // CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ |
OLD | NEW |