| 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 NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ | 5 #ifndef NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ |
| 6 #define NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ | 6 #define NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 DISALLOW_COPY_AND_ASSIGN(ScopedURLFetcherFactory); | 38 DISALLOW_COPY_AND_ASSIGN(ScopedURLFetcherFactory); |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 // TestURLFetcher and TestURLFetcherFactory are used for testing consumers of | 41 // TestURLFetcher and TestURLFetcherFactory are used for testing consumers of |
| 42 // URLFetcher. TestURLFetcherFactory is a URLFetcherFactory that creates | 42 // URLFetcher. TestURLFetcherFactory is a URLFetcherFactory that creates |
| 43 // TestURLFetchers. TestURLFetcher::Start is overriden to do nothing. It is | 43 // TestURLFetchers. TestURLFetcher::Start is overriden to do nothing. It is |
| 44 // expected that you'll grab the delegate from the TestURLFetcher and invoke | 44 // expected that you'll grab the delegate from the TestURLFetcher and invoke |
| 45 // the callback method when appropriate. In this way it's easy to mock a | 45 // the callback method when appropriate. In this way it's easy to mock a |
| 46 // URLFetcher. | 46 // URLFetcher. |
| 47 // Typical usage: | 47 // Typical usage: |
| 48 // // TestURLFetcher requires a MessageLoop. | 48 // // TestURLFetcher requires a MessageLoop and an IO thread to release |
| 49 // MessageLoop message_loop; | 49 // // URLRequestContextGetter in URLFetcher::Core. |
| 50 // // And an IO thread to release URLRequestContextGetter in URLFetcher::Core. | 50 // TestBrowserThreadBundle thread_bundle_; |
| 51 // BrowserThreadImpl io_thread(BrowserThread::IO, &message_loop); | |
| 52 // // Create factory (it automatically sets itself as URLFetcher's factory). | 51 // // Create factory (it automatically sets itself as URLFetcher's factory). |
| 53 // TestURLFetcherFactory factory; | 52 // TestURLFetcherFactory factory; |
| 54 // // Do something that triggers creation of a URLFetcher. | 53 // // Do something that triggers creation of a URLFetcher. |
| 55 // ... | 54 // ... |
| 56 // TestURLFetcher* fetcher = factory.GetFetcherByID(expected_id); | 55 // TestURLFetcher* fetcher = factory.GetFetcherByID(expected_id); |
| 57 // DCHECK(fetcher); | 56 // DCHECK(fetcher); |
| 58 // // Notify delegate with whatever data you want. | 57 // // Notify delegate with whatever data you want. |
| 59 // fetcher->delegate()->OnURLFetchComplete(...); | 58 // fetcher->delegate()->OnURLFetchComplete(...); |
| 60 // // Make sure consumer of URLFetcher does the right thing. | 59 // // Make sure consumer of URLFetcher does the right thing. |
| 61 // ... | 60 // ... |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 std::unique_ptr<URLFetcher> CreateURLFetcher( | 468 std::unique_ptr<URLFetcher> CreateURLFetcher( |
| 470 int id, | 469 int id, |
| 471 const GURL& url, | 470 const GURL& url, |
| 472 URLFetcher::RequestType request_type, | 471 URLFetcher::RequestType request_type, |
| 473 URLFetcherDelegate* d) override; | 472 URLFetcherDelegate* d) override; |
| 474 }; | 473 }; |
| 475 | 474 |
| 476 } // namespace net | 475 } // namespace net |
| 477 | 476 |
| 478 #endif // NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ | 477 #endif // NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ |
| OLD | NEW |