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 "chrome/browser/chromeos/file_system_provider/operations/read_directory
.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/read_directory
.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" | 15 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" |
16 #include "chrome/common/extensions/api/file_system_provider.h" | 16 #include "chrome/common/extensions/api/file_system_provider.h" |
17 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 17 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
18 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "webkit/browser/fileapi/async_file_util.h" | 20 #include "storage/browser/fileapi/async_file_util.h" |
21 | 21 |
22 namespace chromeos { | 22 namespace chromeos { |
23 namespace file_system_provider { | 23 namespace file_system_provider { |
24 namespace operations { | 24 namespace operations { |
25 namespace { | 25 namespace { |
26 | 26 |
27 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 27 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
28 const char kFileSystemId[] = "testing-file-system"; | 28 const char kFileSystemId[] = "testing-file-system"; |
29 const int kRequestId = 2; | 29 const int kRequestId = 2; |
30 const base::FilePath::CharType kDirectoryPath[] = "/directory"; | 30 const base::FilePath::CharType kDirectoryPath[] = "/directory"; |
31 | 31 |
32 // Callback invocation logger. Acts as a fileapi end-point. | 32 // Callback invocation logger. Acts as a fileapi end-point. |
33 class CallbackLogger { | 33 class CallbackLogger { |
34 public: | 34 public: |
35 class Event { | 35 class Event { |
36 public: | 36 public: |
37 Event(base::File::Error result, | 37 Event(base::File::Error result, |
38 const fileapi::AsyncFileUtil::EntryList& entry_list, | 38 const storage::AsyncFileUtil::EntryList& entry_list, |
39 bool has_more) | 39 bool has_more) |
40 : result_(result), entry_list_(entry_list), has_more_(has_more) {} | 40 : result_(result), entry_list_(entry_list), has_more_(has_more) {} |
41 virtual ~Event() {} | 41 virtual ~Event() {} |
42 | 42 |
43 base::File::Error result() { return result_; } | 43 base::File::Error result() { return result_; } |
44 const fileapi::AsyncFileUtil::EntryList& entry_list() { | 44 const storage::AsyncFileUtil::EntryList& entry_list() { |
45 return entry_list_; | 45 return entry_list_; |
46 } | 46 } |
47 bool has_more() { return has_more_; } | 47 bool has_more() { return has_more_; } |
48 | 48 |
49 private: | 49 private: |
50 base::File::Error result_; | 50 base::File::Error result_; |
51 fileapi::AsyncFileUtil::EntryList entry_list_; | 51 storage::AsyncFileUtil::EntryList entry_list_; |
52 bool has_more_; | 52 bool has_more_; |
53 | 53 |
54 DISALLOW_COPY_AND_ASSIGN(Event); | 54 DISALLOW_COPY_AND_ASSIGN(Event); |
55 }; | 55 }; |
56 | 56 |
57 CallbackLogger() {} | 57 CallbackLogger() {} |
58 virtual ~CallbackLogger() {} | 58 virtual ~CallbackLogger() {} |
59 | 59 |
60 void OnReadDirectory(base::File::Error result, | 60 void OnReadDirectory(base::File::Error result, |
61 const fileapi::AsyncFileUtil::EntryList& entry_list, | 61 const storage::AsyncFileUtil::EntryList& entry_list, |
62 bool has_more) { | 62 bool has_more) { |
63 events_.push_back(new Event(result, entry_list, has_more)); | 63 events_.push_back(new Event(result, entry_list, has_more)); |
64 } | 64 } |
65 | 65 |
66 ScopedVector<Event>& events() { return events_; } | 66 ScopedVector<Event>& events() { return events_; } |
67 | 67 |
68 private: | 68 private: |
69 ScopedVector<Event> events_; | 69 ScopedVector<Event> events_; |
70 bool dispatch_reply_; | 70 bool dispatch_reply_; |
71 | 71 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 ASSERT_TRUE(request_value.get()); | 200 ASSERT_TRUE(request_value.get()); |
201 | 201 |
202 const bool has_more = false; | 202 const bool has_more = false; |
203 read_directory.OnSuccess(kRequestId, request_value.Pass(), has_more); | 203 read_directory.OnSuccess(kRequestId, request_value.Pass(), has_more); |
204 | 204 |
205 ASSERT_EQ(1u, callback_logger.events().size()); | 205 ASSERT_EQ(1u, callback_logger.events().size()); |
206 CallbackLogger::Event* event = callback_logger.events()[0]; | 206 CallbackLogger::Event* event = callback_logger.events()[0]; |
207 EXPECT_EQ(base::File::FILE_OK, event->result()); | 207 EXPECT_EQ(base::File::FILE_OK, event->result()); |
208 | 208 |
209 ASSERT_EQ(1u, event->entry_list().size()); | 209 ASSERT_EQ(1u, event->entry_list().size()); |
210 const fileapi::DirectoryEntry entry = event->entry_list()[0]; | 210 const storage::DirectoryEntry entry = event->entry_list()[0]; |
211 EXPECT_FALSE(entry.is_directory); | 211 EXPECT_FALSE(entry.is_directory); |
212 EXPECT_EQ("blueberries.txt", entry.name); | 212 EXPECT_EQ("blueberries.txt", entry.name); |
213 EXPECT_EQ(4096, entry.size); | 213 EXPECT_EQ(4096, entry.size); |
214 base::Time expected_time; | 214 base::Time expected_time; |
215 EXPECT_TRUE( | 215 EXPECT_TRUE( |
216 base::Time::FromString("Thu Apr 24 00:46:52 UTC 2014", &expected_time)); | 216 base::Time::FromString("Thu Apr 24 00:46:52 UTC 2014", &expected_time)); |
217 EXPECT_EQ(expected_time, entry.last_modified_time); | 217 EXPECT_EQ(expected_time, entry.last_modified_time); |
218 } | 218 } |
219 | 219 |
220 TEST_F(FileSystemProviderOperationsReadDirectoryTest, OnError) { | 220 TEST_F(FileSystemProviderOperationsReadDirectoryTest, OnError) { |
(...skipping 17 matching lines...) Expand all Loading... |
238 | 238 |
239 ASSERT_EQ(1u, callback_logger.events().size()); | 239 ASSERT_EQ(1u, callback_logger.events().size()); |
240 CallbackLogger::Event* event = callback_logger.events()[0]; | 240 CallbackLogger::Event* event = callback_logger.events()[0]; |
241 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); | 241 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); |
242 ASSERT_EQ(0u, event->entry_list().size()); | 242 ASSERT_EQ(0u, event->entry_list().size()); |
243 } | 243 } |
244 | 244 |
245 } // namespace operations | 245 } // namespace operations |
246 } // namespace file_system_provider | 246 } // namespace file_system_provider |
247 } // namespace chromeos | 247 } // namespace chromeos |
OLD | NEW |