| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <list> | 5 #include <list> |
| 6 #include <utility> | 6 #include <utility> |
| 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" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/i18n/file_util_icu.h" | 13 #include "base/i18n/file_util_icu.h" |
| 14 #include "base/message_loop/message_loop.h" | |
| 15 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 16 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 17 #include "base/test/scoped_task_scheduler.h" | |
| 18 #include "net/base/directory_lister.h" | 16 #include "net/base/directory_lister.h" |
| 19 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 20 #include "net/test/gtest_util.h" | 18 #include "net/test/gtest_util.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "testing/platform_test.h" | 21 #include "testing/platform_test.h" |
| 24 | 22 |
| 25 using net::test::IsError; | 23 using net::test::IsError; |
| 26 using net::test::IsOk; | 24 using net::test::IsOk; |
| 27 | 25 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 126 |
| 129 std::vector<base::FileEnumerator::FileInfo> file_list_; | 127 std::vector<base::FileEnumerator::FileInfo> file_list_; |
| 130 std::vector<base::FilePath> paths_; | 128 std::vector<base::FilePath> paths_; |
| 131 }; | 129 }; |
| 132 | 130 |
| 133 } // namespace | 131 } // namespace |
| 134 | 132 |
| 135 class DirectoryListerTest : public PlatformTest { | 133 class DirectoryListerTest : public PlatformTest { |
| 136 public: | 134 public: |
| 137 DirectoryListerTest() | 135 DirectoryListerTest() |
| 138 : scoped_task_scheduler_(base::MessageLoop::current()), | 136 : total_created_file_system_objects_in_temp_root_dir_(0), |
| 139 total_created_file_system_objects_in_temp_root_dir_(0), | |
| 140 created_file_system_objects_in_temp_root_dir_(0) {} | 137 created_file_system_objects_in_temp_root_dir_(0) {} |
| 141 | 138 |
| 142 void SetUp() override { | 139 void SetUp() override { |
| 143 // Randomly create a directory structure of depth 3 in a temporary root | 140 // Randomly create a directory structure of depth 3 in a temporary root |
| 144 // directory. | 141 // directory. |
| 145 std::list<std::pair<base::FilePath, int> > directories; | 142 std::list<std::pair<base::FilePath, int> > directories; |
| 146 ASSERT_TRUE(temp_root_dir_.CreateUniqueTempDir()); | 143 ASSERT_TRUE(temp_root_dir_.CreateUniqueTempDir()); |
| 147 directories.push_back(std::make_pair(temp_root_dir_.GetPath(), 0)); | 144 directories.push_back(std::make_pair(temp_root_dir_.GetPath(), 0)); |
| 148 while (!directories.empty()) { | 145 while (!directories.empty()) { |
| 149 std::pair<base::FilePath, int> dir_data = directories.front(); | 146 std::pair<base::FilePath, int> dir_data = directories.front(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 180 // include "..". | 177 // include "..". |
| 181 return total_created_file_system_objects_in_temp_root_dir_; | 178 return total_created_file_system_objects_in_temp_root_dir_; |
| 182 } | 179 } |
| 183 | 180 |
| 184 int expected_list_length_non_recursive() const { | 181 int expected_list_length_non_recursive() const { |
| 185 // List should include everything in the top level directory, and "..". | 182 // List should include everything in the top level directory, and "..". |
| 186 return created_file_system_objects_in_temp_root_dir_ + 1; | 183 return created_file_system_objects_in_temp_root_dir_ + 1; |
| 187 } | 184 } |
| 188 | 185 |
| 189 private: | 186 private: |
| 190 base::test::ScopedTaskScheduler scoped_task_scheduler_; | |
| 191 | |
| 192 // Number of files and directories created in SetUp, excluding | 187 // Number of files and directories created in SetUp, excluding |
| 193 // |temp_root_dir_| itself. Includes all nested directories and their files. | 188 // |temp_root_dir_| itself. Includes all nested directories and their files. |
| 194 int total_created_file_system_objects_in_temp_root_dir_; | 189 int total_created_file_system_objects_in_temp_root_dir_; |
| 195 // Number of files and directories created directly in |temp_root_dir_|. | 190 // Number of files and directories created directly in |temp_root_dir_|. |
| 196 int created_file_system_objects_in_temp_root_dir_; | 191 int created_file_system_objects_in_temp_root_dir_; |
| 197 | 192 |
| 198 base::ScopedTempDir temp_root_dir_; | 193 base::ScopedTempDir temp_root_dir_; |
| 199 }; | 194 }; |
| 200 | 195 |
| 201 TEST_F(DirectoryListerTest, BigDirTest) { | 196 TEST_F(DirectoryListerTest, BigDirTest) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 ListerDelegate delegate(DirectoryLister::ALPHA_DIRS_FIRST); | 287 ListerDelegate delegate(DirectoryLister::ALPHA_DIRS_FIRST); |
| 293 DirectoryLister lister( | 288 DirectoryLister lister( |
| 294 tempDir.GetPath().AppendASCII("this_path_does_not_exist"), &delegate); | 289 tempDir.GetPath().AppendASCII("this_path_does_not_exist"), &delegate); |
| 295 delegate.Run(&lister); | 290 delegate.Run(&lister); |
| 296 | 291 |
| 297 EXPECT_THAT(delegate.error(), IsError(ERR_FILE_NOT_FOUND)); | 292 EXPECT_THAT(delegate.error(), IsError(ERR_FILE_NOT_FOUND)); |
| 298 EXPECT_EQ(0, delegate.num_files()); | 293 EXPECT_EQ(0, delegate.num_files()); |
| 299 } | 294 } |
| 300 | 295 |
| 301 } // namespace net | 296 } // namespace net |
| OLD | NEW |