| 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 #include <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include <glib.h> | 8 #include <glib.h> |
| 9 #include <gmock/gmock.h> | 9 #include <gmock/gmock.h> |
| 10 #include <gtest/gtest.h> | 10 #include <gtest/gtest.h> |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // TODO(adlr): see if we need a different file for build bots | 95 // TODO(adlr): see if we need a different file for build bots |
| 96 ScopedTempFile output_temp_file; | 96 ScopedTempFile output_temp_file; |
| 97 DirectFileWriter writer; | 97 DirectFileWriter writer; |
| 98 | 98 |
| 99 // takes ownership of passed in HttpFetcher | 99 // takes ownership of passed in HttpFetcher |
| 100 string hash = hash_test ? | 100 string hash = hash_test ? |
| 101 OmahaHashCalculator::OmahaHashOfString("random string") : | 101 OmahaHashCalculator::OmahaHashOfString("random string") : |
| 102 OmahaHashCalculator::OmahaHashOfData(data); | 102 OmahaHashCalculator::OmahaHashOfData(data); |
| 103 uint64_t size = data.size() + (size_test ? 1 : 0); | 103 uint64_t size = data.size() + (size_test ? 1 : 0); |
| 104 InstallPlan install_plan(true, | 104 InstallPlan install_plan(true, |
| 105 false, |
| 105 "", | 106 "", |
| 106 size, | 107 size, |
| 107 hash, | 108 hash, |
| 108 output_temp_file.GetPath(), | 109 output_temp_file.GetPath(), |
| 109 ""); | 110 ""); |
| 110 ObjectFeederAction<InstallPlan> feeder_action; | 111 ObjectFeederAction<InstallPlan> feeder_action; |
| 111 feeder_action.set_obj(install_plan); | 112 feeder_action.set_obj(install_plan); |
| 112 PrefsMock prefs; | 113 PrefsMock prefs; |
| 113 DownloadAction download_action(&prefs, new MockHttpFetcher(&data[0], | 114 DownloadAction download_action(&prefs, new MockHttpFetcher(&data[0], |
| 114 data.size())); | 115 data.size())); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 221 |
| 221 vector<char> data(kMockHttpFetcherChunkSize + kMockHttpFetcherChunkSize / 2); | 222 vector<char> data(kMockHttpFetcherChunkSize + kMockHttpFetcherChunkSize / 2); |
| 222 memset(&data[0], 0, data.size()); | 223 memset(&data[0], 0, data.size()); |
| 223 | 224 |
| 224 ScopedTempFile temp_file; | 225 ScopedTempFile temp_file; |
| 225 { | 226 { |
| 226 DirectFileWriter writer; | 227 DirectFileWriter writer; |
| 227 | 228 |
| 228 // takes ownership of passed in HttpFetcher | 229 // takes ownership of passed in HttpFetcher |
| 229 ObjectFeederAction<InstallPlan> feeder_action; | 230 ObjectFeederAction<InstallPlan> feeder_action; |
| 230 InstallPlan install_plan(true, "", 0, "", temp_file.GetPath(), ""); | 231 InstallPlan install_plan(true, false, "", 0, "", temp_file.GetPath(), ""); |
| 231 feeder_action.set_obj(install_plan); | 232 feeder_action.set_obj(install_plan); |
| 232 PrefsMock prefs; | 233 PrefsMock prefs; |
| 233 DownloadAction download_action(&prefs, | 234 DownloadAction download_action(&prefs, |
| 234 new MockHttpFetcher(&data[0], data.size())); | 235 new MockHttpFetcher(&data[0], data.size())); |
| 235 download_action.SetTestFileWriter(&writer); | 236 download_action.SetTestFileWriter(&writer); |
| 236 DownloadActionDelegateMock download_delegate; | 237 DownloadActionDelegateMock download_delegate; |
| 237 if (use_download_delegate) { | 238 if (use_download_delegate) { |
| 238 InSequence s; | 239 InSequence s; |
| 239 download_action.set_delegate(&download_delegate); | 240 download_action.set_delegate(&download_delegate); |
| 240 EXPECT_CALL(download_delegate, SetDownloadStatus(true)).Times(1); | 241 EXPECT_CALL(download_delegate, SetDownloadStatus(true)).Times(1); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 } | 320 } |
| 320 } | 321 } |
| 321 | 322 |
| 322 TEST(DownloadActionTest, PassObjectOutTest) { | 323 TEST(DownloadActionTest, PassObjectOutTest) { |
| 323 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); | 324 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 324 | 325 |
| 325 DirectFileWriter writer; | 326 DirectFileWriter writer; |
| 326 | 327 |
| 327 // takes ownership of passed in HttpFetcher | 328 // takes ownership of passed in HttpFetcher |
| 328 InstallPlan install_plan(true, | 329 InstallPlan install_plan(true, |
| 330 false, |
| 329 "", | 331 "", |
| 330 1, | 332 1, |
| 331 OmahaHashCalculator::OmahaHashOfString("x"), | 333 OmahaHashCalculator::OmahaHashOfString("x"), |
| 332 "/dev/null", | 334 "/dev/null", |
| 333 "/dev/null"); | 335 "/dev/null"); |
| 334 ObjectFeederAction<InstallPlan> feeder_action; | 336 ObjectFeederAction<InstallPlan> feeder_action; |
| 335 feeder_action.set_obj(install_plan); | 337 feeder_action.set_obj(install_plan); |
| 336 PrefsMock prefs; | 338 PrefsMock prefs; |
| 337 DownloadAction download_action(&prefs, new MockHttpFetcher("x", 1)); | 339 DownloadAction download_action(&prefs, new MockHttpFetcher("x", 1)); |
| 338 download_action.SetTestFileWriter(&writer); | 340 download_action.SetTestFileWriter(&writer); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 357 EXPECT_EQ(true, test_action.did_run_); | 359 EXPECT_EQ(true, test_action.did_run_); |
| 358 } | 360 } |
| 359 | 361 |
| 360 TEST(DownloadActionTest, BadOutFileTest) { | 362 TEST(DownloadActionTest, BadOutFileTest) { |
| 361 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); | 363 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 362 | 364 |
| 363 const string path("/fake/path/that/cant/be/created/because/of/missing/dirs"); | 365 const string path("/fake/path/that/cant/be/created/because/of/missing/dirs"); |
| 364 DirectFileWriter writer; | 366 DirectFileWriter writer; |
| 365 | 367 |
| 366 // takes ownership of passed in HttpFetcher | 368 // takes ownership of passed in HttpFetcher |
| 367 InstallPlan install_plan(true, "", 0, "", path, ""); | 369 InstallPlan install_plan(true, false, "", 0, "", path, ""); |
| 368 ObjectFeederAction<InstallPlan> feeder_action; | 370 ObjectFeederAction<InstallPlan> feeder_action; |
| 369 feeder_action.set_obj(install_plan); | 371 feeder_action.set_obj(install_plan); |
| 370 PrefsMock prefs; | 372 PrefsMock prefs; |
| 371 DownloadAction download_action(&prefs, new MockHttpFetcher("x", 1)); | 373 DownloadAction download_action(&prefs, new MockHttpFetcher("x", 1)); |
| 372 download_action.SetTestFileWriter(&writer); | 374 download_action.SetTestFileWriter(&writer); |
| 373 | 375 |
| 374 BondActions(&feeder_action, &download_action); | 376 BondActions(&feeder_action, &download_action); |
| 375 | 377 |
| 376 ActionProcessor processor; | 378 ActionProcessor processor; |
| 377 processor.EnqueueAction(&feeder_action); | 379 processor.EnqueueAction(&feeder_action); |
| 378 processor.EnqueueAction(&download_action); | 380 processor.EnqueueAction(&download_action); |
| 379 processor.StartProcessing(); | 381 processor.StartProcessing(); |
| 380 ASSERT_FALSE(processor.IsRunning()); | 382 ASSERT_FALSE(processor.IsRunning()); |
| 381 | 383 |
| 382 g_main_loop_unref(loop); | 384 g_main_loop_unref(loop); |
| 383 } | 385 } |
| 384 | 386 |
| 385 } // namespace chromeos_update_engine | 387 } // namespace chromeos_update_engine |
| OLD | NEW |