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

Side by Side Diff: components/update_client/component_patcher_unittest.cc

Issue 2321453002: c/browser, c/common, components S-W: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Just rebased Created 4 years, 3 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/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 .AppendASCII("update_client") 61 .AppendASCII("update_client")
62 .AppendASCII(file); 62 .AppendASCII(file);
63 } 63 }
64 64
65 } // namespace 65 } // namespace
66 66
67 ComponentPatcherOperationTest::ComponentPatcherOperationTest() { 67 ComponentPatcherOperationTest::ComponentPatcherOperationTest() {
68 EXPECT_TRUE(unpack_dir_.CreateUniqueTempDir()); 68 EXPECT_TRUE(unpack_dir_.CreateUniqueTempDir());
69 EXPECT_TRUE(input_dir_.CreateUniqueTempDir()); 69 EXPECT_TRUE(input_dir_.CreateUniqueTempDir());
70 EXPECT_TRUE(installed_dir_.CreateUniqueTempDir()); 70 EXPECT_TRUE(installed_dir_.CreateUniqueTempDir());
71 installer_ = new ReadOnlyTestInstaller(installed_dir_.path()); 71 installer_ = new ReadOnlyTestInstaller(installed_dir_.GetPath());
72 task_runner_ = base::MessageLoop::current()->task_runner(); 72 task_runner_ = base::MessageLoop::current()->task_runner();
73 } 73 }
74 74
75 ComponentPatcherOperationTest::~ComponentPatcherOperationTest() { 75 ComponentPatcherOperationTest::~ComponentPatcherOperationTest() {
76 } 76 }
77 77
78 // Verify that a 'create' delta update operation works correctly. 78 // Verify that a 'create' delta update operation works correctly.
79 TEST_F(ComponentPatcherOperationTest, CheckCreateOperation) { 79 TEST_F(ComponentPatcherOperationTest, CheckCreateOperation) {
80 EXPECT_TRUE(base::CopyFile( 80 EXPECT_TRUE(base::CopyFile(
81 test_file("binary_output.bin"), 81 test_file("binary_output.bin"),
82 input_dir_.path().Append(FILE_PATH_LITERAL("binary_output.bin")))); 82 input_dir_.GetPath().Append(FILE_PATH_LITERAL("binary_output.bin"))));
83 83
84 std::unique_ptr<base::DictionaryValue> command_args( 84 std::unique_ptr<base::DictionaryValue> command_args(
85 new base::DictionaryValue()); 85 new base::DictionaryValue());
86 command_args->SetString("output", "output.bin"); 86 command_args->SetString("output", "output.bin");
87 command_args->SetString("sha256", binary_output_hash); 87 command_args->SetString("sha256", binary_output_hash);
88 command_args->SetString("op", "create"); 88 command_args->SetString("op", "create");
89 command_args->SetString("patch", "binary_output.bin"); 89 command_args->SetString("patch", "binary_output.bin");
90 90
91 TestCallback callback; 91 TestCallback callback;
92 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCreate(); 92 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCreate();
93 op->Run(command_args.get(), input_dir_.path(), unpack_dir_.path(), NULL, 93 op->Run(command_args.get(), input_dir_.GetPath(), unpack_dir_.GetPath(), NULL,
94 base::Bind(&TestCallback::Set, base::Unretained(&callback)), 94 base::Bind(&TestCallback::Set, base::Unretained(&callback)),
95 task_runner_); 95 task_runner_);
96 base::RunLoop().RunUntilIdle(); 96 base::RunLoop().RunUntilIdle();
97 97
98 EXPECT_EQ(true, callback.called_); 98 EXPECT_EQ(true, callback.called_);
99 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); 99 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_);
100 EXPECT_EQ(0, callback.extra_code_); 100 EXPECT_EQ(0, callback.extra_code_);
101 EXPECT_TRUE(base::ContentsEqual( 101 EXPECT_TRUE(base::ContentsEqual(
102 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 102 unpack_dir_.GetPath().Append(FILE_PATH_LITERAL("output.bin")),
103 test_file("binary_output.bin"))); 103 test_file("binary_output.bin")));
104 } 104 }
105 105
106 // Verify that a 'copy' delta update operation works correctly. 106 // Verify that a 'copy' delta update operation works correctly.
107 TEST_F(ComponentPatcherOperationTest, CheckCopyOperation) { 107 TEST_F(ComponentPatcherOperationTest, CheckCopyOperation) {
108 EXPECT_TRUE(base::CopyFile( 108 EXPECT_TRUE(base::CopyFile(
109 test_file("binary_output.bin"), 109 test_file("binary_output.bin"),
110 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_output.bin")))); 110 installed_dir_.GetPath().Append(FILE_PATH_LITERAL("binary_output.bin"))));
111 111
112 std::unique_ptr<base::DictionaryValue> command_args( 112 std::unique_ptr<base::DictionaryValue> command_args(
113 new base::DictionaryValue()); 113 new base::DictionaryValue());
114 command_args->SetString("output", "output.bin"); 114 command_args->SetString("output", "output.bin");
115 command_args->SetString("sha256", binary_output_hash); 115 command_args->SetString("sha256", binary_output_hash);
116 command_args->SetString("op", "copy"); 116 command_args->SetString("op", "copy");
117 command_args->SetString("input", "binary_output.bin"); 117 command_args->SetString("input", "binary_output.bin");
118 118
119 TestCallback callback; 119 TestCallback callback;
120 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCopy(); 120 scoped_refptr<DeltaUpdateOp> op = new DeltaUpdateOpCopy();
121 op->Run(command_args.get(), input_dir_.path(), unpack_dir_.path(), 121 op->Run(command_args.get(), input_dir_.GetPath(), unpack_dir_.GetPath(),
122 installer_.get(), 122 installer_.get(),
123 base::Bind(&TestCallback::Set, base::Unretained(&callback)), 123 base::Bind(&TestCallback::Set, base::Unretained(&callback)),
124 task_runner_); 124 task_runner_);
125 base::RunLoop().RunUntilIdle(); 125 base::RunLoop().RunUntilIdle();
126 126
127 EXPECT_EQ(true, callback.called_); 127 EXPECT_EQ(true, callback.called_);
128 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); 128 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_);
129 EXPECT_EQ(0, callback.extra_code_); 129 EXPECT_EQ(0, callback.extra_code_);
130 EXPECT_TRUE(base::ContentsEqual( 130 EXPECT_TRUE(base::ContentsEqual(
131 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 131 unpack_dir_.GetPath().Append(FILE_PATH_LITERAL("output.bin")),
132 test_file("binary_output.bin"))); 132 test_file("binary_output.bin")));
133 } 133 }
134 134
135 // Verify that a 'courgette' delta update operation works correctly. 135 // Verify that a 'courgette' delta update operation works correctly.
136 TEST_F(ComponentPatcherOperationTest, CheckCourgetteOperation) { 136 TEST_F(ComponentPatcherOperationTest, CheckCourgetteOperation) {
137 EXPECT_TRUE(base::CopyFile( 137 EXPECT_TRUE(base::CopyFile(
138 test_file("binary_input.bin"), 138 test_file("binary_input.bin"),
139 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_input.bin")))); 139 installed_dir_.GetPath().Append(FILE_PATH_LITERAL("binary_input.bin"))));
140 EXPECT_TRUE(base::CopyFile(test_file("binary_courgette_patch.bin"), 140 EXPECT_TRUE(base::CopyFile(test_file("binary_courgette_patch.bin"),
141 input_dir_.path().Append(FILE_PATH_LITERAL( 141 input_dir_.GetPath().Append(FILE_PATH_LITERAL(
142 "binary_courgette_patch.bin")))); 142 "binary_courgette_patch.bin"))));
143 143
144 std::unique_ptr<base::DictionaryValue> command_args( 144 std::unique_ptr<base::DictionaryValue> command_args(
145 new base::DictionaryValue()); 145 new base::DictionaryValue());
146 command_args->SetString("output", "output.bin"); 146 command_args->SetString("output", "output.bin");
147 command_args->SetString("sha256", binary_output_hash); 147 command_args->SetString("sha256", binary_output_hash);
148 command_args->SetString("op", "courgette"); 148 command_args->SetString("op", "courgette");
149 command_args->SetString("input", "binary_input.bin"); 149 command_args->SetString("input", "binary_input.bin");
150 command_args->SetString("patch", "binary_courgette_patch.bin"); 150 command_args->SetString("patch", "binary_courgette_patch.bin");
151 151
152 TestCallback callback; 152 TestCallback callback;
153 scoped_refptr<DeltaUpdateOp> op = 153 scoped_refptr<DeltaUpdateOp> op =
154 CreateDeltaUpdateOp("courgette", NULL /* out_of_process_patcher */); 154 CreateDeltaUpdateOp("courgette", NULL /* out_of_process_patcher */);
155 op->Run(command_args.get(), input_dir_.path(), unpack_dir_.path(), 155 op->Run(command_args.get(), input_dir_.GetPath(), unpack_dir_.GetPath(),
156 installer_.get(), 156 installer_.get(),
157 base::Bind(&TestCallback::Set, base::Unretained(&callback)), 157 base::Bind(&TestCallback::Set, base::Unretained(&callback)),
158 task_runner_); 158 task_runner_);
159 base::RunLoop().RunUntilIdle(); 159 base::RunLoop().RunUntilIdle();
160 160
161 EXPECT_EQ(true, callback.called_); 161 EXPECT_EQ(true, callback.called_);
162 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); 162 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_);
163 EXPECT_EQ(0, callback.extra_code_); 163 EXPECT_EQ(0, callback.extra_code_);
164 EXPECT_TRUE(base::ContentsEqual( 164 EXPECT_TRUE(base::ContentsEqual(
165 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 165 unpack_dir_.GetPath().Append(FILE_PATH_LITERAL("output.bin")),
166 test_file("binary_output.bin"))); 166 test_file("binary_output.bin")));
167 } 167 }
168 168
169 // Verify that a 'bsdiff' delta update operation works correctly. 169 // Verify that a 'bsdiff' delta update operation works correctly.
170 TEST_F(ComponentPatcherOperationTest, CheckBsdiffOperation) { 170 TEST_F(ComponentPatcherOperationTest, CheckBsdiffOperation) {
171 EXPECT_TRUE(base::CopyFile( 171 EXPECT_TRUE(base::CopyFile(
172 test_file("binary_input.bin"), 172 test_file("binary_input.bin"),
173 installed_dir_.path().Append(FILE_PATH_LITERAL("binary_input.bin")))); 173 installed_dir_.GetPath().Append(FILE_PATH_LITERAL("binary_input.bin"))));
174 EXPECT_TRUE(base::CopyFile( 174 EXPECT_TRUE(base::CopyFile(test_file("binary_bsdiff_patch.bin"),
175 test_file("binary_bsdiff_patch.bin"), 175 input_dir_.GetPath().Append(FILE_PATH_LITERAL(
176 input_dir_.path().Append(FILE_PATH_LITERAL("binary_bsdiff_patch.bin")))); 176 "binary_bsdiff_patch.bin"))));
177 177
178 std::unique_ptr<base::DictionaryValue> command_args( 178 std::unique_ptr<base::DictionaryValue> command_args(
179 new base::DictionaryValue()); 179 new base::DictionaryValue());
180 command_args->SetString("output", "output.bin"); 180 command_args->SetString("output", "output.bin");
181 command_args->SetString("sha256", binary_output_hash); 181 command_args->SetString("sha256", binary_output_hash);
182 command_args->SetString("op", "courgette"); 182 command_args->SetString("op", "courgette");
183 command_args->SetString("input", "binary_input.bin"); 183 command_args->SetString("input", "binary_input.bin");
184 command_args->SetString("patch", "binary_bsdiff_patch.bin"); 184 command_args->SetString("patch", "binary_bsdiff_patch.bin");
185 185
186 TestCallback callback; 186 TestCallback callback;
187 scoped_refptr<DeltaUpdateOp> op = 187 scoped_refptr<DeltaUpdateOp> op =
188 CreateDeltaUpdateOp("bsdiff", NULL /* out_of_process_patcher */); 188 CreateDeltaUpdateOp("bsdiff", NULL /* out_of_process_patcher */);
189 op->Run(command_args.get(), input_dir_.path(), unpack_dir_.path(), 189 op->Run(command_args.get(), input_dir_.GetPath(), unpack_dir_.GetPath(),
190 installer_.get(), 190 installer_.get(),
191 base::Bind(&TestCallback::Set, base::Unretained(&callback)), 191 base::Bind(&TestCallback::Set, base::Unretained(&callback)),
192 task_runner_); 192 task_runner_);
193 base::RunLoop().RunUntilIdle(); 193 base::RunLoop().RunUntilIdle();
194 194
195 EXPECT_EQ(true, callback.called_); 195 EXPECT_EQ(true, callback.called_);
196 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_); 196 EXPECT_EQ(ComponentUnpacker::kNone, callback.error_);
197 EXPECT_EQ(0, callback.extra_code_); 197 EXPECT_EQ(0, callback.extra_code_);
198 EXPECT_TRUE(base::ContentsEqual( 198 EXPECT_TRUE(base::ContentsEqual(
199 unpack_dir_.path().Append(FILE_PATH_LITERAL("output.bin")), 199 unpack_dir_.GetPath().Append(FILE_PATH_LITERAL("output.bin")),
200 test_file("binary_output.bin"))); 200 test_file("binary_output.bin")));
201 } 201 }
202 202
203 } // namespace update_client 203 } // namespace update_client
OLDNEW
« no previous file with comments | « components/tracing/browser/trace_config_file_unittest.cc ('k') | components/upload_list/upload_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698