blob: 84673c88aaf39b7b805b48a6066e44970b640101 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2011 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
rspangler@google.com49fdf182009-10-10 00:57:34 +000016
Alex Deymo39910dc2015-11-09 17:04:30 -080017#include "update_engine/payload_consumer/download_action.h"
Alex Deymo8427b4a2014-11-05 14:00:32 -080018
Darin Petkov9d911fa2010-08-19 09:36:08 -070019#include <gmock/gmock.h>
rspangler@google.com49fdf182009-10-10 00:57:34 +000020#include <gtest/gtest.h>
Darin Petkov73058b42010-10-06 16:32:19 -070021
Ben Chan02f7c1d2014-10-18 15:18:02 -070022#include <memory>
David Zeuthen8f191b22013-08-06 12:27:50 -070023#include <string>
24#include <utility>
Sen Jiangba2213a2018-02-27 16:28:20 -080025#include <vector>
David Zeuthen8f191b22013-08-06 12:27:50 -070026
Alex Deymo60ca1a72015-06-18 18:19:15 -070027#include <base/bind.h>
Alex Vakulenko75039d72014-03-25 12:36:28 -070028#include <base/files/file_path.h>
Ben Chan06c76a42014-09-05 08:21:06 -070029#include <base/files/file_util.h>
Alex Deymo60ca1a72015-06-18 18:19:15 -070030#include <base/location.h>
Alex Vakulenko75039d72014-03-25 12:36:28 -070031#include <base/strings/stringprintf.h>
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070032#include <brillo/message_loops/fake_message_loop.h>
33#include <brillo/message_loops/message_loop.h>
David Zeuthen8f191b22013-08-06 12:27:50 -070034
Alex Deymo39910dc2015-11-09 17:04:30 -080035#include "update_engine/common/action_pipe.h"
36#include "update_engine/common/hash_calculator.h"
37#include "update_engine/common/mock_http_fetcher.h"
38#include "update_engine/common/mock_prefs.h"
39#include "update_engine/common/test_utils.h"
40#include "update_engine/common/utils.h"
David Zeuthen8f191b22013-08-06 12:27:50 -070041#include "update_engine/fake_p2p_manager_configuration.h"
Gilad Arnold5bb4c902014-04-10 12:32:13 -070042#include "update_engine/fake_system_state.h"
Aaron Wood9321f502017-09-07 11:18:54 -070043#include "update_engine/mock_file_writer.h"
Alex Deymo542c19b2015-12-03 07:43:31 -030044#include "update_engine/payload_consumer/mock_download_action.h"
Gilad Arnold4a0321b2014-10-28 15:57:30 -070045#include "update_engine/update_manager/fake_update_manager.h"
rspangler@google.com49fdf182009-10-10 00:57:34 +000046
47namespace chromeos_update_engine {
48
Alex Deymof329b932014-10-30 01:37:48 -070049using base::FilePath;
50using base::ReadFileToString;
51using base::WriteFile;
rspangler@google.com49fdf182009-10-10 00:57:34 +000052using std::string;
Ben Chan02f7c1d2014-10-18 15:18:02 -070053using std::unique_ptr;
Alex Deymoe5e5fe92015-10-05 09:28:19 -070054using test_utils::ScopedTempFile;
Darin Petkov9d911fa2010-08-19 09:36:08 -070055using testing::AtLeast;
56using testing::InSequence;
Gilad Arnold74b5f552014-10-07 08:17:16 -070057using testing::Return;
Aaron Wood9321f502017-09-07 11:18:54 -070058using testing::SetArgPointee;
Alex Deymof329b932014-10-30 01:37:48 -070059using testing::_;
rspangler@google.com49fdf182009-10-10 00:57:34 +000060
61class DownloadActionTest : public ::testing::Test { };
62
63namespace {
Darin Petkov9d911fa2010-08-19 09:36:08 -070064
rspangler@google.com49fdf182009-10-10 00:57:34 +000065class DownloadActionTestProcessorDelegate : public ActionProcessorDelegate {
66 public:
Amin Hassanid3f4bea2018-04-30 14:52:40 -070067 DownloadActionTestProcessorDelegate()
68 : processing_done_called_(false), expected_code_(ErrorCode::kSuccess) {}
Alex Deymo610277e2014-11-11 21:18:11 -080069 ~DownloadActionTestProcessorDelegate() override {
rspangler@google.com49fdf182009-10-10 00:57:34 +000070 EXPECT_TRUE(processing_done_called_);
71 }
Yunlian Jiang35866ed2015-01-29 13:09:20 -080072 void ProcessingDone(const ActionProcessor* processor,
73 ErrorCode code) override {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070074 brillo::MessageLoop::current()->BreakLoop();
75 brillo::Blob found_data;
adlr@google.comc98a7ed2009-12-04 18:54:03 +000076 ASSERT_TRUE(utils::ReadFile(path_, &found_data));
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -070077 if (expected_code_ != ErrorCode::kDownloadWriteError) {
Darin Petkov9ce452b2010-11-17 14:33:28 -080078 ASSERT_EQ(expected_data_.size(), found_data.size());
79 for (unsigned i = 0; i < expected_data_.size(); i++) {
80 EXPECT_EQ(expected_data_[i], found_data[i]);
81 }
rspangler@google.com49fdf182009-10-10 00:57:34 +000082 }
83 processing_done_called_ = true;
84 }
85
Yunlian Jiang35866ed2015-01-29 13:09:20 -080086 void ActionCompleted(ActionProcessor* processor,
87 AbstractAction* action,
88 ErrorCode code) override {
Darin Petkovc97435c2010-07-20 12:37:43 -070089 const string type = action->Type();
90 if (type == DownloadAction::StaticType()) {
91 EXPECT_EQ(expected_code_, code);
Amin Hassanid3f4bea2018-04-30 14:52:40 -070092 p2p_file_id_ = static_cast<DownloadAction*>(action)->p2p_file_id();
Darin Petkovc97435c2010-07-20 12:37:43 -070093 } else {
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -070094 EXPECT_EQ(ErrorCode::kSuccess, code);
Darin Petkovc97435c2010-07-20 12:37:43 -070095 }
rspangler@google.com49fdf182009-10-10 00:57:34 +000096 }
97
rspangler@google.com49fdf182009-10-10 00:57:34 +000098 string path_;
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070099 brillo::Blob expected_data_;
rspangler@google.com49fdf182009-10-10 00:57:34 +0000100 bool processing_done_called_;
David Zeuthena99981f2013-04-29 13:42:47 -0700101 ErrorCode expected_code_;
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700102 string p2p_file_id_;
rspangler@google.com49fdf182009-10-10 00:57:34 +0000103};
104
Darin Petkov9ce452b2010-11-17 14:33:28 -0800105class TestDirectFileWriter : public DirectFileWriter {
106 public:
107 TestDirectFileWriter() : fail_write_(0), current_write_(0) {}
108 void set_fail_write(int fail_write) { fail_write_ = fail_write; }
109
Don Garrette410e0f2011-11-10 15:39:01 -0800110 virtual bool Write(const void* bytes, size_t count) {
Darin Petkov9ce452b2010-11-17 14:33:28 -0800111 if (++current_write_ == fail_write_) {
Don Garrette410e0f2011-11-10 15:39:01 -0800112 return false;
Darin Petkov9ce452b2010-11-17 14:33:28 -0800113 }
114 return DirectFileWriter::Write(bytes, count);
115 }
116
117 private:
118 // If positive, fail on the |fail_write_| call to Write.
119 int fail_write_;
120 int current_write_;
121};
122
Alex Deymo60ca1a72015-06-18 18:19:15 -0700123void StartProcessorInRunLoop(ActionProcessor* processor,
124 MockHttpFetcher* http_fetcher) {
rspangler@google.com49fdf182009-10-10 00:57:34 +0000125 processor->StartProcessing();
Andrew de los Reyes34e41a12010-10-26 20:07:58 -0700126 http_fetcher->SetOffset(1);
rspangler@google.com49fdf182009-10-10 00:57:34 +0000127}
128
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700129void TestWithData(const brillo::Blob& data,
Darin Petkov9ce452b2010-11-17 14:33:28 -0800130 int fail_write,
Darin Petkov9d911fa2010-08-19 09:36:08 -0700131 bool use_download_delegate) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700132 brillo::FakeMessageLoop loop(nullptr);
Alex Deymo60ca1a72015-06-18 18:19:15 -0700133 loop.SetAsCurrent();
Alex Deymo5ed695e2015-10-05 16:59:23 -0700134 FakeSystemState fake_system_state;
rspangler@google.com49fdf182009-10-10 00:57:34 +0000135
136 // TODO(adlr): see if we need a different file for build bots
Andrew de los Reyesf9185172010-05-03 11:07:05 -0700137 ScopedTempFile output_temp_file;
Darin Petkov9ce452b2010-11-17 14:33:28 -0800138 TestDirectFileWriter writer;
Alex Deymobffa0602016-02-12 17:16:29 -0800139 EXPECT_EQ(
140 0, writer.Open(output_temp_file.path().c_str(), O_WRONLY | O_CREAT, 0));
Darin Petkov9ce452b2010-11-17 14:33:28 -0800141 writer.set_fail_write(fail_write);
Andrew de los Reyesf9185172010-05-03 11:07:05 -0700142
Sen Jiang5ae865b2017-04-18 14:24:40 -0700143 uint64_t size = data.size() - 1;
Alex Deymo64d98782016-02-05 18:03:48 -0800144 InstallPlan install_plan;
Sen Jiangcdd52062017-05-18 15:33:10 -0700145 install_plan.payloads.push_back(
146 {.size = size, .type = InstallPayloadType::kDelta});
Sen Jiang2703ef42017-03-16 13:36:21 -0700147 // We pull off the first byte from data and seek past it.
148 EXPECT_TRUE(HashCalculator::RawHashOfBytes(
Sen Jiang0affc2c2017-02-10 15:55:05 -0800149 &data[1], data.size() - 1, &install_plan.payloads[0].hash));
Alex Deymo5ed695e2015-10-05 16:59:23 -0700150 install_plan.source_slot = 0;
151 install_plan.target_slot = 1;
152 // We mark both slots as bootable. Only the target slot should be unbootable
153 // after the download starts.
154 fake_system_state.fake_boot_control()->SetSlotBootable(
155 install_plan.source_slot, true);
156 fake_system_state.fake_boot_control()->SetSlotBootable(
157 install_plan.target_slot, true);
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700158 auto feeder_action = std::make_unique<ObjectFeederAction<InstallPlan>>();
159 feeder_action->set_obj(install_plan);
Alex Deymo8427b4a2014-11-05 14:00:32 -0800160 MockPrefs prefs;
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -0800161 MockHttpFetcher* http_fetcher = new MockHttpFetcher(data.data(),
Andrew de los Reyes45168102010-11-22 11:13:50 -0800162 data.size(),
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700163 nullptr);
Andrew de los Reyes34e41a12010-10-26 20:07:58 -0700164 // takes ownership of passed in HttpFetcher
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700165 auto download_action =
166 std::make_unique<DownloadAction>(&prefs,
167 fake_system_state.boot_control(),
168 fake_system_state.hardware(),
169 &fake_system_state,
170 http_fetcher,
171 false /* interactive */);
172 download_action->SetTestFileWriter(&writer);
173 BondActions(feeder_action.get(), download_action.get());
Alex Deymo542c19b2015-12-03 07:43:31 -0300174 MockDownloadActionDelegate download_delegate;
Darin Petkov9d911fa2010-08-19 09:36:08 -0700175 if (use_download_delegate) {
176 InSequence s;
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700177 download_action->set_delegate(&download_delegate);
Andrew de los Reyes34e41a12010-10-26 20:07:58 -0700178 if (data.size() > kMockHttpFetcherChunkSize)
179 EXPECT_CALL(download_delegate,
Sen Jiang5ae865b2017-04-18 14:24:40 -0700180 BytesReceived(_, kMockHttpFetcherChunkSize, _));
Alex Deymo542c19b2015-12-03 07:43:31 -0300181 EXPECT_CALL(download_delegate, BytesReceived(_, _, _)).Times(AtLeast(1));
Sen Jiang7ebfccf2018-03-15 13:55:55 -0700182 EXPECT_CALL(download_delegate, DownloadComplete())
183 .Times(fail_write == 0 ? 1 : 0);
Darin Petkov9d911fa2010-08-19 09:36:08 -0700184 }
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700185 DownloadActionTestProcessorDelegate delegate;
186 delegate.expected_code_ =
187 (fail_write > 0) ? ErrorCode::kDownloadWriteError : ErrorCode::kSuccess;
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700188 delegate.expected_data_ = brillo::Blob(data.begin() + 1, data.end());
Alex Deymobffa0602016-02-12 17:16:29 -0800189 delegate.path_ = output_temp_file.path();
rspangler@google.com49fdf182009-10-10 00:57:34 +0000190 ActionProcessor processor;
191 processor.set_delegate(&delegate);
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700192 processor.EnqueueAction(std::move(feeder_action));
193 processor.EnqueueAction(std::move(download_action));
rspangler@google.com49fdf182009-10-10 00:57:34 +0000194
Alex Deymo60ca1a72015-06-18 18:19:15 -0700195 loop.PostTask(FROM_HERE,
196 base::Bind(&StartProcessorInRunLoop, &processor, http_fetcher));
197 loop.Run();
198 EXPECT_FALSE(loop.PendingTasks());
Alex Deymo5ed695e2015-10-05 16:59:23 -0700199
200 EXPECT_TRUE(fake_system_state.fake_boot_control()->IsSlotBootable(
201 install_plan.source_slot));
202 EXPECT_FALSE(fake_system_state.fake_boot_control()->IsSlotBootable(
203 install_plan.target_slot));
rspangler@google.com49fdf182009-10-10 00:57:34 +0000204}
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700205} // namespace
rspangler@google.com49fdf182009-10-10 00:57:34 +0000206
207TEST(DownloadActionTest, SimpleTest) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700208 brillo::Blob small;
rspangler@google.com49fdf182009-10-10 00:57:34 +0000209 const char* foo = "foo";
210 small.insert(small.end(), foo, foo + strlen(foo));
Darin Petkov50332f12010-09-24 11:44:47 -0700211 TestWithData(small,
Darin Petkov9ce452b2010-11-17 14:33:28 -0800212 0, // fail_write
Darin Petkov50332f12010-09-24 11:44:47 -0700213 true); // use_download_delegate
rspangler@google.com49fdf182009-10-10 00:57:34 +0000214}
215
216TEST(DownloadActionTest, LargeTest) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700217 brillo::Blob big(5 * kMockHttpFetcherChunkSize);
rspangler@google.com49fdf182009-10-10 00:57:34 +0000218 char c = '0';
219 for (unsigned int i = 0; i < big.size(); i++) {
220 big[i] = c;
Darin Petkov9ce452b2010-11-17 14:33:28 -0800221 c = ('9' == c) ? '0' : c + 1;
rspangler@google.com49fdf182009-10-10 00:57:34 +0000222 }
Darin Petkov50332f12010-09-24 11:44:47 -0700223 TestWithData(big,
Darin Petkov9ce452b2010-11-17 14:33:28 -0800224 0, // fail_write
225 true); // use_download_delegate
226}
227
228TEST(DownloadActionTest, FailWriteTest) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700229 brillo::Blob big(5 * kMockHttpFetcherChunkSize);
Darin Petkov9ce452b2010-11-17 14:33:28 -0800230 char c = '0';
231 for (unsigned int i = 0; i < big.size(); i++) {
232 big[i] = c;
233 c = ('9' == c) ? '0' : c + 1;
234 }
235 TestWithData(big,
Darin Petkov9ce452b2010-11-17 14:33:28 -0800236 2, // fail_write
Darin Petkov50332f12010-09-24 11:44:47 -0700237 true); // use_download_delegate
Darin Petkovc97435c2010-07-20 12:37:43 -0700238}
239
Darin Petkov9d911fa2010-08-19 09:36:08 -0700240TEST(DownloadActionTest, NoDownloadDelegateTest) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700241 brillo::Blob small;
Darin Petkov9d911fa2010-08-19 09:36:08 -0700242 const char* foo = "foofoo";
243 small.insert(small.end(), foo, foo + strlen(foo));
Darin Petkov50332f12010-09-24 11:44:47 -0700244 TestWithData(small,
Darin Petkov9ce452b2010-11-17 14:33:28 -0800245 0, // fail_write
Darin Petkov50332f12010-09-24 11:44:47 -0700246 false); // use_download_delegate
rspangler@google.com49fdf182009-10-10 00:57:34 +0000247}
248
Aaron Wood9321f502017-09-07 11:18:54 -0700249TEST(DownloadActionTest, MultiPayloadProgressTest) {
250 std::vector<brillo::Blob> payload_datas;
251 // the first payload must be the largest, as it's the actual payload used by
252 // the MockHttpFetcher for all downloaded data.
253 payload_datas.emplace_back(4 * kMockHttpFetcherChunkSize + 256);
254 payload_datas.emplace_back(2 * kMockHttpFetcherChunkSize);
255 brillo::FakeMessageLoop loop(nullptr);
256 loop.SetAsCurrent();
257 FakeSystemState fake_system_state;
258 EXPECT_CALL(*fake_system_state.mock_payload_state(), NextPayload())
259 .WillOnce(Return(true));
260
261 MockFileWriter mock_file_writer;
262 EXPECT_CALL(mock_file_writer, Close()).WillRepeatedly(Return(0));
263 EXPECT_CALL(mock_file_writer, Write(_, _, _))
264 .WillRepeatedly(
265 DoAll(SetArgPointee<2>(ErrorCode::kSuccess), Return(true)));
266
267 InstallPlan install_plan;
268 uint64_t total_expected_download_size{0};
269 for (const auto& data : payload_datas) {
270 uint64_t size = data.size();
271 install_plan.payloads.push_back(
272 {.size = size, .type = InstallPayloadType::kFull});
273 total_expected_download_size += size;
274 }
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700275 auto feeder_action = std::make_unique<ObjectFeederAction<InstallPlan>>();
276 feeder_action->set_obj(install_plan);
Aaron Wood9321f502017-09-07 11:18:54 -0700277 MockPrefs prefs;
278 MockHttpFetcher* http_fetcher = new MockHttpFetcher(
279 payload_datas[0].data(), payload_datas[0].size(), nullptr);
280 // takes ownership of passed in HttpFetcher
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700281 auto download_action =
282 std::make_unique<DownloadAction>(&prefs,
283 fake_system_state.boot_control(),
284 fake_system_state.hardware(),
285 &fake_system_state,
286 http_fetcher,
287 false /* interactive */);
288 download_action->SetTestFileWriter(&mock_file_writer);
289 BondActions(feeder_action.get(), download_action.get());
Aaron Wood9321f502017-09-07 11:18:54 -0700290 MockDownloadActionDelegate download_delegate;
291 {
292 InSequence s;
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700293 download_action->set_delegate(&download_delegate);
Aaron Wood9321f502017-09-07 11:18:54 -0700294 // these are hand-computed based on the payloads specified above
295 EXPECT_CALL(download_delegate,
296 BytesReceived(kMockHttpFetcherChunkSize,
297 kMockHttpFetcherChunkSize,
298 total_expected_download_size));
299 EXPECT_CALL(download_delegate,
300 BytesReceived(kMockHttpFetcherChunkSize,
301 kMockHttpFetcherChunkSize * 2,
302 total_expected_download_size));
303 EXPECT_CALL(download_delegate,
304 BytesReceived(kMockHttpFetcherChunkSize,
305 kMockHttpFetcherChunkSize * 3,
306 total_expected_download_size));
307 EXPECT_CALL(download_delegate,
308 BytesReceived(kMockHttpFetcherChunkSize,
309 kMockHttpFetcherChunkSize * 4,
310 total_expected_download_size));
311 EXPECT_CALL(download_delegate,
312 BytesReceived(256,
313 kMockHttpFetcherChunkSize * 4 + 256,
314 total_expected_download_size));
315 EXPECT_CALL(download_delegate,
316 BytesReceived(kMockHttpFetcherChunkSize,
317 kMockHttpFetcherChunkSize * 5 + 256,
318 total_expected_download_size));
319 EXPECT_CALL(download_delegate,
320 BytesReceived(kMockHttpFetcherChunkSize,
321 total_expected_download_size,
322 total_expected_download_size));
323 }
324 ActionProcessor processor;
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700325 processor.EnqueueAction(std::move(feeder_action));
326 processor.EnqueueAction(std::move(download_action));
Aaron Wood9321f502017-09-07 11:18:54 -0700327
328 loop.PostTask(
329 FROM_HERE,
330 base::Bind(
331 [](ActionProcessor* processor) { processor->StartProcessing(); },
332 base::Unretained(&processor)));
333 loop.Run();
334 EXPECT_FALSE(loop.PendingTasks());
335}
336
rspangler@google.com49fdf182009-10-10 00:57:34 +0000337namespace {
338class TerminateEarlyTestProcessorDelegate : public ActionProcessorDelegate {
339 public:
340 void ProcessingStopped(const ActionProcessor* processor) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700341 brillo::MessageLoop::current()->BreakLoop();
rspangler@google.com49fdf182009-10-10 00:57:34 +0000342 }
rspangler@google.com49fdf182009-10-10 00:57:34 +0000343};
344
Alex Deymo60ca1a72015-06-18 18:19:15 -0700345void TerminateEarlyTestStarter(ActionProcessor* processor) {
rspangler@google.com49fdf182009-10-10 00:57:34 +0000346 processor->StartProcessing();
347 CHECK(processor->IsRunning());
348 processor->StopProcessing();
rspangler@google.com49fdf182009-10-10 00:57:34 +0000349}
350
Darin Petkov9d911fa2010-08-19 09:36:08 -0700351void TestTerminateEarly(bool use_download_delegate) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700352 brillo::FakeMessageLoop loop(nullptr);
Alex Deymo60ca1a72015-06-18 18:19:15 -0700353 loop.SetAsCurrent();
rspangler@google.com49fdf182009-10-10 00:57:34 +0000354
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700355 brillo::Blob data(kMockHttpFetcherChunkSize +
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -0800356 kMockHttpFetcherChunkSize / 2);
357 memset(data.data(), 0, data.size());
rspangler@google.com49fdf182009-10-10 00:57:34 +0000358
Andrew de los Reyesf9185172010-05-03 11:07:05 -0700359 ScopedTempFile temp_file;
rspangler@google.com49fdf182009-10-10 00:57:34 +0000360 {
Andrew de los Reyesf9185172010-05-03 11:07:05 -0700361 DirectFileWriter writer;
Alex Deymobffa0602016-02-12 17:16:29 -0800362 EXPECT_EQ(0, writer.Open(temp_file.path().c_str(), O_WRONLY | O_CREAT, 0));
Andrew de los Reyesf9185172010-05-03 11:07:05 -0700363
rspangler@google.com49fdf182009-10-10 00:57:34 +0000364 // takes ownership of passed in HttpFetcher
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700365 auto feeder_action = std::make_unique<ObjectFeederAction<InstallPlan>>();
Alex Deymo64d98782016-02-05 18:03:48 -0800366 InstallPlan install_plan;
Sen Jiang0affc2c2017-02-10 15:55:05 -0800367 install_plan.payloads.resize(1);
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700368 feeder_action->set_obj(install_plan);
Alex Deymo5ed695e2015-10-05 16:59:23 -0700369 FakeSystemState fake_system_state_;
Alex Deymo8427b4a2014-11-05 14:00:32 -0800370 MockPrefs prefs;
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700371 auto download_action = std::make_unique<DownloadAction>(
Alex Deymo1b3556c2016-02-03 09:54:02 -0800372 &prefs,
373 fake_system_state_.boot_control(),
374 fake_system_state_.hardware(),
375 &fake_system_state_,
Amin Hassani7ecda262017-07-11 17:10:50 -0700376 new MockHttpFetcher(data.data(), data.size(), nullptr),
Amin Hassanied37d682018-04-06 13:22:00 -0700377 false /* interactive */);
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700378 download_action->SetTestFileWriter(&writer);
Alex Deymo542c19b2015-12-03 07:43:31 -0300379 MockDownloadActionDelegate download_delegate;
Darin Petkov9d911fa2010-08-19 09:36:08 -0700380 if (use_download_delegate) {
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700381 download_action->set_delegate(&download_delegate);
Alex Deymo542c19b2015-12-03 07:43:31 -0300382 EXPECT_CALL(download_delegate, BytesReceived(_, _, _)).Times(0);
Darin Petkov9d911fa2010-08-19 09:36:08 -0700383 }
rspangler@google.com49fdf182009-10-10 00:57:34 +0000384 TerminateEarlyTestProcessorDelegate delegate;
rspangler@google.com49fdf182009-10-10 00:57:34 +0000385 ActionProcessor processor;
386 processor.set_delegate(&delegate);
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700387 BondActions(feeder_action.get(), download_action.get());
388 processor.EnqueueAction(std::move(feeder_action));
389 processor.EnqueueAction(std::move(download_action));
rspangler@google.com49fdf182009-10-10 00:57:34 +0000390
Alex Deymo60ca1a72015-06-18 18:19:15 -0700391 loop.PostTask(FROM_HERE,
392 base::Bind(&TerminateEarlyTestStarter, &processor));
393 loop.Run();
394 EXPECT_FALSE(loop.PendingTasks());
rspangler@google.com49fdf182009-10-10 00:57:34 +0000395 }
396
397 // 1 or 0 chunks should have come through
Alex Deymobffa0602016-02-12 17:16:29 -0800398 const off_t resulting_file_size(utils::FileSize(temp_file.path()));
Andrew de los Reyesf9185172010-05-03 11:07:05 -0700399 EXPECT_GE(resulting_file_size, 0);
rspangler@google.com49fdf182009-10-10 00:57:34 +0000400 if (resulting_file_size != 0)
Alex Deymo5fe0c4e2016-02-16 18:46:24 -0800401 EXPECT_EQ(kMockHttpFetcherChunkSize,
402 static_cast<size_t>(resulting_file_size));
rspangler@google.com49fdf182009-10-10 00:57:34 +0000403}
404
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700405} // namespace
Darin Petkov9d911fa2010-08-19 09:36:08 -0700406
407TEST(DownloadActionTest, TerminateEarlyTest) {
408 TestTerminateEarly(true);
409}
410
411TEST(DownloadActionTest, TerminateEarlyNoDownloadDelegateTest) {
412 TestTerminateEarly(false);
413}
414
rspangler@google.com49fdf182009-10-10 00:57:34 +0000415class DownloadActionTestAction;
416
417template<>
418class ActionTraits<DownloadActionTestAction> {
419 public:
adlr@google.comc98a7ed2009-12-04 18:54:03 +0000420 typedef InstallPlan OutputObjectType;
421 typedef InstallPlan InputObjectType;
rspangler@google.com49fdf182009-10-10 00:57:34 +0000422};
423
424// This is a simple Action class for testing.
Yunlian Jiang2dac5762013-04-12 09:53:09 -0700425class DownloadActionTestAction : public Action<DownloadActionTestAction> {
426 public:
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700427 DownloadActionTestAction() = default;
adlr@google.comc98a7ed2009-12-04 18:54:03 +0000428 typedef InstallPlan InputObjectType;
429 typedef InstallPlan OutputObjectType;
430 ActionPipe<InstallPlan>* in_pipe() { return in_pipe_.get(); }
431 ActionPipe<InstallPlan>* out_pipe() { return out_pipe_.get(); }
rspangler@google.com49fdf182009-10-10 00:57:34 +0000432 ActionProcessor* processor() { return processor_; }
433 void PerformAction() {
rspangler@google.com49fdf182009-10-10 00:57:34 +0000434 ASSERT_TRUE(HasInputObject());
adlr@google.comc98a7ed2009-12-04 18:54:03 +0000435 EXPECT_TRUE(expected_input_object_ == GetInputObject());
rspangler@google.com49fdf182009-10-10 00:57:34 +0000436 ASSERT_TRUE(processor());
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700437 processor()->ActionComplete(this, ErrorCode::kSuccess);
rspangler@google.com49fdf182009-10-10 00:57:34 +0000438 }
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700439 static std::string StaticType() { return "DownloadActionTestAction"; }
440 string Type() const { return StaticType(); }
adlr@google.comc98a7ed2009-12-04 18:54:03 +0000441 InstallPlan expected_input_object_;
rspangler@google.com49fdf182009-10-10 00:57:34 +0000442};
443
444namespace {
445// This class is an ActionProcessorDelegate that simply terminates the
446// run loop when the ActionProcessor has completed processing. It's used
447// only by the test PassObjectOutTest.
448class PassObjectOutTestProcessorDelegate : public ActionProcessorDelegate {
449 public:
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700450 void ProcessingDone(const ActionProcessor* processor,
451 ErrorCode code) override {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700452 brillo::MessageLoop::current()->BreakLoop();
rspangler@google.com49fdf182009-10-10 00:57:34 +0000453 }
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700454 void ActionCompleted(ActionProcessor* processor,
455 AbstractAction* action,
456 ErrorCode code) override {
457 if (action->Type() == DownloadActionTestAction::StaticType()) {
458 did_test_action_run_ = true;
459 }
460 }
461
462 bool did_test_action_run_ = false;
rspangler@google.com49fdf182009-10-10 00:57:34 +0000463};
464
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700465} // namespace
rspangler@google.com49fdf182009-10-10 00:57:34 +0000466
467TEST(DownloadActionTest, PassObjectOutTest) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700468 brillo::FakeMessageLoop loop(nullptr);
Alex Deymo60ca1a72015-06-18 18:19:15 -0700469 loop.SetAsCurrent();
rspangler@google.com49fdf182009-10-10 00:57:34 +0000470
Andrew de los Reyesf9185172010-05-03 11:07:05 -0700471 DirectFileWriter writer;
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700472 EXPECT_EQ(0, writer.Open("/dev/null", O_WRONLY | O_CREAT, 0));
Andrew de los Reyesf9185172010-05-03 11:07:05 -0700473
rspangler@google.com49fdf182009-10-10 00:57:34 +0000474 // takes ownership of passed in HttpFetcher
Alex Deymo64d98782016-02-05 18:03:48 -0800475 InstallPlan install_plan;
Sen Jiang0affc2c2017-02-10 15:55:05 -0800476 install_plan.payloads.push_back({.size = 1});
477 EXPECT_TRUE(
478 HashCalculator::RawHashOfData({'x'}, &install_plan.payloads[0].hash));
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700479 auto feeder_action = std::make_unique<ObjectFeederAction<InstallPlan>>();
480 feeder_action->set_obj(install_plan);
Alex Deymo8427b4a2014-11-05 14:00:32 -0800481 MockPrefs prefs;
Alex Deymo5ed695e2015-10-05 16:59:23 -0700482 FakeSystemState fake_system_state_;
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700483 auto download_action =
484 std::make_unique<DownloadAction>(&prefs,
485 fake_system_state_.boot_control(),
486 fake_system_state_.hardware(),
487 &fake_system_state_,
488 new MockHttpFetcher("x", 1, nullptr),
489 false /* interactive */);
490 download_action->SetTestFileWriter(&writer);
rspangler@google.com49fdf182009-10-10 00:57:34 +0000491
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700492 auto test_action = std::make_unique<DownloadActionTestAction>();
493 test_action->expected_input_object_ = install_plan;
494 BondActions(feeder_action.get(), download_action.get());
495 BondActions(download_action.get(), test_action.get());
rspangler@google.com49fdf182009-10-10 00:57:34 +0000496
497 ActionProcessor processor;
498 PassObjectOutTestProcessorDelegate delegate;
rspangler@google.com49fdf182009-10-10 00:57:34 +0000499 processor.set_delegate(&delegate);
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700500 processor.EnqueueAction(std::move(feeder_action));
501 processor.EnqueueAction(std::move(download_action));
502 processor.EnqueueAction(std::move(test_action));
rspangler@google.com49fdf182009-10-10 00:57:34 +0000503
Luis Hector Chavezf1cf3482016-07-19 14:29:19 -0700504 loop.PostTask(
505 FROM_HERE,
506 base::Bind(
507 [](ActionProcessor* processor) { processor->StartProcessing(); },
508 base::Unretained(&processor)));
Alex Deymo60ca1a72015-06-18 18:19:15 -0700509 loop.Run();
510 EXPECT_FALSE(loop.PendingTasks());
rspangler@google.com49fdf182009-10-10 00:57:34 +0000511
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700512 EXPECT_EQ(true, delegate.did_test_action_run_);
rspangler@google.com49fdf182009-10-10 00:57:34 +0000513}
514
David Zeuthen8f191b22013-08-06 12:27:50 -0700515// Test fixture for P2P tests.
516class P2PDownloadActionTest : public testing::Test {
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700517 protected:
David Zeuthen8f191b22013-08-06 12:27:50 -0700518 P2PDownloadActionTest()
Alex Deymo60ca1a72015-06-18 18:19:15 -0700519 : start_at_offset_(0),
Gilad Arnold4a0321b2014-10-28 15:57:30 -0700520 fake_um_(fake_system_state_.fake_clock()) {}
David Zeuthen8f191b22013-08-06 12:27:50 -0700521
Alex Deymo610277e2014-11-11 21:18:11 -0800522 ~P2PDownloadActionTest() override {}
David Zeuthen8f191b22013-08-06 12:27:50 -0700523
524 // Derived from testing::Test.
Alex Deymo610277e2014-11-11 21:18:11 -0800525 void SetUp() override {
Alex Deymo60ca1a72015-06-18 18:19:15 -0700526 loop_.SetAsCurrent();
David Zeuthen8f191b22013-08-06 12:27:50 -0700527 }
528
529 // Derived from testing::Test.
Alex Deymo610277e2014-11-11 21:18:11 -0800530 void TearDown() override {
Alex Deymo60ca1a72015-06-18 18:19:15 -0700531 EXPECT_FALSE(loop_.PendingTasks());
David Zeuthen8f191b22013-08-06 12:27:50 -0700532 }
533
534 // To be called by tests to setup the download. The
535 // |starting_offset| parameter is for where to resume.
536 void SetupDownload(off_t starting_offset) {
537 start_at_offset_ = starting_offset;
538 // Prepare data 10 kB of data.
539 data_.clear();
540 for (unsigned int i = 0; i < 10 * 1000; i++)
541 data_ += 'a' + (i % 25);
542
543 // Setup p2p.
544 FakeP2PManagerConfiguration *test_conf = new FakeP2PManagerConfiguration();
David Zeuthen41f2cf52014-11-05 12:29:45 -0500545 p2p_manager_.reset(P2PManager::Construct(
Gilad Arnold4a0321b2014-10-28 15:57:30 -0700546 test_conf, nullptr, &fake_um_, "cros_au", 3,
David Zeuthen41f2cf52014-11-05 12:29:45 -0500547 base::TimeDelta::FromDays(5)));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700548 fake_system_state_.set_p2p_manager(p2p_manager_.get());
David Zeuthen8f191b22013-08-06 12:27:50 -0700549 }
550
551 // To be called by tests to perform the download. The
552 // |use_p2p_to_share| parameter is used to indicate whether the
553 // payload should be shared via p2p.
554 void StartDownload(bool use_p2p_to_share) {
Gilad Arnold74b5f552014-10-07 08:17:16 -0700555 EXPECT_CALL(*fake_system_state_.mock_payload_state(),
556 GetUsingP2PForSharing())
557 .WillRepeatedly(Return(use_p2p_to_share));
David Zeuthen8f191b22013-08-06 12:27:50 -0700558
559 ScopedTempFile output_temp_file;
560 TestDirectFileWriter writer;
Alex Deymobffa0602016-02-12 17:16:29 -0800561 EXPECT_EQ(
562 0, writer.Open(output_temp_file.path().c_str(), O_WRONLY | O_CREAT, 0));
Alex Deymo64d98782016-02-05 18:03:48 -0800563 InstallPlan install_plan;
Sen Jiang0affc2c2017-02-10 15:55:05 -0800564 install_plan.payloads.push_back(
565 {.size = data_.length(),
566 .hash = {'1', '2', '3', '4', 'h', 'a', 's', 'h'}});
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700567 auto feeder_action = std::make_unique<ObjectFeederAction<InstallPlan>>();
568 feeder_action->set_obj(install_plan);
Alex Deymo8427b4a2014-11-05 14:00:32 -0800569 MockPrefs prefs;
David Zeuthen8f191b22013-08-06 12:27:50 -0700570 // Note that DownloadAction takes ownership of the passed in HttpFetcher.
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700571 auto download_action = std::make_unique<DownloadAction>(
572 &prefs,
573 fake_system_state_.boot_control(),
574 fake_system_state_.hardware(),
575 &fake_system_state_,
576 new MockHttpFetcher(data_.c_str(), data_.length(), nullptr),
577 false /* interactive */);
578 auto http_fetcher = download_action->http_fetcher();
579 download_action->SetTestFileWriter(&writer);
580 BondActions(feeder_action.get(), download_action.get());
581 delegate_.expected_data_ =
582 brillo::Blob(data_.begin() + start_at_offset_, data_.end());
583 delegate_.path_ = output_temp_file.path();
584 processor_.set_delegate(&delegate_);
585 processor_.EnqueueAction(std::move(feeder_action));
586 processor_.EnqueueAction(std::move(download_action));
David Zeuthen8f191b22013-08-06 12:27:50 -0700587
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700588 loop_.PostTask(
589 FROM_HERE,
590 base::Bind(
591 [](P2PDownloadActionTest* action_test, HttpFetcher* http_fetcher) {
592 action_test->processor_.StartProcessing();
593 http_fetcher->SetOffset(action_test->start_at_offset_);
594 },
595 base::Unretained(this),
596 base::Unretained(http_fetcher)));
Alex Deymo60ca1a72015-06-18 18:19:15 -0700597 loop_.Run();
David Zeuthen8f191b22013-08-06 12:27:50 -0700598 }
599
Alex Deymo60ca1a72015-06-18 18:19:15 -0700600 // Mainloop used to make StartDownload() synchronous.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700601 brillo::FakeMessageLoop loop_{nullptr};
Alex Deymo60ca1a72015-06-18 18:19:15 -0700602
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700603 // Delegate that is passed to the ActionProcessor.
604 DownloadActionTestProcessorDelegate delegate_;
David Zeuthen8f191b22013-08-06 12:27:50 -0700605
606 // The P2PManager used in the test.
Ben Chan02f7c1d2014-10-18 15:18:02 -0700607 unique_ptr<P2PManager> p2p_manager_;
David Zeuthen8f191b22013-08-06 12:27:50 -0700608
609 // The ActionProcessor used for running the actions.
610 ActionProcessor processor_;
611
612 // A fake system state.
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700613 FakeSystemState fake_system_state_;
David Zeuthen8f191b22013-08-06 12:27:50 -0700614
615 // The data being downloaded.
616 string data_;
617
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700618 private:
David Zeuthen8f191b22013-08-06 12:27:50 -0700619 // The requested starting offset passed to SetupDownload().
620 off_t start_at_offset_;
Gilad Arnold4a0321b2014-10-28 15:57:30 -0700621
622 chromeos_update_manager::FakeUpdateManager fake_um_;
David Zeuthen8f191b22013-08-06 12:27:50 -0700623};
624
625TEST_F(P2PDownloadActionTest, IsWrittenTo) {
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700626 SetupDownload(0); // starting_offset
627 StartDownload(true); // use_p2p_to_share
David Zeuthen8f191b22013-08-06 12:27:50 -0700628
629 // Check the p2p file and its content matches what was sent.
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700630 string file_id = delegate_.p2p_file_id_;
Gilad Arnold74b5f552014-10-07 08:17:16 -0700631 EXPECT_NE("", file_id);
Alex Deymo80f70ff2016-02-10 16:08:11 -0800632 EXPECT_EQ(static_cast<int>(data_.length()),
633 p2p_manager_->FileGetSize(file_id));
634 EXPECT_EQ(static_cast<int>(data_.length()),
635 p2p_manager_->FileGetExpectedSize(file_id));
David Zeuthen8f191b22013-08-06 12:27:50 -0700636 string p2p_file_contents;
637 EXPECT_TRUE(ReadFileToString(p2p_manager_->FileGetPath(file_id),
638 &p2p_file_contents));
639 EXPECT_EQ(data_, p2p_file_contents);
640}
641
642TEST_F(P2PDownloadActionTest, DeleteIfHoleExists) {
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700643 SetupDownload(1000); // starting_offset
644 StartDownload(true); // use_p2p_to_share
David Zeuthen8f191b22013-08-06 12:27:50 -0700645
646 // DownloadAction should convey that the file is not being shared.
647 // and that we don't have any p2p files.
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700648 EXPECT_EQ(delegate_.p2p_file_id_, "");
David Zeuthen8f191b22013-08-06 12:27:50 -0700649 EXPECT_EQ(p2p_manager_->CountSharedFiles(), 0);
650}
651
652TEST_F(P2PDownloadActionTest, CanAppend) {
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700653 SetupDownload(1000); // starting_offset
David Zeuthen8f191b22013-08-06 12:27:50 -0700654
655 // Prepare the file with existing data before starting to write to
656 // it via DownloadAction.
Sen Jiang2703ef42017-03-16 13:36:21 -0700657 string file_id = utils::CalculateP2PFileId(
658 {'1', '2', '3', '4', 'h', 'a', 's', 'h'}, data_.length());
David Zeuthen8f191b22013-08-06 12:27:50 -0700659 ASSERT_TRUE(p2p_manager_->FileShare(file_id, data_.length()));
660 string existing_data;
661 for (unsigned int i = 0; i < 1000; i++)
662 existing_data += '0' + (i % 10);
663 ASSERT_EQ(WriteFile(p2p_manager_->FileGetPath(file_id), existing_data.c_str(),
664 1000), 1000);
665
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700666 StartDownload(true); // use_p2p_to_share
David Zeuthen8f191b22013-08-06 12:27:50 -0700667
668 // DownloadAction should convey the same file_id and the file should
669 // have the expected size.
Amin Hassanid3f4bea2018-04-30 14:52:40 -0700670 EXPECT_EQ(delegate_.p2p_file_id_, file_id);
Alex Deymo80f70ff2016-02-10 16:08:11 -0800671 EXPECT_EQ(static_cast<ssize_t>(data_.length()),
672 p2p_manager_->FileGetSize(file_id));
673 EXPECT_EQ(static_cast<ssize_t>(data_.length()),
674 p2p_manager_->FileGetExpectedSize(file_id));
David Zeuthen8f191b22013-08-06 12:27:50 -0700675 string p2p_file_contents;
676 // Check that the first 1000 bytes wasn't touched and that we
677 // appended the remaining as appropriate.
678 EXPECT_TRUE(ReadFileToString(p2p_manager_->FileGetPath(file_id),
679 &p2p_file_contents));
680 EXPECT_EQ(existing_data, p2p_file_contents.substr(0, 1000));
681 EXPECT_EQ(data_.substr(1000), p2p_file_contents.substr(1000));
682}
683
David Zeuthen8f191b22013-08-06 12:27:50 -0700684TEST_F(P2PDownloadActionTest, DeletePartialP2PFileIfResumingWithoutP2P) {
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700685 SetupDownload(1000); // starting_offset
David Zeuthen8f191b22013-08-06 12:27:50 -0700686
687 // Prepare the file with all existing data before starting to write
688 // to it via DownloadAction.
Sen Jiang2703ef42017-03-16 13:36:21 -0700689 string file_id = utils::CalculateP2PFileId(
690 {'1', '2', '3', '4', 'h', 'a', 's', 'h'}, data_.length());
David Zeuthen8f191b22013-08-06 12:27:50 -0700691 ASSERT_TRUE(p2p_manager_->FileShare(file_id, data_.length()));
692 string existing_data;
693 for (unsigned int i = 0; i < 1000; i++)
694 existing_data += '0' + (i % 10);
695 ASSERT_EQ(WriteFile(p2p_manager_->FileGetPath(file_id), existing_data.c_str(),
696 1000), 1000);
697
698 // Check that the file is there.
Alex Deymo80f70ff2016-02-10 16:08:11 -0800699 EXPECT_EQ(1000, p2p_manager_->FileGetSize(file_id));
700 EXPECT_EQ(1, p2p_manager_->CountSharedFiles());
David Zeuthen8f191b22013-08-06 12:27:50 -0700701
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700702 StartDownload(false); // use_p2p_to_share
David Zeuthen8f191b22013-08-06 12:27:50 -0700703
704 // DownloadAction should have deleted the p2p file. Check that it's gone.
Alex Deymo80f70ff2016-02-10 16:08:11 -0800705 EXPECT_EQ(-1, p2p_manager_->FileGetSize(file_id));
706 EXPECT_EQ(0, p2p_manager_->CountSharedFiles());
David Zeuthen8f191b22013-08-06 12:27:50 -0700707}
708
rspangler@google.com49fdf182009-10-10 00:57:34 +0000709} // namespace chromeos_update_engine