Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: chrome/browser/component_updater/test/component_patcher_unittest.cc

Issue 25883006: Support asynchronous patching operations in the component updater. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tests
Patch Set: New LKGR, Windows fixes. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium 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 "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 18 matching lines...) Expand all
29 EXPECT_TRUE(unpack_dir_.CreateUniqueTempDir()); 29 EXPECT_TRUE(unpack_dir_.CreateUniqueTempDir());
30 EXPECT_TRUE(input_dir_.CreateUniqueTempDir()); 30 EXPECT_TRUE(input_dir_.CreateUniqueTempDir());
31 EXPECT_TRUE(installed_dir_.CreateUniqueTempDir()); 31 EXPECT_TRUE(installed_dir_.CreateUniqueTempDir());
32 patcher_.reset(new MockComponentPatcher()); 32 patcher_.reset(new MockComponentPatcher());
33 installer_.reset(new ReadOnlyTestInstaller(installed_dir_.path())); 33 installer_.reset(new ReadOnlyTestInstaller(installed_dir_.path()));
34 } 34 }
35 35
36 ComponentPatcherOperationTest::~ComponentPatcherOperationTest() { 36 ComponentPatcherOperationTest::~ComponentPatcherOperationTest() {
37 } 37 }
38 38
39 ComponentUnpacker::Error MockComponentPatcher::Patch( 39 component_updater::Error MockComponentPatcher::Patch(
40 PatchType patch_type, 40 PatchType patch_type,
41 const base::FilePath& input_file, 41 const base::FilePath& input_file,
42 const base::FilePath& patch_file, 42 const base::FilePath& patch_file,
43 const base::FilePath& output_file, 43 const base::FilePath& output_file,
44 int* error) { 44 int* error) {
45 *error = 0; 45 *error = 0;
46 int exit_code; 46 int exit_code;
47 if (patch_type == kPatchTypeCourgette) { 47 if (patch_type == kPatchTypeCourgette) {
48 exit_code = courgette::ApplyEnsemblePatch(input_file.value().c_str(), 48 exit_code = courgette::ApplyEnsemblePatch(input_file.value().c_str(),
49 patch_file.value().c_str(), 49 patch_file.value().c_str(),
50 output_file.value().c_str()); 50 output_file.value().c_str());
51 if (exit_code == courgette::C_OK) 51 if (exit_code == courgette::C_OK)
52 return ComponentUnpacker::kNone; 52 return component_updater::kNone;
53 *error = exit_code + kCourgetteErrorOffset; 53 *error = exit_code + kCourgetteErrorOffset;
54 } else if (patch_type == kPatchTypeBsdiff) { 54 } else if (patch_type == kPatchTypeBsdiff) {
55 exit_code = courgette::ApplyBinaryPatch(input_file, 55 exit_code = courgette::ApplyBinaryPatch(input_file,
56 patch_file, 56 patch_file,
57 output_file); 57 output_file);
58 if (exit_code == courgette::OK) 58 if (exit_code == courgette::OK)
59 return ComponentUnpacker::kNone; 59 return component_updater::kNone;
60 *error = exit_code + kBsdiffErrorOffset; 60 *error = exit_code + kBsdiffErrorOffset;
61 } 61 }
62 return ComponentUnpacker::kDeltaOperationFailure; 62 return component_updater::kDeltaOperationFailure;
63 } 63 }
64 64
65 // Verify that a 'create' delta update operation works correctly. 65 // Verify that a 'create' delta update operation works correctly.
66 TEST_F(ComponentPatcherOperationTest, CheckCreateOperation) { 66 TEST_F(ComponentPatcherOperationTest, CheckCreateOperation) {
67 EXPECT_TRUE(base::CopyFile( 67 EXPECT_TRUE(base::CopyFile(
68 test_file("binary_output.bin"), 68 test_file("binary_output.bin"),
69 input_dir_.path().Append(FILE_PATH_LITERAL("binary_output.bin")))); 69 input_dir_.path().Append(FILE_PATH_LITERAL("binary_output.bin"))));
70 70
71 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue()); 71 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue());
72 command_args->SetString("output", "output.bin"); 72 command_args->SetString("output", "output.bin");
73 command_args->SetString("sha256", binary_output_hash); 73 command_args->SetString("sha256", binary_output_hash);
74 command_args->SetString("op", "create"); 74 command_args->SetString("op", "create");
75 command_args->SetString("patch", "binary_output.bin"); 75 command_args->SetString("patch", "binary_output.bin");
76 76
77 int error = 0; 77 int error = 0;
78 scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpCreate()); 78 scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpCreate());
79 ComponentUnpacker::Error result = op->Run(command_args.get(), 79 component_updater::Error result = op->Run(command_args.get(),
80 input_dir_.path(), 80 input_dir_.path(),
81 unpack_dir_.path(), 81 unpack_dir_.path(),
82 patcher_.get(), 82 patcher_.get(),
83 NULL, 83 NULL,
84 &error); 84 &error);
85 85
86 EXPECT_EQ(ComponentUnpacker::kNone, result); 86 EXPECT_EQ(component_updater::kNone, result);
87 EXPECT_EQ(0, error); 87 EXPECT_EQ(0, error);
88 EXPECT_TRUE(base::ContentsEqual( 88 EXPECT_TRUE(base::ContentsEqual(
89 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 89 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")),
90 test_file("binary_output.bin"))); 90 test_file("binary_output.bin")));
91 } 91 }
92 92
93 // Verify that a 'copy' delta update operation works correctly. 93 // Verify that a 'copy' delta update operation works correctly.
94 TEST_F(ComponentPatcherOperationTest, CheckCopyOperation) { 94 TEST_F(ComponentPatcherOperationTest, CheckCopyOperation) {
95 EXPECT_TRUE(base::CopyFile( 95 EXPECT_TRUE(base::CopyFile(
96 test_file("binary_output.bin"), 96 test_file("binary_output.bin"),
97 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_output.bin")))); 97 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_output.bin"))));
98 98
99 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue()); 99 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue());
100 command_args->SetString("output", "output.bin"); 100 command_args->SetString("output", "output.bin");
101 command_args->SetString("sha256", binary_output_hash); 101 command_args->SetString("sha256", binary_output_hash);
102 command_args->SetString("op", "copy"); 102 command_args->SetString("op", "copy");
103 command_args->SetString("input", "binary_output.bin"); 103 command_args->SetString("input", "binary_output.bin");
104 104
105 int error = 0; 105 int error = 0;
106 scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpCopy()); 106 scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpCopy());
107 ComponentUnpacker::Error result = op->Run(command_args.get(), 107 component_updater::Error result = op->Run(command_args.get(),
108 input_dir_.path(), 108 input_dir_.path(),
109 unpack_dir_.path(), 109 unpack_dir_.path(),
110 patcher_.get(), 110 patcher_.get(),
111 installer_.get(), 111 installer_.get(),
112 &error); 112 &error);
113 EXPECT_EQ(ComponentUnpacker::kNone, result); 113 EXPECT_EQ(component_updater::kNone, result);
114 EXPECT_EQ(0, error); 114 EXPECT_EQ(0, error);
115 EXPECT_TRUE(base::ContentsEqual( 115 EXPECT_TRUE(base::ContentsEqual(
116 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 116 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")),
117 test_file("binary_output.bin"))); 117 test_file("binary_output.bin")));
118 } 118 }
119 119
120 // Verify that a 'courgette' delta update operation works correctly. 120 // Verify that a 'courgette' delta update operation works correctly.
121 TEST_F(ComponentPatcherOperationTest, CheckCourgetteOperation) { 121 TEST_F(ComponentPatcherOperationTest, CheckCourgetteOperation) {
122 EXPECT_TRUE(base::CopyFile( 122 EXPECT_TRUE(base::CopyFile(
123 test_file("binary_input.bin"), 123 test_file("binary_input.bin"),
124 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_input.bin")))); 124 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_input.bin"))));
125 EXPECT_TRUE(base::CopyFile( 125 EXPECT_TRUE(base::CopyFile(
126 test_file("binary_courgette_patch.bin"), 126 test_file("binary_courgette_patch.bin"),
127 input_dir_.path().Append( 127 input_dir_.path().Append(
128 FILE_PATH_LITERAL("binary_courgette_patch.bin")))); 128 FILE_PATH_LITERAL("binary_courgette_patch.bin"))));
129 129
130 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue()); 130 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue());
131 command_args->SetString("output", "output.bin"); 131 command_args->SetString("output", "output.bin");
132 command_args->SetString("sha256", binary_output_hash); 132 command_args->SetString("sha256", binary_output_hash);
133 command_args->SetString("op", "courgette"); 133 command_args->SetString("op", "courgette");
134 command_args->SetString("input", "binary_input.bin"); 134 command_args->SetString("input", "binary_input.bin");
135 command_args->SetString("patch", "binary_courgette_patch.bin"); 135 command_args->SetString("patch", "binary_courgette_patch.bin");
136 136
137 int error = 0; 137 int error = 0;
138 scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpPatchCourgette()); 138 scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpPatchCourgette());
139 ComponentUnpacker::Error result = op->Run(command_args.get(), 139 component_updater::Error result = op->Run(command_args.get(),
140 input_dir_.path(), 140 input_dir_.path(),
141 unpack_dir_.path(), 141 unpack_dir_.path(),
142 patcher_.get(), 142 patcher_.get(),
143 installer_.get(), 143 installer_.get(),
144 &error); 144 &error);
145 EXPECT_EQ(ComponentUnpacker::kNone, result); 145 EXPECT_EQ(component_updater::kNone, result);
146 EXPECT_EQ(0, error); 146 EXPECT_EQ(0, error);
147 EXPECT_TRUE(base::ContentsEqual( 147 EXPECT_TRUE(base::ContentsEqual(
148 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 148 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")),
149 test_file("binary_output.bin"))); 149 test_file("binary_output.bin")));
150 } 150 }
151 151
152 // Verify that a 'bsdiff' delta update operation works correctly. 152 // Verify that a 'bsdiff' delta update operation works correctly.
153 TEST_F(ComponentPatcherOperationTest, CheckBsdiffOperation) { 153 TEST_F(ComponentPatcherOperationTest, CheckBsdiffOperation) {
154 EXPECT_TRUE(base::CopyFile( 154 EXPECT_TRUE(base::CopyFile(
155 test_file("binary_input.bin"), 155 test_file("binary_input.bin"),
156 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_input.bin")))); 156 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_input.bin"))));
157 EXPECT_TRUE(base::CopyFile( 157 EXPECT_TRUE(base::CopyFile(
158 test_file("binary_bsdiff_patch.bin"), 158 test_file("binary_bsdiff_patch.bin"),
159 input_dir_.path().Append(FILE_PATH_LITERAL("binary_bsdiff_patch.bin")))); 159 input_dir_.path().Append(FILE_PATH_LITERAL("binary_bsdiff_patch.bin"))));
160 160
161 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue()); 161 scoped_ptr<base::DictionaryValue> command_args(new base::DictionaryValue());
162 command_args->SetString("output", "output.bin"); 162 command_args->SetString("output", "output.bin");
163 command_args->SetString("sha256", binary_output_hash); 163 command_args->SetString("sha256", binary_output_hash);
164 command_args->SetString("op", "courgette"); 164 command_args->SetString("op", "courgette");
165 command_args->SetString("input", "binary_input.bin"); 165 command_args->SetString("input", "binary_input.bin");
166 command_args->SetString("patch", "binary_bsdiff_patch.bin"); 166 command_args->SetString("patch", "binary_bsdiff_patch.bin");
167 167
168 int error = 0; 168 int error = 0;
169 scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpPatchBsdiff()); 169 scoped_ptr<DeltaUpdateOp> op(new DeltaUpdateOpPatchBsdiff());
170 ComponentUnpacker::Error result = op->Run(command_args.get(), 170 component_updater::Error result = op->Run(command_args.get(),
171 input_dir_.path(), 171 input_dir_.path(),
172 unpack_dir_.path(), 172 unpack_dir_.path(),
173 patcher_.get(), 173 patcher_.get(),
174 installer_.get(), 174 installer_.get(),
175 &error); 175 &error);
176 EXPECT_EQ(ComponentUnpacker::kNone, result); 176 EXPECT_EQ(component_updater::kNone, result);
177 EXPECT_EQ(0, error); 177 EXPECT_EQ(0, error);
178 EXPECT_TRUE(base::ContentsEqual( 178 EXPECT_TRUE(base::ContentsEqual(
179 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 179 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")),
180 test_file("binary_output.bin"))); 180 test_file("binary_output.bin")));
181 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698