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

Unified Diff: net/base/directory_lister_unittest.cc

Issue 3175023: Allow net::DirectoryLister to be used to recursively list the directory, and ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/directory_lister.cc ('k') | net/url_request/url_request_file_dir_job.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/directory_lister_unittest.cc
===================================================================
--- net/base/directory_lister_unittest.cc (revision 56913)
+++ net/base/directory_lister_unittest.cc (working copy)
@@ -5,6 +5,7 @@
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/i18n/file_util_icu.h"
+#include "base/logging.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "net/base/directory_lister.h"
@@ -17,19 +18,37 @@
class ListerDelegate : public net::DirectoryLister::DirectoryListerDelegate {
public:
- ListerDelegate() : error_(-1) {
+ explicit ListerDelegate(bool recursive) : error_(-1), recursive_(recursive) {
}
- void OnListFile(const file_util::FileEnumerator::FindInfo& data) {
- file_list_.push_back(data);
+ void OnListFile(const net::DirectoryLister::DirectoryListerData& data) {
+ file_list_.push_back(data.info);
+ paths_.push_back(data.path);
}
void OnListDone(int error) {
error_ = error;
MessageLoop::current()->Quit();
+ if (recursive_)
+ CheckRecursiveSort();
+ else
+ CheckSort();
+ }
+ void CheckRecursiveSort() {
// Check that we got files in the right order.
if (!file_list_.empty()) {
for (size_t previous = 0, current = 1;
current < file_list_.size();
previous++, current++) {
+ EXPECT_TRUE(file_util::LocaleAwareCompareFilenames(
+ paths_[previous], paths_[current]));
+ }
+ }
+ }
+ void CheckSort() {
+ // Check that we got files in the right order.
+ if (!file_list_.empty()) {
+ for (size_t previous = 0, current = 1;
+ current < file_list_.size();
+ previous++, current++) {
// Directories should come before files.
if (file_util::FileEnumerator::IsDirectory(file_list_[previous]) &&
!file_util::FileEnumerator::IsDirectory(file_list_[current])) {
@@ -48,14 +67,16 @@
int error() const { return error_; }
private:
int error_;
+ bool recursive_;
std::vector<file_util::FileEnumerator::FindInfo> file_list_;
+ std::vector<FilePath> paths_;
};
TEST(DirectoryListerTest, BigDirTest) {
FilePath path;
ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &path));
- ListerDelegate delegate;
+ ListerDelegate delegate(false);
scoped_refptr<net::DirectoryLister> lister =
new net::DirectoryLister(path, &delegate);
@@ -66,11 +87,29 @@
EXPECT_EQ(delegate.error(), net::OK);
}
+TEST(DirectoryListerTest, BigDirRecursiveTest) {
+ FilePath path;
+ ASSERT_TRUE(PathService::Get(base::DIR_EXE, &path));
+
+ ListerDelegate delegate(true);
+ scoped_refptr<net::DirectoryLister> lister =
+ new net::DirectoryLister(path,
+ true,
+ net::DirectoryLister::FULL_PATH,
+ &delegate);
+
+ lister->Start();
+
+ MessageLoop::current()->Run();
+
+ EXPECT_EQ(delegate.error(), net::OK);
+}
+
TEST(DirectoryListerTest, CancelTest) {
FilePath path;
ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &path));
- ListerDelegate delegate;
+ ListerDelegate delegate(false);
scoped_refptr<net::DirectoryLister> lister =
new net::DirectoryLister(path, &delegate);
« no previous file with comments | « net/base/directory_lister.cc ('k') | net/url_request/url_request_file_dir_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698