Index: chrome/browser/component_updater/test/component_patcher_unittest.cc |
diff --git a/chrome/browser/component_updater/test/component_patcher_unittest.cc b/chrome/browser/component_updater/test/component_patcher_unittest.cc |
index 3cc4f65610b8cbce7d2f26f08b35ba91a036ca50..8769545f276048c4c13f18637c11280f75b2edaa 100644 |
--- a/chrome/browser/component_updater/test/component_patcher_unittest.cc |
+++ b/chrome/browser/component_updater/test/component_patcher_unittest.cc |
@@ -2,23 +2,55 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "base/bind.h" |
#include "base/compiler_specific.h" |
#include "base/file_util.h" |
#include "base/files/file_path.h" |
#include "base/files/scoped_temp_dir.h" |
+#include "base/message_loop/message_loop.h" |
#include "base/path_service.h" |
+#include "base/run_loop.h" |
#include "base/values.h" |
#include "chrome/browser/component_updater/component_patcher.h" |
#include "chrome/browser/component_updater/component_patcher_operation.h" |
#include "chrome/browser/component_updater/component_updater_service.h" |
-#include "chrome/browser/component_updater/test/component_patcher_mock.h" |
#include "chrome/browser/component_updater/test/component_patcher_unittest.h" |
#include "chrome/browser/component_updater/test/test_installer.h" |
#include "chrome/common/chrome_paths.h" |
+#include "content/public/browser/browser_thread.h" |
#include "courgette/courgette.h" |
#include "courgette/third_party/bsdiff.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+namespace { |
+ |
+class TestCallback { |
+ public: |
+ TestCallback(); |
+ virtual ~TestCallback() {} |
+ void Set(component_updater::ComponentUnpacker::Error error, int extra_code); |
+ |
+ int error_; |
+ int extra_code_; |
+ bool called_; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(TestCallback); |
+}; |
+ |
+TestCallback::TestCallback() |
+ : error_(-1), extra_code_(-1), called_(false) { |
+} |
+ |
+void TestCallback::Set(component_updater::ComponentUnpacker::Error error, |
+ int extra_code) { |
+ error_ = error; |
+ extra_code_ = extra_code; |
+ called_ = true; |
+} |
+ |
+} // namespace |
+ |
namespace component_updater { |
namespace { |
@@ -35,39 +67,14 @@ ComponentPatcherOperationTest::ComponentPatcherOperationTest() { |
EXPECT_TRUE(unpack_dir_.CreateUniqueTempDir()); |
EXPECT_TRUE(input_dir_.CreateUniqueTempDir()); |
EXPECT_TRUE(installed_dir_.CreateUniqueTempDir()); |
- patcher_.reset(new MockComponentPatcher()); |
installer_.reset(new ReadOnlyTestInstaller(installed_dir_.path())); |
+ task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread( |
+ content::BrowserThread::FILE); |
} |
ComponentPatcherOperationTest::~ComponentPatcherOperationTest() { |
} |
-ComponentUnpacker::Error MockComponentPatcher::Patch( |
- PatchType patch_type, |
- const base::FilePath& input_file, |
- const base::FilePath& patch_file, |
- const base::FilePath& output_file, |
- int* error) { |
- *error = 0; |
- int exit_code; |
- if (patch_type == kPatchTypeCourgette) { |
- exit_code = courgette::ApplyEnsemblePatch(input_file.value().c_str(), |
- patch_file.value().c_str(), |
- output_file.value().c_str()); |
- if (exit_code == courgette::C_OK) |
- return ComponentUnpacker::kNone; |
- *error = exit_code + kCourgetteErrorOffset; |
- } else if (patch_type == kPatchTypeBsdiff) { |
- exit_code = courgette::ApplyBinaryPatch(input_file, |
- patch_file, |
- output_file); |
- if (exit_code == courgette::OK) |
- return ComponentUnpacker::kNone; |
- *error = exit_code + kBsdiffErrorOffset; |
- } |
- return ComponentUnpacker::kDeltaOperationFailure; |
-} |
- |
// Verify that a 'create' delta update operation works correctly. |
TEST_F(ComponentPatcherOperationTest, CheckCreateOperation) { |
EXPECT_TRUE(base::CopyFile( |
@@ -80,17 +87,20 @@ TEST_F(ComponentPatcherOperationTest, CheckCreateOperation) { |
command_args->SetString("op", "create"); |
command_args->SetString("patch", "binary_output.bin"); |
- int error = 0; |
- scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpCreate()); |
- ComponentUnpacker::Error result = op->Run(command_args.get(), |
- input_dir_.path(), |
- unpack_dir_.path(), |
- patcher_.get(), |
- NULL, |
- &error); |
- |
- EXPECT_EQ(ComponentUnpacker::kNone, result); |
- EXPECT_EQ(0, error); |
+ TestCallback callback; |
+ scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCreate(); |
+ op->Run(command_args.get(), |
+ input_dir_.path(), |
+ unpack_dir_.path(), |
+ NULL, |
+ true, |
+ base::Bind(&TestCallback::Set, base::Unretained(&callback)), |
+ task_runner_); |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ EXPECT_EQ(true, callback.called_); |
+ EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); |
+ EXPECT_EQ(0, callback.extra_code_); |
EXPECT_TRUE(base::ContentsEqual( |
unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), |
test_file("binary_output.bin"))); |
@@ -108,16 +118,20 @@ TEST_F(ComponentPatcherOperationTest, CheckCopyOperation) { |
command_args->SetString("op", "copy"); |
command_args->SetString("input", "binary_output.bin"); |
- int error = 0; |
- scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpCopy()); |
- ComponentUnpacker::Error result = op->Run(command_args.get(), |
- input_dir_.path(), |
- unpack_dir_.path(), |
- patcher_.get(), |
- installer_.get(), |
- &error); |
- EXPECT_EQ(ComponentUnpacker::kNone, result); |
- EXPECT_EQ(0, error); |
+ TestCallback callback; |
+ scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCopy(); |
+ op->Run(command_args.get(), |
+ input_dir_.path(), |
+ unpack_dir_.path(), |
+ installer_.get(), |
+ true, |
+ base::Bind(&TestCallback::Set, base::Unretained(&callback)), |
+ task_runner_); |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ EXPECT_EQ(true, callback.called_); |
+ EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); |
+ EXPECT_EQ(0, callback.extra_code_); |
EXPECT_TRUE(base::ContentsEqual( |
unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), |
test_file("binary_output.bin"))); |
@@ -140,16 +154,20 @@ TEST_F(ComponentPatcherOperationTest, CheckCourgetteOperation) { |
command_args->SetString("input", "binary_input.bin"); |
command_args->SetString("patch", "binary_courgette_patch.bin"); |
- int error = 0; |
- scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpPatchCourgette()); |
- ComponentUnpacker::Error result = op->Run(command_args.get(), |
- input_dir_.path(), |
- unpack_dir_.path(), |
- patcher_.get(), |
- installer_.get(), |
- &error); |
- EXPECT_EQ(ComponentUnpacker::kNone, result); |
- EXPECT_EQ(0, error); |
+ TestCallback callback; |
+ scoped_refptr<DeltaUpdateOp> op = CreateDeltaUpdateOp("courgette"); |
+ op->Run(command_args.get(), |
+ input_dir_.path(), |
+ unpack_dir_.path(), |
+ installer_.get(), |
+ true, |
+ base::Bind(&TestCallback::Set, base::Unretained(&callback)), |
+ task_runner_); |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ EXPECT_EQ(true, callback.called_); |
+ EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); |
+ EXPECT_EQ(0, callback.extra_code_); |
EXPECT_TRUE(base::ContentsEqual( |
unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), |
test_file("binary_output.bin"))); |
@@ -171,16 +189,20 @@ TEST_F(ComponentPatcherOperationTest, CheckBsdiffOperation) { |
command_args->SetString("input", "binary_input.bin"); |
command_args->SetString("patch", "binary_bsdiff_patch.bin"); |
- int error = 0; |
- scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpPatchBsdiff()); |
- ComponentUnpacker::Error result = op->Run(command_args.get(), |
- input_dir_.path(), |
- unpack_dir_.path(), |
- patcher_.get(), |
- installer_.get(), |
- &error); |
- EXPECT_EQ(ComponentUnpacker::kNone, result); |
- EXPECT_EQ(0, error); |
+ TestCallback callback; |
+ scoped_refptr<DeltaUpdateOp> op = CreateDeltaUpdateOp("bsdiff"); |
+ op->Run(command_args.get(), |
+ input_dir_.path(), |
+ unpack_dir_.path(), |
+ installer_.get(), |
+ true, |
+ base::Bind(&TestCallback::Set, base::Unretained(&callback)), |
+ task_runner_); |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ EXPECT_EQ(true, callback.called_); |
+ EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); |
+ EXPECT_EQ(0, callback.extra_code_); |
EXPECT_TRUE(base::ContentsEqual( |
unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), |
test_file("binary_output.bin"))); |