OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 bool has_more() { return has_more_; } | 67 bool has_more() { return has_more_; } |
68 | 68 |
69 private: | 69 private: |
70 base::File::Error result_; | 70 base::File::Error result_; |
71 fileapi::AsyncFileUtil::EntryList entry_list_; | 71 fileapi::AsyncFileUtil::EntryList entry_list_; |
72 bool has_more_; | 72 bool has_more_; |
73 | 73 |
74 DISALLOW_COPY_AND_ASSIGN(Event); | 74 DISALLOW_COPY_AND_ASSIGN(Event); |
75 }; | 75 }; |
76 | 76 |
77 CallbackLogger() : weak_ptr_factory_(this) {} | 77 CallbackLogger() {} |
78 virtual ~CallbackLogger() {} | 78 virtual ~CallbackLogger() {} |
79 | 79 |
80 void OnReadDirectory(base::File::Error result, | 80 void OnReadDirectory(base::File::Error result, |
81 const fileapi::AsyncFileUtil::EntryList& entry_list, | 81 const fileapi::AsyncFileUtil::EntryList& entry_list, |
82 bool has_more) { | 82 bool has_more) { |
83 events_.push_back(new Event(result, entry_list, has_more)); | 83 events_.push_back(new Event(result, entry_list, has_more)); |
84 } | 84 } |
85 | 85 |
86 ScopedVector<Event>& events() { return events_; } | 86 ScopedVector<Event>& events() { return events_; } |
87 | 87 |
88 base::WeakPtr<CallbackLogger> GetWeakPtr() { | |
89 return weak_ptr_factory_.GetWeakPtr(); | |
90 } | |
91 | |
92 private: | 88 private: |
93 ScopedVector<Event> events_; | 89 ScopedVector<Event> events_; |
94 bool dispatch_reply_; | 90 bool dispatch_reply_; |
95 base::WeakPtrFactory<CallbackLogger> weak_ptr_factory_; | |
96 | 91 |
97 DISALLOW_COPY_AND_ASSIGN(CallbackLogger); | 92 DISALLOW_COPY_AND_ASSIGN(CallbackLogger); |
98 }; | 93 }; |
99 | 94 |
100 } // namespace | 95 } // namespace |
101 | 96 |
102 class FileSystemProviderOperationsReadDirectoryTest : public testing::Test { | 97 class FileSystemProviderOperationsReadDirectoryTest : public testing::Test { |
103 protected: | 98 protected: |
104 FileSystemProviderOperationsReadDirectoryTest() {} | 99 FileSystemProviderOperationsReadDirectoryTest() {} |
105 virtual ~FileSystemProviderOperationsReadDirectoryTest() {} | 100 virtual ~FileSystemProviderOperationsReadDirectoryTest() {} |
(...skipping 10 matching lines...) Expand all Loading... |
116 }; | 111 }; |
117 | 112 |
118 TEST_F(FileSystemProviderOperationsReadDirectoryTest, Execute) { | 113 TEST_F(FileSystemProviderOperationsReadDirectoryTest, Execute) { |
119 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 114 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
120 CallbackLogger callback_logger; | 115 CallbackLogger callback_logger; |
121 | 116 |
122 ReadDirectory read_directory(NULL, | 117 ReadDirectory read_directory(NULL, |
123 file_system_info_, | 118 file_system_info_, |
124 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 119 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
125 base::Bind(&CallbackLogger::OnReadDirectory, | 120 base::Bind(&CallbackLogger::OnReadDirectory, |
126 callback_logger.GetWeakPtr())); | 121 base::Unretained(&callback_logger))); |
127 read_directory.SetDispatchEventImplForTesting( | 122 read_directory.SetDispatchEventImplForTesting( |
128 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, | 123 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, |
129 base::Unretained(&dispatcher))); | 124 base::Unretained(&dispatcher))); |
130 | 125 |
131 EXPECT_TRUE(read_directory.Execute(kRequestId)); | 126 EXPECT_TRUE(read_directory.Execute(kRequestId)); |
132 | 127 |
133 ASSERT_EQ(1u, dispatcher.events().size()); | 128 ASSERT_EQ(1u, dispatcher.events().size()); |
134 extensions::Event* event = dispatcher.events()[0]; | 129 extensions::Event* event = dispatcher.events()[0]; |
135 EXPECT_EQ(extensions::api::file_system_provider::OnReadDirectoryRequested:: | 130 EXPECT_EQ(extensions::api::file_system_provider::OnReadDirectoryRequested:: |
136 kEventName, | 131 kEventName, |
(...skipping 18 matching lines...) Expand all Loading... |
155 } | 150 } |
156 | 151 |
157 TEST_F(FileSystemProviderOperationsReadDirectoryTest, Execute_NoListener) { | 152 TEST_F(FileSystemProviderOperationsReadDirectoryTest, Execute_NoListener) { |
158 LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 153 LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
159 CallbackLogger callback_logger; | 154 CallbackLogger callback_logger; |
160 | 155 |
161 ReadDirectory read_directory(NULL, | 156 ReadDirectory read_directory(NULL, |
162 file_system_info_, | 157 file_system_info_, |
163 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 158 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
164 base::Bind(&CallbackLogger::OnReadDirectory, | 159 base::Bind(&CallbackLogger::OnReadDirectory, |
165 callback_logger.GetWeakPtr())); | 160 base::Unretained(&callback_logger))); |
166 read_directory.SetDispatchEventImplForTesting( | 161 read_directory.SetDispatchEventImplForTesting( |
167 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, | 162 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, |
168 base::Unretained(&dispatcher))); | 163 base::Unretained(&dispatcher))); |
169 | 164 |
170 EXPECT_FALSE(read_directory.Execute(kRequestId)); | 165 EXPECT_FALSE(read_directory.Execute(kRequestId)); |
171 } | 166 } |
172 | 167 |
173 TEST_F(FileSystemProviderOperationsReadDirectoryTest, OnSuccess) { | 168 TEST_F(FileSystemProviderOperationsReadDirectoryTest, OnSuccess) { |
174 using extensions::api::file_system_provider_internal:: | 169 using extensions::api::file_system_provider_internal:: |
175 ReadDirectoryRequestedSuccess::Params; | 170 ReadDirectoryRequestedSuccess::Params; |
176 | 171 |
177 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 172 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
178 CallbackLogger callback_logger; | 173 CallbackLogger callback_logger; |
179 | 174 |
180 ReadDirectory read_directory(NULL, | 175 ReadDirectory read_directory(NULL, |
181 file_system_info_, | 176 file_system_info_, |
182 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 177 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
183 base::Bind(&CallbackLogger::OnReadDirectory, | 178 base::Bind(&CallbackLogger::OnReadDirectory, |
184 callback_logger.GetWeakPtr())); | 179 base::Unretained(&callback_logger))); |
185 read_directory.SetDispatchEventImplForTesting( | 180 read_directory.SetDispatchEventImplForTesting( |
186 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, | 181 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, |
187 base::Unretained(&dispatcher))); | 182 base::Unretained(&dispatcher))); |
188 | 183 |
189 EXPECT_TRUE(read_directory.Execute(kRequestId)); | 184 EXPECT_TRUE(read_directory.Execute(kRequestId)); |
190 | 185 |
191 // Sample input as JSON. Keep in sync with file_system_provider_api.idl. | 186 // Sample input as JSON. Keep in sync with file_system_provider_api.idl. |
192 // As for now, it is impossible to create *::Params class directly, not from | 187 // As for now, it is impossible to create *::Params class directly, not from |
193 // base::Value. | 188 // base::Value. |
194 const std::string input = | 189 const std::string input = |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 } | 237 } |
243 | 238 |
244 TEST_F(FileSystemProviderOperationsReadDirectoryTest, OnError) { | 239 TEST_F(FileSystemProviderOperationsReadDirectoryTest, OnError) { |
245 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 240 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
246 CallbackLogger callback_logger; | 241 CallbackLogger callback_logger; |
247 | 242 |
248 ReadDirectory read_directory(NULL, | 243 ReadDirectory read_directory(NULL, |
249 file_system_info_, | 244 file_system_info_, |
250 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 245 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
251 base::Bind(&CallbackLogger::OnReadDirectory, | 246 base::Bind(&CallbackLogger::OnReadDirectory, |
252 callback_logger.GetWeakPtr())); | 247 base::Unretained(&callback_logger))); |
253 read_directory.SetDispatchEventImplForTesting( | 248 read_directory.SetDispatchEventImplForTesting( |
254 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, | 249 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, |
255 base::Unretained(&dispatcher))); | 250 base::Unretained(&dispatcher))); |
256 | 251 |
257 EXPECT_TRUE(read_directory.Execute(kRequestId)); | 252 EXPECT_TRUE(read_directory.Execute(kRequestId)); |
258 | 253 |
259 read_directory.OnError(kRequestId, | 254 read_directory.OnError(kRequestId, |
260 scoped_ptr<RequestValue>(new RequestValue()), | 255 scoped_ptr<RequestValue>(new RequestValue()), |
261 base::File::FILE_ERROR_TOO_MANY_OPENED); | 256 base::File::FILE_ERROR_TOO_MANY_OPENED); |
262 | 257 |
263 ASSERT_EQ(1u, callback_logger.events().size()); | 258 ASSERT_EQ(1u, callback_logger.events().size()); |
264 CallbackLogger::Event* event = callback_logger.events()[0]; | 259 CallbackLogger::Event* event = callback_logger.events()[0]; |
265 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); | 260 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); |
266 ASSERT_EQ(0u, event->entry_list().size()); | 261 ASSERT_EQ(0u, event->entry_list().size()); |
267 } | 262 } |
268 | 263 |
269 } // namespace operations | 264 } // namespace operations |
270 } // namespace file_system_provider | 265 } // namespace file_system_provider |
271 } // namespace chromeos | 266 } // namespace chromeos |
OLD | NEW |