| 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 UPDATE_ENGINE_MOCK_HTTP_FETCHER_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_HTTP_FETCHER_H__ |
| 6 #define 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 #include <glib.h> | 9 #include <glib.h> |
| 10 #include <base/logging.h> | 10 #include "chromeos/obsolete_logging.h" |
| 11 #include "update_engine/http_fetcher.h" | 11 #include "update_engine/http_fetcher.h" |
| 12 | 12 |
| 13 // This is a mock implementation of HttpFetcher which is useful for testing. | 13 // 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 | 14 // All data must be passed into the ctor. When started, MockHttpFetcher will |
| 15 // deliver the data in chunks of size kMockHttpFetcherChunkSize. To simulate | 15 // deliver the data in chunks of size kMockHttpFetcherChunkSize. To simulate |
| 16 // a network failure, you can call FailTransfer(). | 16 // a network failure, you can call FailTransfer(). |
| 17 | 17 |
| 18 namespace chromeos_update_engine { | 18 namespace chromeos_update_engine { |
| 19 | 19 |
| 20 // MockHttpFetcher will send a chunk of data down in each call to BeginTransfer | 20 // MockHttpFetcher will send a chunk of data down in each call to BeginTransfer |
| (...skipping 26 matching lines...) Expand all Loading... |
| 47 | 47 |
| 48 // Resume the mock transfer. | 48 // Resume the mock transfer. |
| 49 virtual void Unpause(); | 49 virtual void Unpause(); |
| 50 | 50 |
| 51 // Fail the transfer. This simulates a network failure. | 51 // Fail the transfer. This simulates a network failure. |
| 52 void FailTransfer(); | 52 void FailTransfer(); |
| 53 | 53 |
| 54 const std::vector<char>& post_data() const { | 54 const std::vector<char>& post_data() const { |
| 55 return post_data_; | 55 return post_data_; |
| 56 } | 56 } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 // Sends data to the delegate and sets up a glib timeout callback if needed. | 59 // Sends data to the delegate and sets up a glib timeout callback if needed. |
| 60 // There must be a delegate and there must be data to send. If there is | 60 // There must be a delegate and there must be data to send. If there is |
| 61 // already a timeout callback, and it should be deleted by the caller, | 61 // already a timeout callback, and it should be deleted by the caller, |
| 62 // this will return false; otherwise true is returned. | 62 // this will return false; otherwise true is returned. |
| 63 // If skip_delivery is true, no bytes will be delivered, but the callbacks | 63 // If skip_delivery is true, no bytes will be delivered, but the callbacks |
| 64 // still still be set if needed | 64 // still still be set if needed |
| 65 bool SendData(bool skip_delivery); | 65 bool SendData(bool skip_delivery); |
| 66 | 66 |
| 67 // Callback for when our glib main loop callback is called | 67 // Callback for when our glib main loop callback is called |
| (...skipping 16 matching lines...) Expand all Loading... |
| 84 guint timout_tag_; | 84 guint timout_tag_; |
| 85 | 85 |
| 86 // True iff the fetcher is paused. | 86 // True iff the fetcher is paused. |
| 87 bool paused_; | 87 bool paused_; |
| 88 | 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(MockHttpFetcher); | 89 DISALLOW_COPY_AND_ASSIGN(MockHttpFetcher); |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 } // namespace chromeos_update_engine | 92 } // namespace chromeos_update_engine |
| 93 | 93 |
| 94 #endif // UPDATE_ENGINE_MOCK_HTTP_FETCHER_H__ | 94 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_HTTP_FETCHER_H__ |
| OLD | NEW |