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 #ifndef CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ | 5 #ifndef CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ |
6 #define CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ | 6 #define CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
(...skipping 17 matching lines...) Expand all Loading... |
28 DISALLOW_COPY_AND_ASSIGN(ScopedURLFetcherFactory); | 28 DISALLOW_COPY_AND_ASSIGN(ScopedURLFetcherFactory); |
29 }; | 29 }; |
30 | 30 |
31 // TestURLFetcher and TestURLFetcherFactory are used for testing consumers of | 31 // TestURLFetcher and TestURLFetcherFactory are used for testing consumers of |
32 // URLFetcher. TestURLFetcherFactory is a URLFetcherFactory that creates | 32 // URLFetcher. TestURLFetcherFactory is a URLFetcherFactory that creates |
33 // TestURLFetchers. TestURLFetcher::Start is overriden to do nothing. It is | 33 // TestURLFetchers. TestURLFetcher::Start is overriden to do nothing. It is |
34 // expected that you'll grab the delegate from the TestURLFetcher and invoke | 34 // expected that you'll grab the delegate from the TestURLFetcher and invoke |
35 // the callback method when appropriate. In this way it's easy to mock a | 35 // the callback method when appropriate. In this way it's easy to mock a |
36 // URLFetcher. | 36 // URLFetcher. |
37 // Typical usage: | 37 // Typical usage: |
38 // // TestURLFetcher requires a MessageLoop: | 38 // // TestURLFetcher requires a MessageLoop. |
39 // MessageLoopForUI message_loop; | 39 // MessageLoop message_loop; |
40 // // And io_thread to release URLRequestContextGetter in URLFetcher::Core. | 40 // // And an IO thread to release URLRequestContextGetter in URLFetcher::Core. |
41 // BrowserThreadImpl io_thread(BrowserThread::IO, &message_loop); | 41 // BrowserThreadImpl io_thread(BrowserThread::IO, &message_loop); |
42 // // Create factory (it automatically sets itself as URLFetcher's factory). | 42 // // Create factory (it automatically sets itself as URLFetcher's factory). |
43 // TestURLFetcherFactory factory; | 43 // TestURLFetcherFactory factory; |
44 // // Do something that triggers creation of a URLFetcher. | 44 // // Do something that triggers creation of a URLFetcher. |
| 45 // ... |
45 // TestURLFetcher* fetcher = factory.GetFetcherByID(expected_id); | 46 // TestURLFetcher* fetcher = factory.GetFetcherByID(expected_id); |
46 // DCHECK(fetcher); | 47 // DCHECK(fetcher); |
47 // // Notify delegate with whatever data you want. | 48 // // Notify delegate with whatever data you want. |
48 // fetcher->delegate()->OnURLFetchComplete(...); | 49 // fetcher->delegate()->OnURLFetchComplete(...); |
49 // // Make sure consumer of URLFetcher does the right thing. | 50 // // Make sure consumer of URLFetcher does the right thing. |
50 // ... | 51 // ... |
51 // | 52 // |
52 // Note: if you don't know when your request objects will be created you | 53 // Note: if you don't know when your request objects will be created you |
53 // might want to use the FakeURLFetcher and FakeURLFetcherFactory classes | 54 // might want to use the FakeURLFetcher and FakeURLFetcherFactory classes |
54 // below. | 55 // below. |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // This method will create a real URLFetcher. | 278 // This method will create a real URLFetcher. |
278 virtual content::URLFetcher* CreateURLFetcher( | 279 virtual content::URLFetcher* CreateURLFetcher( |
279 int id, | 280 int id, |
280 const GURL& url, | 281 const GURL& url, |
281 content::URLFetcher::RequestType request_type, | 282 content::URLFetcher::RequestType request_type, |
282 content::URLFetcherDelegate* d) OVERRIDE; | 283 content::URLFetcherDelegate* d) OVERRIDE; |
283 | 284 |
284 }; | 285 }; |
285 | 286 |
286 #endif // CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ | 287 #endif // CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ |
OLD | NEW |