Index: chrome/browser/component_updater/test/component_unpacker_unittest.cc |
diff --git a/chrome/browser/component_updater/test/component_unpacker_unittest.cc b/chrome/browser/component_updater/test/component_unpacker_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..62e6576810d50212fb4847c35dde19ea9566df21 |
--- /dev/null |
+++ b/chrome/browser/component_updater/test/component_unpacker_unittest.cc |
@@ -0,0 +1,192 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/component_updater/test/component_unpacker_unittest.h" |
+ |
+#include "base/compiler_specific.h" |
+#include "base/file_util.h" |
+#include "base/files/file_path.h" |
+#include "base/path_service.h" |
+#include "base/values.h" |
+#include "chrome/browser/component_updater/component_updater_service.h" |
+#include "chrome/common/chrome_paths.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+const char binary_output_hash[] = |
+ "599aba6d15a7da390621ef1bacb66601ed6aed04dadc1f9b445dcfe31296142a"; |
+ |
+base::FilePath test_file(const char* file); |
+ |
+class DummyInstaller : public ComponentInstaller { |
+ public: |
+ explicit DummyInstaller(const base::FilePath& installed_dir); |
+ |
+ virtual void OnUpdateError(int error) OVERRIDE; |
+ |
+ virtual bool Install(const base::DictionaryValue& manifest, |
+ const base::FilePath& unpack_path) OVERRIDE; |
+ |
+ virtual bool GetInstalledFile(const std::string& file, |
+ base::FilePath* installed_file) OVERRIDE; |
+ |
+ private: |
+ base::FilePath installed_dir_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DummyInstaller); |
+}; |
+ |
+class ComponentUnpackerOperationTest : public testing::Test { |
+ public: |
+ ComponentUnpackerOperationTest(); |
+ |
+ virtual ~ComponentUnpackerOperationTest(); |
+ |
+ protected: |
+ base::FilePath input_dir_; |
+ base::FilePath installed_dir_; |
+ base::FilePath unpack_dir_; |
+ scoped_ptr<DummyInstaller> installer_; |
+}; |
+ |
+base::FilePath test_file(const char* file) { |
+ base::FilePath path; |
+ PathService::Get(chrome::DIR_TEST_DATA, &path); |
+ return path.AppendASCII("components").AppendASCII(file); |
+} |
+ |
+ComponentUnpackerOperationTest::ComponentUnpackerOperationTest() { |
erikwright (departed)
2013/06/17 17:24:28
Consider whether a common test fixture base class
waffles
2013/06/17 22:17:49
Oops. Somehow this file escaped deletion. It's an
|
+ file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), &unpack_dir_); |
+ file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), &input_dir_); |
+ file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), |
+ &installed_dir_); |
+ installer_.reset(new DummyInstaller(installed_dir_)); |
+} |
+ |
+ComponentUnpackerOperationTest::~ComponentUnpackerOperationTest() { |
+ file_util::Delete(unpack_dir_, true); |
erikwright (departed)
2013/06/17 17:24:28
I think base/files/scoped_temp_dir.h would take ca
waffles
2013/06/17 22:17:49
Applied in component_patcher_unittest.cc.
|
+ file_util::Delete(input_dir_, true); |
+ file_util::Delete(installed_dir_, true); |
+} |
+ |
+DummyInstaller::DummyInstaller(const base::FilePath& installed_dir) |
+ : installed_dir_(installed_dir) { |
+} |
+ |
+void DummyInstaller::OnUpdateError(int error) {} |
+ |
+bool DummyInstaller::Install(const base::DictionaryValue& manifest, |
+ const base::FilePath& unpack_path) { |
+ return false; |
+} |
+ |
+bool DummyInstaller::GetInstalledFile(const std::string& file, |
+ base::FilePath* installed_file) { |
+ *installed_file = installed_dir_.AppendASCII(file); |
+ return true; |
+} |
+ |
+// Verify that a 'create' delta update operation works correctly. |
+TEST_F(ComponentUnpackerOperationTest, CheckCreateOperation) { |
+ file_util::CopyFile( |
+ test_file("binary_output.bin"), |
+ input_dir_.Append(FILE_PATH_LITERAL("binary_output.bin"))); |
+ |
+ scoped_ptr<base::ListValue> command_args(new base::ListValue()); |
+ command_args->AppendString("output.bin"); |
+ command_args->AppendString(binary_output_hash); |
+ command_args->AppendString("create"); |
+ command_args->AppendString("binary_output.bin"); |
+ |
+ scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpCreate()); |
+ DeltaUpdateResult result = op->Run(command_args.get(), |
+ input_dir_, |
+ unpack_dir_, |
+ NULL); |
+ |
+ EXPECT_EQ(DELTA_OK, result); |
+ EXPECT_TRUE(file_util::ContentsEqual( |
+ unpack_dir_.Append(FILE_PATH_LITERAL("output.bin")), |
+ test_file("binary_output.bin"))); |
+} |
+ |
+// Verify that a 'copy' delta update operation works correctly. |
+TEST_F(ComponentUnpackerOperationTest, CheckCopyOperation) { |
+ file_util::CopyFile( |
+ test_file("binary_output.bin"), |
+ installed_dir_.Append(FILE_PATH_LITERAL("binary_output.bin"))); |
+ |
+ scoped_ptr<base::ListValue> command_args(new base::ListValue()); |
+ command_args->AppendString("output.bin"); |
+ command_args->AppendString(binary_output_hash); |
+ command_args->AppendString("copy"); |
+ command_args->AppendString("binary_output.bin"); |
+ |
+ scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpCopy()); |
+ DeltaUpdateResult result = op->Run(command_args.get(), |
+ input_dir_, |
+ unpack_dir_, |
+ installer_.get()); |
+ |
+ EXPECT_EQ(DELTA_OK, result); |
+ EXPECT_TRUE(file_util::ContentsEqual( |
+ unpack_dir_.Append(FILE_PATH_LITERAL("output.bin")), |
+ test_file("binary_output.bin"))); |
+} |
+ |
+// Verify that a 'courgette' delta update operation works correctly. |
+TEST_F(ComponentUnpackerOperationTest, CheckCourgetteOperation) { |
+ file_util::CopyFile( |
+ test_file("binary_input.bin"), |
+ installed_dir_.Append(FILE_PATH_LITERAL("binary_input.bin"))); |
+ file_util::CopyFile( |
+ test_file("binary_courgette_patch.bin"), |
+ input_dir_.Append(FILE_PATH_LITERAL("binary_courgette_patch.bin"))); |
+ |
+ scoped_ptr<base::ListValue> command_args(new base::ListValue()); |
+ command_args->AppendString("output.bin"); |
+ command_args->AppendString(binary_output_hash); |
+ command_args->AppendString("courgette"); |
+ command_args->AppendString("binary_input.bin"); |
+ command_args->AppendString("binary_courgette_patch.bin"); |
+ |
+ scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpPatchCourgette()); |
+ DeltaUpdateResult result = op->Run(command_args.get(), |
+ input_dir_, |
+ unpack_dir_, |
+ installer_.get()); |
+ |
+ EXPECT_EQ(DELTA_OK, result); |
+ EXPECT_TRUE(file_util::ContentsEqual( |
+ unpack_dir_.Append(FILE_PATH_LITERAL("output.bin")), |
+ test_file("binary_output.bin"))); |
+} |
+ |
+// Verify that a 'bsdiff' delta update operation works correctly. |
+TEST_F(ComponentUnpackerOperationTest, CheckBsdiffOperation) { |
+ file_util::CopyFile( |
+ test_file("binary_input.bin"), |
+ installed_dir_.Append(FILE_PATH_LITERAL("binary_input.bin"))); |
+ file_util::CopyFile( |
+ test_file("binary_bsdiff_patch.bin"), |
+ input_dir_.Append(FILE_PATH_LITERAL("binary_bsdiff_patch.bin"))); |
+ |
+ scoped_ptr<base::ListValue> command_args(new base::ListValue()); |
+ command_args->AppendString("output.bin"); |
+ command_args->AppendString(binary_output_hash); |
+ command_args->AppendString("courgette"); |
+ command_args->AppendString("binary_input.bin"); |
+ command_args->AppendString("binary_bsdiff_patch.bin"); |
+ |
+ scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpPatchBsdiff()); |
+ DeltaUpdateResult result = op->Run(command_args.get(), |
+ input_dir_, |
+ unpack_dir_, |
+ installer_.get()); |
+ |
+ EXPECT_EQ(DELTA_OK, result); |
+ EXPECT_TRUE(file_util::ContentsEqual( |
+ unpack_dir_.Append(FILE_PATH_LITERAL("output.bin")), |
+ test_file("binary_output.bin"))); |
+} |
+ |