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

Side by Side Diff: third_party/zlib/google/zip_reader_unittest.cc

Issue 92873003: Adds asynchronous unzip functions to ZipReader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 7 years 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "third_party/zlib/google/zip_reader.h" 5 #include "third_party/zlib/google/zip_reader.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/md5.h" 13 #include "base/md5.h"
14 #include "base/message_loop/message_loop.h"
14 #include "base/path_service.h" 15 #include "base/path_service.h"
15 #include "base/platform_file.h" 16 #include "base/platform_file.h"
17 #include "base/run_loop.h"
16 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
17 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "testing/gmock/include/gmock/gmock.h"
satorux1 2013/12/05 04:39:37 gmock should usually be avoided in Chrome code.
Drew Haven 2013/12/09 23:33:12 I personally like gmock for mocking out interfaces
18 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/platform_test.h" 22 #include "testing/platform_test.h"
20 #include "third_party/zlib/google/zip_internal.h" 23 #include "third_party/zlib/google/zip_internal.h"
21 24
22 namespace { 25 namespace {
23 26
27 using testing::_;
28 using testing::AtLeast;
29
30 const static std::string kQuuxExpectedMD5 = "d1ae4ac8a17a0e09317113ab284b57a6";
31
24 // Wrap PlatformFiles in a class so that we don't leak them in tests. 32 // Wrap PlatformFiles in a class so that we don't leak them in tests.
25 class PlatformFileWrapper { 33 class PlatformFileWrapper {
26 public: 34 public:
27 typedef enum { 35 typedef enum {
28 READ_ONLY, 36 READ_ONLY,
29 READ_WRITE 37 READ_WRITE
30 } AccessMode; 38 } AccessMode;
31 39
32 PlatformFileWrapper(const base::FilePath& file, AccessMode mode) 40 PlatformFileWrapper(const base::FilePath& file, AccessMode mode)
33 : file_(base::kInvalidPlatformFileValue) { 41 : file_(base::kInvalidPlatformFileValue) {
(...skipping 20 matching lines...) Expand all
54 ~PlatformFileWrapper() { 62 ~PlatformFileWrapper() {
55 base::ClosePlatformFile(file_); 63 base::ClosePlatformFile(file_);
56 } 64 }
57 65
58 base::PlatformFile platform_file() { return file_; } 66 base::PlatformFile platform_file() { return file_; }
59 67
60 private: 68 private:
61 base::PlatformFile file_; 69 base::PlatformFile file_;
62 }; 70 };
63 71
72 class MockListener : public zip::ZipReader::Listener {
73 public:
74 MockListener() {}
75 MOCK_METHOD1(OnUnzipProgress, void(int progress));
76 MOCK_METHOD0(OnUnzipSuccess, void());
77 MOCK_METHOD0(OnUnzipFailed, void());
78
79 void ExpectSuccess() {
80 EXPECT_CALL(*this, OnUnzipSuccess());
81 EXPECT_CALL(*this, OnUnzipFailed()).Times(0);
82 EXPECT_CALL(*this, OnUnzipProgress(_)).Times(AtLeast(0));
83 }
84
85 void ExpectSuccessWithProgress() {
86 EXPECT_CALL(*this, OnUnzipSuccess());
87 EXPECT_CALL(*this, OnUnzipFailed()).Times(0);
88 EXPECT_CALL(*this, OnUnzipProgress(_)).Times(AtLeast(1));
satorux1 2013/12/05 04:39:37 Instead of checking with GMock, can you do somethi
Drew Haven 2013/12/09 23:33:12 I was originally reporting the percentage because
89 }
90 protected:
91 virtual ~MockListener() { }
92 };
93
64 } // namespace 94 } // namespace
65 95
66 namespace zip { 96 namespace zip {
67 97
68 // Make the test a PlatformTest to setup autorelease pools properly on Mac. 98 // Make the test a PlatformTest to setup autorelease pools properly on Mac.
69 class ZipReaderTest : public PlatformTest { 99 class ZipReaderTest : public PlatformTest {
70 protected: 100 protected:
71 virtual void SetUp() { 101 virtual void SetUp() {
72 PlatformTest::SetUp(); 102 PlatformTest::SetUp();
73 103
(...skipping 13 matching lines...) Expand all
87 test_zip_contents_.insert(base::FilePath(FILE_PATH_LITERAL("foo/bar/"))); 117 test_zip_contents_.insert(base::FilePath(FILE_PATH_LITERAL("foo/bar/")));
88 test_zip_contents_.insert( 118 test_zip_contents_.insert(
89 base::FilePath(FILE_PATH_LITERAL("foo/bar/baz.txt"))); 119 base::FilePath(FILE_PATH_LITERAL("foo/bar/baz.txt")));
90 test_zip_contents_.insert( 120 test_zip_contents_.insert(
91 base::FilePath(FILE_PATH_LITERAL("foo/bar/quux.txt"))); 121 base::FilePath(FILE_PATH_LITERAL("foo/bar/quux.txt")));
92 test_zip_contents_.insert( 122 test_zip_contents_.insert(
93 base::FilePath(FILE_PATH_LITERAL("foo/bar.txt"))); 123 base::FilePath(FILE_PATH_LITERAL("foo/bar.txt")));
94 test_zip_contents_.insert(base::FilePath(FILE_PATH_LITERAL("foo.txt"))); 124 test_zip_contents_.insert(base::FilePath(FILE_PATH_LITERAL("foo.txt")));
95 test_zip_contents_.insert( 125 test_zip_contents_.insert(
96 base::FilePath(FILE_PATH_LITERAL("foo/bar/.hidden"))); 126 base::FilePath(FILE_PATH_LITERAL("foo/bar/.hidden")));
127
128 mock_listener_ = new MockListener;
129 message_loop_proxy_ = base::MessageLoop::current()->message_loop_proxy();
97 } 130 }
98 131
99 virtual void TearDown() { 132 virtual void TearDown() {
100 PlatformTest::TearDown(); 133 PlatformTest::TearDown();
101 } 134 }
102 135
103 bool GetTestDataDirectory(base::FilePath* path) { 136 bool GetTestDataDirectory(base::FilePath* path) {
104 bool success = PathService::Get(base::DIR_SOURCE_ROOT, path); 137 bool success = PathService::Get(base::DIR_SOURCE_ROOT, path);
105 EXPECT_TRUE(success); 138 EXPECT_TRUE(success);
106 if (!success) 139 if (!success)
107 return false; 140 return false;
108 *path = path->AppendASCII("third_party"); 141 *path = path->AppendASCII("third_party");
109 *path = path->AppendASCII("zlib"); 142 *path = path->AppendASCII("zlib");
110 *path = path->AppendASCII("google"); 143 *path = path->AppendASCII("google");
111 *path = path->AppendASCII("test"); 144 *path = path->AppendASCII("test");
112 *path = path->AppendASCII("data"); 145 *path = path->AppendASCII("data");
113 return true; 146 return true;
114 } 147 }
115 148
149 void CompareFileAndMD5(const base::FilePath& path,
150 const std::string expected_md5) {
151 // Read the output file and compute the MD5.
152 std::string output;
153 ASSERT_TRUE(base::ReadFileToString(path, &output));
154 const std::string md5 = base::MD5String(output);
155 EXPECT_EQ(expected_md5, md5);
156 }
157
116 // The path to temporary directory used to contain the test operations. 158 // The path to temporary directory used to contain the test operations.
117 base::FilePath test_dir_; 159 base::FilePath test_dir_;
118 // The path to the test data directory where test.zip etc. are located. 160 // The path to the test data directory where test.zip etc. are located.
119 base::FilePath test_data_dir_; 161 base::FilePath test_data_dir_;
120 // The path to test.zip in the test data directory. 162 // The path to test.zip in the test data directory.
121 base::FilePath test_zip_file_; 163 base::FilePath test_zip_file_;
122 // The path to evil.zip in the test data directory. 164 // The path to evil.zip in the test data directory.
123 base::FilePath evil_zip_file_; 165 base::FilePath evil_zip_file_;
124 // The path to evil_via_invalid_utf8.zip in the test data directory. 166 // The path to evil_via_invalid_utf8.zip in the test data directory.
125 base::FilePath evil_via_invalid_utf8_zip_file_; 167 base::FilePath evil_via_invalid_utf8_zip_file_;
126 // The path to evil_via_absolute_file_name.zip in the test data directory. 168 // The path to evil_via_absolute_file_name.zip in the test data directory.
127 base::FilePath evil_via_absolute_file_name_zip_file_; 169 base::FilePath evil_via_absolute_file_name_zip_file_;
128 std::set<base::FilePath> test_zip_contents_; 170 std::set<base::FilePath> test_zip_contents_;
129 171
130 base::ScopedTempDir temp_dir_; 172 base::ScopedTempDir temp_dir_;
173
174 scoped_refptr<MockListener> mock_listener_;
175 base::MessageLoop message_loop_;
176 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
131 }; 177 };
132 178
133 TEST_F(ZipReaderTest, Open_ValidZipFile) { 179 TEST_F(ZipReaderTest, Open_ValidZipFile) {
134 ZipReader reader; 180 ZipReader reader;
135 ASSERT_TRUE(reader.Open(test_zip_file_)); 181 ASSERT_TRUE(reader.Open(test_zip_file_));
136 } 182 }
137 183
138 TEST_F(ZipReaderTest, Open_ValidZipPlatformFile) { 184 TEST_F(ZipReaderTest, Open_ValidZipPlatformFile) {
139 ZipReader reader; 185 ZipReader reader;
140 PlatformFileWrapper zip_fd_wrapper(test_zip_file_, 186 PlatformFileWrapper zip_fd_wrapper(test_zip_file_,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 ASSERT_TRUE(reader.Open(test_zip_file_)); 259 ASSERT_TRUE(reader.Open(test_zip_file_));
214 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt")); 260 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
215 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path)); 261 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
216 ASSERT_TRUE(reader.ExtractCurrentEntryToFilePath( 262 ASSERT_TRUE(reader.ExtractCurrentEntryToFilePath(
217 test_dir_.AppendASCII("quux.txt"))); 263 test_dir_.AppendASCII("quux.txt")));
218 // Read the output file ans compute the MD5. 264 // Read the output file ans compute the MD5.
219 std::string output; 265 std::string output;
220 ASSERT_TRUE(base::ReadFileToString(test_dir_.AppendASCII("quux.txt"), 266 ASSERT_TRUE(base::ReadFileToString(test_dir_.AppendASCII("quux.txt"),
221 &output)); 267 &output));
222 const std::string md5 = base::MD5String(output); 268 const std::string md5 = base::MD5String(output);
223 const std::string kExpectedMD5 = "d1ae4ac8a17a0e09317113ab284b57a6"; 269 EXPECT_EQ(kQuuxExpectedMD5, md5);
224 EXPECT_EQ(kExpectedMD5, md5);
225 // quux.txt should be larger than kZipBufSize so that we can exercise 270 // quux.txt should be larger than kZipBufSize so that we can exercise
226 // the loop in ExtractCurrentEntry(). 271 // the loop in ExtractCurrentEntry().
227 EXPECT_LT(static_cast<size_t>(internal::kZipBufSize), output.size()); 272 EXPECT_LT(static_cast<size_t>(internal::kZipBufSize), output.size());
228 } 273 }
229 274
230 TEST_F(ZipReaderTest, PlatformFileExtractCurrentEntryToFilePath_RegularFile) { 275 TEST_F(ZipReaderTest, PlatformFileExtractCurrentEntryToFilePath_RegularFile) {
231 ZipReader reader; 276 ZipReader reader;
232 PlatformFileWrapper zip_fd_wrapper(test_zip_file_, 277 PlatformFileWrapper zip_fd_wrapper(test_zip_file_,
233 PlatformFileWrapper::READ_ONLY); 278 PlatformFileWrapper::READ_ONLY);
234 ASSERT_TRUE(reader.OpenFromPlatformFile(zip_fd_wrapper.platform_file())); 279 ASSERT_TRUE(reader.OpenFromPlatformFile(zip_fd_wrapper.platform_file()));
235 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt")); 280 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
236 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path)); 281 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
237 ASSERT_TRUE(reader.ExtractCurrentEntryToFilePath( 282 ASSERT_TRUE(reader.ExtractCurrentEntryToFilePath(
238 test_dir_.AppendASCII("quux.txt"))); 283 test_dir_.AppendASCII("quux.txt")));
239 // Read the output file and compute the MD5. 284 // Read the output file and compute the MD5.
240 std::string output; 285 std::string output;
241 ASSERT_TRUE(base::ReadFileToString(test_dir_.AppendASCII("quux.txt"), 286 ASSERT_TRUE(base::ReadFileToString(test_dir_.AppendASCII("quux.txt"),
242 &output)); 287 &output));
243 const std::string md5 = base::MD5String(output); 288 const std::string md5 = base::MD5String(output);
244 const std::string kExpectedMD5 = "d1ae4ac8a17a0e09317113ab284b57a6"; 289 EXPECT_EQ(kQuuxExpectedMD5, md5);
245 EXPECT_EQ(kExpectedMD5, md5);
246 // quux.txt should be larger than kZipBufSize so that we can exercise 290 // quux.txt should be larger than kZipBufSize so that we can exercise
247 // the loop in ExtractCurrentEntry(). 291 // the loop in ExtractCurrentEntry().
248 EXPECT_LT(static_cast<size_t>(internal::kZipBufSize), output.size()); 292 EXPECT_LT(static_cast<size_t>(internal::kZipBufSize), output.size());
249 } 293 }
250 294
251 #if defined(OS_POSIX) 295 #if defined(OS_POSIX)
252 TEST_F(ZipReaderTest, PlatformFileExtractCurrentEntryToFd_RegularFile) { 296 TEST_F(ZipReaderTest, PlatformFileExtractCurrentEntryToFd_RegularFile) {
253 ZipReader reader; 297 ZipReader reader;
254 PlatformFileWrapper zip_fd_wrapper(test_zip_file_, 298 PlatformFileWrapper zip_fd_wrapper(test_zip_file_,
255 PlatformFileWrapper::READ_ONLY); 299 PlatformFileWrapper::READ_ONLY);
256 ASSERT_TRUE(reader.OpenFromPlatformFile(zip_fd_wrapper.platform_file())); 300 ASSERT_TRUE(reader.OpenFromPlatformFile(zip_fd_wrapper.platform_file()));
257 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt")); 301 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
258 base::FilePath out_path = test_dir_.AppendASCII("quux.txt"); 302 base::FilePath out_path = test_dir_.AppendASCII("quux.txt");
259 PlatformFileWrapper out_fd_w(out_path, PlatformFileWrapper::READ_WRITE); 303 PlatformFileWrapper out_fd_w(out_path, PlatformFileWrapper::READ_WRITE);
260 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path)); 304 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
261 ASSERT_TRUE(reader.ExtractCurrentEntryToFd(out_fd_w.platform_file())); 305 ASSERT_TRUE(reader.ExtractCurrentEntryToFd(out_fd_w.platform_file()));
262 // Read the output file and compute the MD5. 306 // Read the output file and compute the MD5.
263 std::string output; 307 std::string output;
264 ASSERT_TRUE(base::ReadFileToString(test_dir_.AppendASCII("quux.txt"), 308 ASSERT_TRUE(base::ReadFileToString(test_dir_.AppendASCII("quux.txt"),
265 &output)); 309 &output));
266 const std::string md5 = base::MD5String(output); 310 const std::string md5 = base::MD5String(output);
267 const std::string kExpectedMD5 = "d1ae4ac8a17a0e09317113ab284b57a6"; 311 EXPECT_EQ(kQuuxExpectedMD5, md5);
268 EXPECT_EQ(kExpectedMD5, md5);
269 // quux.txt should be larger than kZipBufSize so that we can exercise 312 // quux.txt should be larger than kZipBufSize so that we can exercise
270 // the loop in ExtractCurrentEntry(). 313 // the loop in ExtractCurrentEntry().
271 EXPECT_LT(static_cast<size_t>(internal::kZipBufSize), output.size()); 314 EXPECT_LT(static_cast<size_t>(internal::kZipBufSize), output.size());
272 } 315 }
273 #endif 316 #endif
274 317
275 TEST_F(ZipReaderTest, ExtractCurrentEntryToFilePath_Directory) { 318 TEST_F(ZipReaderTest, ExtractCurrentEntryToFilePath_Directory) {
276 ZipReader reader; 319 ZipReader reader;
277 ASSERT_TRUE(reader.Open(test_zip_file_)); 320 ASSERT_TRUE(reader.Open(test_zip_file_));
278 base::FilePath target_path(FILE_PATH_LITERAL("foo/")); 321 base::FilePath target_path(FILE_PATH_LITERAL("foo/"));
(...skipping 10 matching lines...) Expand all
289 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt")); 332 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
290 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path)); 333 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
291 ASSERT_TRUE(reader.ExtractCurrentEntryIntoDirectory(test_dir_)); 334 ASSERT_TRUE(reader.ExtractCurrentEntryIntoDirectory(test_dir_));
292 // Sub directories should be created. 335 // Sub directories should be created.
293 ASSERT_TRUE(base::DirectoryExists(test_dir_.AppendASCII("foo/bar"))); 336 ASSERT_TRUE(base::DirectoryExists(test_dir_.AppendASCII("foo/bar")));
294 // And the file should be created. 337 // And the file should be created.
295 std::string output; 338 std::string output;
296 ASSERT_TRUE(base::ReadFileToString( 339 ASSERT_TRUE(base::ReadFileToString(
297 test_dir_.AppendASCII("foo/bar/quux.txt"), &output)); 340 test_dir_.AppendASCII("foo/bar/quux.txt"), &output));
298 const std::string md5 = base::MD5String(output); 341 const std::string md5 = base::MD5String(output);
299 const std::string kExpectedMD5 = "d1ae4ac8a17a0e09317113ab284b57a6"; 342 EXPECT_EQ(kQuuxExpectedMD5, md5);
300 EXPECT_EQ(kExpectedMD5, md5);
301 } 343 }
302 344
303 TEST_F(ZipReaderTest, current_entry_info_RegularFile) { 345 TEST_F(ZipReaderTest, current_entry_info_RegularFile) {
304 ZipReader reader; 346 ZipReader reader;
305 ASSERT_TRUE(reader.Open(test_zip_file_)); 347 ASSERT_TRUE(reader.Open(test_zip_file_));
306 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt")); 348 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
307 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path)); 349 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
308 ZipReader::EntryInfo* current_entry_info = reader.current_entry_info(); 350 ZipReader::EntryInfo* current_entry_info = reader.current_entry_info();
309 351
310 EXPECT_EQ(target_path, current_entry_info->file_path()); 352 EXPECT_EQ(target_path, current_entry_info->file_path());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path)); 463 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
422 ASSERT_TRUE(reader.ExtractCurrentEntryToFilePath( 464 ASSERT_TRUE(reader.ExtractCurrentEntryToFilePath(
423 test_dir_.AppendASCII("test.txt"))); 465 test_dir_.AppendASCII("test.txt")));
424 466
425 std::string actual; 467 std::string actual;
426 ASSERT_TRUE(base::ReadFileToString( 468 ASSERT_TRUE(base::ReadFileToString(
427 test_dir_.AppendASCII("test.txt"), &actual)); 469 test_dir_.AppendASCII("test.txt"), &actual));
428 EXPECT_EQ(std::string("This is a test.\n"), actual); 470 EXPECT_EQ(std::string("This is a test.\n"), actual);
429 } 471 }
430 472
473 // Verifies that the asynchronous extraction to a file works.
474 TEST_F(ZipReaderTest, ExtractToFileAsync_RegularFile) {
475 mock_listener_->ExpectSuccessWithProgress();
476
477 ZipReader reader;
478 base::FilePath target_file = test_dir_.AppendASCII("quux.txt");
479 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
480 ASSERT_TRUE(reader.Open(test_zip_file_));
481 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
482 reader.ExtractCurrentEntryToFilePathAsync(target_file,
483 message_loop_proxy_,
484 mock_listener_);
485
486 base::RunLoop().RunUntilIdle();
487
488 CompareFileAndMD5(target_file, kQuuxExpectedMD5);
489 }
490
491 // Verifies that the asynchronous extraction to a file works.
492 TEST_F(ZipReaderTest, ExtractToFileAsync_Directory) {
493 mock_listener_->ExpectSuccess();
494
495 ZipReader reader;
496 base::FilePath target_path(FILE_PATH_LITERAL("foo/"));
497 ASSERT_TRUE(reader.Open(test_zip_file_));
498 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
499 reader.ExtractCurrentEntryToFilePathAsync(target_path,
500 message_loop_proxy_,
501 mock_listener_);
502
503 base::RunLoop().RunUntilIdle();
504
505 ASSERT_TRUE(base::DirectoryExists(target_path));
506 }
507
508 // Verifies that the asynchronous extraction to a directory works.
509 TEST_F(ZipReaderTest, ExtractIntoDirectoryAsync_RegularFile) {
510 mock_listener_->ExpectSuccessWithProgress();
511
512 ZipReader reader;
513 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
514 base::FilePath target_file = test_dir_.AppendASCII("foo/bar/quux.txt");
515 ASSERT_TRUE(reader.Open(test_zip_file_));
516 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
517 reader.ExtractCurrentEntryIntoDirectoryAsync(test_dir_,
518 message_loop_proxy_,
519 mock_listener_);
520
521 base::RunLoop().RunUntilIdle();
522
523 ASSERT_TRUE(base::DirectoryExists(test_dir_.AppendASCII("foo/bar")));
524 CompareFileAndMD5(target_file, kQuuxExpectedMD5);
525 }
526
527 #if defined(OS_POSIX)
528 // Verifies that the asynchronous extraction to a file descriptor works.
529 TEST_F(ZipReaderTest, ExtractToFdAsync) {
530 mock_listener_->ExpectSuccessWithProgress();
531
532 ZipReader reader;
533 PlatformFileWrapper zip_fd_wrapper(test_zip_file_,
534 PlatformFileWrapper::READ_ONLY);
535 ASSERT_TRUE(reader.OpenFromPlatformFile(zip_fd_wrapper.platform_file()));
536 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
537 base::FilePath out_path = test_dir_.AppendASCII("quux.txt");
538 PlatformFileWrapper out_fd_w(out_path, PlatformFileWrapper::READ_WRITE);
539 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
540 reader.ExtractCurrentEntryToFdAsync(out_fd_w.platform_file(),
541 message_loop_proxy_,
542 mock_listener_);
543
544 base::RunLoop().RunUntilIdle();
545
546 CompareFileAndMD5(out_path, kQuuxExpectedMD5);
547 }
548 #endif
549
550 // Verifies that the asynchronous extraction to a platform file works.
551 TEST_F(ZipReaderTest, ExtractToPlatformFileAsync) {
552 mock_listener_->ExpectSuccessWithProgress();
553
554 ZipReader reader;
555 PlatformFileWrapper zip_fd_wrapper(test_zip_file_,
556 PlatformFileWrapper::READ_ONLY);
557 ASSERT_TRUE(reader.OpenFromPlatformFile(zip_fd_wrapper.platform_file()));
558 base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
559 base::FilePath out_path = test_dir_.AppendASCII("quux.txt");
560 PlatformFileWrapper out_fd_w(out_path, PlatformFileWrapper::READ_WRITE);
561 ASSERT_TRUE(reader.LocateAndOpenEntry(target_path));
562 reader.ExtractCurrentEntryToPlatformFileAsync(out_fd_w.platform_file(),
563 message_loop_proxy_,
564 mock_listener_);
565
566 base::RunLoop().RunUntilIdle();
567
568 CompareFileAndMD5(out_path, kQuuxExpectedMD5);
569 }
570
431 } // namespace zip 571 } // namespace zip
OLDNEW
« third_party/zlib/google/zip_reader.cc ('K') | « third_party/zlib/google/zip_reader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698