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 "base/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" |
7 #include "base/i18n/file_util_icu.h" | 8 #include "base/i18n/file_util_icu.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
11 #include "base/scoped_temp_dir.h" | |
12 #include "net/base/directory_lister.h" | 12 #include "net/base/directory_lister.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 | 17 |
18 class ListerDelegate : public DirectoryLister::DirectoryListerDelegate { | 18 class ListerDelegate : public DirectoryLister::DirectoryListerDelegate { |
19 public: | 19 public: |
20 ListerDelegate(bool recursive, | 20 ListerDelegate(bool recursive, |
21 bool quit_loop_after_each_file) | 21 bool quit_loop_after_each_file) |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 int num_files = delegate.num_files(); | 125 int num_files = delegate.num_files(); |
126 | 126 |
127 lister.Cancel(); | 127 lister.Cancel(); |
128 | 128 |
129 MessageLoop::current()->RunUntilIdle(); | 129 MessageLoop::current()->RunUntilIdle(); |
130 | 130 |
131 EXPECT_EQ(num_files, delegate.num_files()); | 131 EXPECT_EQ(num_files, delegate.num_files()); |
132 } | 132 } |
133 | 133 |
134 TEST(DirectoryListerTest, EmptyDirTest) { | 134 TEST(DirectoryListerTest, EmptyDirTest) { |
135 ScopedTempDir tempDir; | 135 base::ScopedTempDir tempDir; |
136 EXPECT_TRUE(tempDir.CreateUniqueTempDir()); | 136 EXPECT_TRUE(tempDir.CreateUniqueTempDir()); |
137 | 137 |
138 bool kRecursive = false; | 138 bool kRecursive = false; |
139 bool kQuitLoopAfterEachFile = false; | 139 bool kQuitLoopAfterEachFile = false; |
140 ListerDelegate delegate(kRecursive, kQuitLoopAfterEachFile); | 140 ListerDelegate delegate(kRecursive, kQuitLoopAfterEachFile); |
141 DirectoryLister lister(tempDir.path(), &delegate); | 141 DirectoryLister lister(tempDir.path(), &delegate); |
142 lister.Start(); | 142 lister.Start(); |
143 | 143 |
144 MessageLoop::current()->Run(); | 144 MessageLoop::current()->Run(); |
145 | 145 |
146 // Contains only the parent directory ("..") | 146 // Contains only the parent directory ("..") |
147 EXPECT_EQ(1, delegate.num_files()); | 147 EXPECT_EQ(1, delegate.num_files()); |
148 EXPECT_EQ(OK, delegate.error()); | 148 EXPECT_EQ(OK, delegate.error()); |
149 } | 149 } |
150 | 150 |
151 } // namespace net | 151 } // namespace net |
OLD | NEW |