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