| 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> |
| 11 | 11 |
| 12 #include "chrome/common/net/url_fetcher.h" | 12 #include "chrome/common/net/url_fetcher.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 | 14 |
| 15 // TestURLFetcher and TestURLFetcherFactory are used for testing consumers of | 15 // TestURLFetcher and TestURLFetcherFactory are used for testing consumers of |
| 16 // URLFetcher. TestURLFetcherFactory is a URLFetcher::Factory that creates | 16 // URLFetcher. TestURLFetcherFactory is a URLFetcher::Factory that creates |
| 17 // TestURLFetchers. TestURLFetcher::Start is overriden to do nothing. It is | 17 // TestURLFetchers. TestURLFetcher::Start is overriden to do nothing. It is |
| 18 // expected that you'll grab the delegate from the TestURLFetcher and invoke | 18 // expected that you'll grab the delegate from the TestURLFetcher and invoke |
| 19 // the callback method when appropriate. In this way it's easy to mock a | 19 // the callback method when appropriate. In this way it's easy to mock a |
| 20 // URLFetcher. | 20 // URLFetcher. |
| 21 // Typical usage: | 21 // Typical usage: |
| 22 // // TestURLFetcher requires a MessageLoop: | 22 // // TestURLFetcher requires a MessageLoop: |
| 23 // MessageLoopForIO message_loop; | 23 // MessageLoopForUI message_loop; |
| 24 // // and IO thread to clean up request_context etc. | |
| 25 // ChromeThread io_thread(ChromeThread::IO, &message_loop); | |
| 26 // // Create and register factory. | 24 // // Create and register factory. |
| 27 // TestURLFetcherFactory factory; | 25 // TestURLFetcherFactory factory; |
| 28 // URLFetcher::set_factory(&factory); | 26 // URLFetcher::set_factory(&factory); |
| 29 // // Do something that triggers creation of a URLFetcher. | 27 // // Do something that triggers creation of a URLFetcher. |
| 30 // TestURLFetcher* fetcher = factory.GetFetcherByID(expected_id); | 28 // TestURLFetcher* fetcher = factory.GetFetcherByID(expected_id); |
| 31 // DCHECK(fetcher); | 29 // DCHECK(fetcher); |
| 32 // // Notify delegate with whatever data you want. | 30 // // Notify delegate with whatever data you want. |
| 33 // fetcher->delegate()->OnURLFetchComplete(...); | 31 // fetcher->delegate()->OnURLFetchComplete(...); |
| 34 // // Make sure consumer of URLFetcher does the right thing. | 32 // // Make sure consumer of URLFetcher does the right thing. |
| 35 // ... | 33 // ... |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 74 |
| 77 private: | 75 private: |
| 78 // Maps from id passed to create to the returned URLFetcher. | 76 // Maps from id passed to create to the returned URLFetcher. |
| 79 typedef std::map<int, TestURLFetcher*> Fetchers; | 77 typedef std::map<int, TestURLFetcher*> Fetchers; |
| 80 Fetchers fetchers_; | 78 Fetchers fetchers_; |
| 81 | 79 |
| 82 DISALLOW_COPY_AND_ASSIGN(TestURLFetcherFactory); | 80 DISALLOW_COPY_AND_ASSIGN(TestURLFetcherFactory); |
| 83 }; | 81 }; |
| 84 | 82 |
| 85 #endif // CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ | 83 #endif // CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ |
| OLD | NEW |