OLD | NEW |
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 "chrome/browser/chromeos/file_manager/zip_file_creator.h" | 5 #include "chrome/browser/chromeos/file_manager/zip_file_creator.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 } // namespace | 48 } // namespace |
49 | 49 |
50 IN_PROC_BROWSER_TEST_F(ZipFileCreatorTest, FailZipForAbsentFile) { | 50 IN_PROC_BROWSER_TEST_F(ZipFileCreatorTest, FailZipForAbsentFile) { |
51 base::RunLoop run_loop; | 51 base::RunLoop run_loop; |
52 bool success = true; | 52 bool success = true; |
53 | 53 |
54 std::vector<base::FilePath> paths; | 54 std::vector<base::FilePath> paths; |
55 paths.push_back(base::FilePath(FILE_PATH_LITERAL("not.exist"))); | 55 paths.push_back(base::FilePath(FILE_PATH_LITERAL("not.exist"))); |
56 (new ZipFileCreator( | 56 (new ZipFileCreator( |
57 base::Bind(&TestCallback, &success, | 57 base::Bind( |
58 content::GetDeferredQuitTaskForRunLoop(&run_loop)), | 58 &TestCallback, &success, content::GetQuitTaskForRunLoop(&run_loop)), |
59 zip_base_dir(), paths, zip_archive_path())) | 59 zip_base_dir(), |
60 ->Start(); | 60 paths, |
| 61 zip_archive_path()))->Start(); |
61 | 62 |
62 content::RunThisRunLoop(&run_loop); | 63 content::RunThisRunLoop(&run_loop); |
63 EXPECT_FALSE(success); | 64 EXPECT_FALSE(success); |
64 } | 65 } |
65 | 66 |
66 IN_PROC_BROWSER_TEST_F(ZipFileCreatorTest, SomeFilesZip) { | 67 IN_PROC_BROWSER_TEST_F(ZipFileCreatorTest, SomeFilesZip) { |
67 // Prepare files. | 68 // Prepare files. |
68 const base::FilePath kDir1(FILE_PATH_LITERAL("foo")); | 69 const base::FilePath kDir1(FILE_PATH_LITERAL("foo")); |
69 const base::FilePath kFile1(kDir1.AppendASCII("bar")); | 70 const base::FilePath kFile1(kDir1.AppendASCII("bar")); |
70 const base::FilePath kFile2(FILE_PATH_LITERAL("random")); | 71 const base::FilePath kFile2(FILE_PATH_LITERAL("random")); |
71 const int kRandomDataSize = 100000; | 72 const int kRandomDataSize = 100000; |
72 const std::string kRandomData = base::RandBytesAsString(kRandomDataSize); | 73 const std::string kRandomData = base::RandBytesAsString(kRandomDataSize); |
73 base::CreateDirectory(zip_base_dir().Append(kDir1)); | 74 base::CreateDirectory(zip_base_dir().Append(kDir1)); |
74 base::WriteFile(zip_base_dir().Append(kFile1), "123", 3); | 75 base::WriteFile(zip_base_dir().Append(kFile1), "123", 3); |
75 base::WriteFile(zip_base_dir().Append(kFile2), | 76 base::WriteFile(zip_base_dir().Append(kFile2), |
76 kRandomData.c_str(), kRandomData.size()); | 77 kRandomData.c_str(), kRandomData.size()); |
77 | 78 |
78 bool success = false; | 79 bool success = false; |
79 base::RunLoop run_loop; | 80 base::RunLoop run_loop; |
80 | 81 |
81 std::vector<base::FilePath> paths; | 82 std::vector<base::FilePath> paths; |
82 paths.push_back(kDir1); | 83 paths.push_back(kDir1); |
83 paths.push_back(kFile1); | 84 paths.push_back(kFile1); |
84 paths.push_back(kFile2); | 85 paths.push_back(kFile2); |
85 (new ZipFileCreator( | 86 (new ZipFileCreator( |
86 base::Bind(&TestCallback, &success, | 87 base::Bind( |
87 content::GetDeferredQuitTaskForRunLoop(&run_loop)), | 88 &TestCallback, &success, content::GetQuitTaskForRunLoop(&run_loop)), |
88 zip_base_dir(), paths, zip_archive_path())) | 89 zip_base_dir(), |
89 ->Start(); | 90 paths, |
| 91 zip_archive_path()))->Start(); |
90 | 92 |
91 content::RunThisRunLoop(&run_loop); | 93 content::RunThisRunLoop(&run_loop); |
92 EXPECT_TRUE(success); | 94 EXPECT_TRUE(success); |
93 | 95 |
94 // Check the archive content. | 96 // Check the archive content. |
95 zip::ZipReader reader; | 97 zip::ZipReader reader; |
96 ASSERT_TRUE(reader.Open(zip_archive_path())); | 98 ASSERT_TRUE(reader.Open(zip_archive_path())); |
97 EXPECT_EQ(3, reader.num_entries()); | 99 EXPECT_EQ(3, reader.num_entries()); |
98 while (reader.HasMore()) { | 100 while (reader.HasMore()) { |
99 ASSERT_TRUE(reader.OpenCurrentEntryInZip()); | 101 ASSERT_TRUE(reader.OpenCurrentEntryInZip()); |
(...skipping 12 matching lines...) Expand all Loading... |
112 EXPECT_TRUE(reader.ExtractCurrentEntryToFilePath(out)); | 114 EXPECT_TRUE(reader.ExtractCurrentEntryToFilePath(out)); |
113 EXPECT_TRUE(base::ContentsEqual(zip_base_dir().Append(kFile2), out)); | 115 EXPECT_TRUE(base::ContentsEqual(zip_base_dir().Append(kFile2), out)); |
114 } else { | 116 } else { |
115 ADD_FAILURE(); | 117 ADD_FAILURE(); |
116 } | 118 } |
117 ASSERT_TRUE(reader.AdvanceToNextEntry()); | 119 ASSERT_TRUE(reader.AdvanceToNextEntry()); |
118 } | 120 } |
119 } | 121 } |
120 | 122 |
121 } // namespace file_manager | 123 } // namespace file_manager |
OLD | NEW |