OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_HTTP_FETCHER_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_HTTP_FETCHER_H__ |
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_HTTP_FETCHER_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_HTTP_FETCHER_H__ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
| 9 |
| 10 #include <base/logging.h> |
9 #include <glib.h> | 11 #include <glib.h> |
10 #include "base/logging.h" | 12 |
11 #include "update_engine/http_fetcher.h" | 13 #include "update_engine/http_fetcher.h" |
12 | 14 |
13 // This is a mock implementation of HttpFetcher which is useful for testing. | 15 // This is a mock implementation of HttpFetcher which is useful for testing. |
14 // All data must be passed into the ctor. When started, MockHttpFetcher will | 16 // All data must be passed into the ctor. When started, MockHttpFetcher will |
15 // deliver the data in chunks of size kMockHttpFetcherChunkSize. To simulate | 17 // deliver the data in chunks of size kMockHttpFetcherChunkSize. To simulate |
16 // a network failure, you can call FailTransfer(). | 18 // a network failure, you can call FailTransfer(). |
17 | 19 |
18 namespace chromeos_update_engine { | 20 namespace chromeos_update_engine { |
19 | 21 |
20 // MockHttpFetcher will send a chunk of data down in each call to BeginTransfer | 22 // MockHttpFetcher will send a chunk of data down in each call to BeginTransfer |
21 // and Unpause. For the other chunks of data, a callback is put on the run | 23 // and Unpause. For the other chunks of data, a callback is put on the run |
22 // loop and when that's called, another chunk is sent down. | 24 // loop and when that's called, another chunk is sent down. |
23 const size_t kMockHttpFetcherChunkSize(65536); | 25 const size_t kMockHttpFetcherChunkSize(65536); |
24 | 26 |
25 class MockHttpFetcher : public HttpFetcher { | 27 class MockHttpFetcher : public HttpFetcher { |
26 public: | 28 public: |
27 // The data passed in here is copied and then passed to the delegate after | 29 // The data passed in here is copied and then passed to the delegate after |
28 // the transfer begins. | 30 // the transfer begins. |
29 MockHttpFetcher(const char* data, size_t size) | 31 MockHttpFetcher(const char* data, |
30 : sent_size_(0), | 32 size_t size, |
| 33 ProxyResolver* proxy_resolver) |
| 34 : HttpFetcher(proxy_resolver), |
| 35 sent_size_(0), |
31 timeout_source_(NULL), | 36 timeout_source_(NULL), |
32 timout_tag_(0), | 37 timout_tag_(0), |
33 paused_(false), | 38 paused_(false), |
34 fail_transfer_(false) { | 39 fail_transfer_(false) { |
35 data_.insert(data_.end(), data, data + size); | 40 data_.insert(data_.end(), data, data + size); |
36 } | 41 } |
37 | 42 |
38 // Cleans up all internal state. Does not notify delegate | 43 // Cleans up all internal state. Does not notify delegate |
39 ~MockHttpFetcher(); | 44 ~MockHttpFetcher(); |
40 | 45 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 107 |
103 // Set to true if the transfer should fail. | 108 // Set to true if the transfer should fail. |
104 bool fail_transfer_; | 109 bool fail_transfer_; |
105 | 110 |
106 DISALLOW_COPY_AND_ASSIGN(MockHttpFetcher); | 111 DISALLOW_COPY_AND_ASSIGN(MockHttpFetcher); |
107 }; | 112 }; |
108 | 113 |
109 } // namespace chromeos_update_engine | 114 } // namespace chromeos_update_engine |
110 | 115 |
111 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_HTTP_FETCHER_H__ | 116 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_HTTP_FETCHER_H__ |
OLD | NEW |