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 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "chrome/browser/chromeos/file_system_provider/operations/close_file.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "chrome/browser/chromeos/file_system_provider/operations/create_directo
ry.h" |
12 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" | 13 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" |
13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" | 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
14 #include "chrome/common/extensions/api/file_system_provider.h" | 15 #include "chrome/common/extensions/api/file_system_provider.h" |
15 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 16 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
16 #include "extensions/browser/event_router.h" | 17 #include "extensions/browser/event_router.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "webkit/browser/fileapi/async_file_util.h" | 19 #include "webkit/browser/fileapi/async_file_util.h" |
19 | 20 |
20 namespace chromeos { | 21 namespace chromeos { |
21 namespace file_system_provider { | 22 namespace file_system_provider { |
22 namespace operations { | 23 namespace operations { |
23 namespace { | 24 namespace { |
24 | 25 |
25 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 26 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
26 const char kFileSystemId[] = "testing-file-system"; | 27 const char kFileSystemId[] = "testing-file-system"; |
27 const int kRequestId = 2; | 28 const int kRequestId = 2; |
28 const int kOpenRequestId = 3; | 29 const base::FilePath::CharType kDirectoryPath[] = "/kitty/and/puppy/happy"; |
29 | 30 |
30 } // namespace | 31 } // namespace |
31 | 32 |
32 class FileSystemProviderOperationsCloseFileTest : public testing::Test { | 33 class FileSystemProviderOperationsCreateDirectoryTest : public testing::Test { |
33 protected: | 34 protected: |
34 FileSystemProviderOperationsCloseFileTest() {} | 35 FileSystemProviderOperationsCreateDirectoryTest() {} |
35 virtual ~FileSystemProviderOperationsCloseFileTest() {} | 36 virtual ~FileSystemProviderOperationsCreateDirectoryTest() {} |
36 | 37 |
37 virtual void SetUp() OVERRIDE { | 38 virtual void SetUp() OVERRIDE { |
38 file_system_info_ = | 39 file_system_info_ = |
39 ProvidedFileSystemInfo(kExtensionId, | 40 ProvidedFileSystemInfo(kExtensionId, |
40 kFileSystemId, | 41 kFileSystemId, |
41 "" /* file_system_name */, | 42 "" /* file_system_name */, |
42 base::FilePath() /* mount_path */); | 43 base::FilePath() /* mount_path */); |
43 } | 44 } |
44 | 45 |
45 ProvidedFileSystemInfo file_system_info_; | 46 ProvidedFileSystemInfo file_system_info_; |
46 }; | 47 }; |
47 | 48 |
48 TEST_F(FileSystemProviderOperationsCloseFileTest, Execute) { | 49 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute) { |
49 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 50 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
50 util::StatusCallbackLog callback_log; | 51 util::StatusCallbackLog callback_log; |
51 | 52 |
52 CloseFile close_file(NULL, | 53 CreateDirectory create_directory( |
53 file_system_info_, | 54 NULL, |
54 kOpenRequestId, | 55 file_system_info_, |
55 base::Bind(&util::LogStatusCallback, &callback_log)); | 56 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
56 close_file.SetDispatchEventImplForTesting( | 57 false /* exclusive */, |
| 58 true /* recursive */, |
| 59 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 60 create_directory.SetDispatchEventImplForTesting( |
57 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 61 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
58 base::Unretained(&dispatcher))); | 62 base::Unretained(&dispatcher))); |
59 | 63 |
60 EXPECT_TRUE(close_file.Execute(kRequestId)); | 64 EXPECT_TRUE(create_directory.Execute(kRequestId)); |
61 | 65 |
62 ASSERT_EQ(1u, dispatcher.events().size()); | 66 ASSERT_EQ(1u, dispatcher.events().size()); |
63 extensions::Event* event = dispatcher.events()[0]; | 67 extensions::Event* event = dispatcher.events()[0]; |
64 EXPECT_EQ( | 68 EXPECT_EQ(extensions::api::file_system_provider::OnCreateDirectoryRequested:: |
65 extensions::api::file_system_provider::OnCloseFileRequested::kEventName, | 69 kEventName, |
66 event->event_name); | 70 event->event_name); |
67 base::ListValue* event_args = event->event_args.get(); | 71 base::ListValue* event_args = event->event_args.get(); |
68 ASSERT_EQ(1u, event_args->GetSize()); | 72 ASSERT_EQ(1u, event_args->GetSize()); |
69 | 73 |
70 base::DictionaryValue* options = NULL; | 74 base::DictionaryValue* options = NULL; |
71 ASSERT_TRUE(event_args->GetDictionary(0, &options)); | 75 ASSERT_TRUE(event_args->GetDictionary(0, &options)); |
72 | 76 |
73 std::string event_file_system_id; | 77 std::string event_file_system_id; |
74 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); | 78 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); |
75 EXPECT_EQ(kFileSystemId, event_file_system_id); | 79 EXPECT_EQ(kFileSystemId, event_file_system_id); |
76 | 80 |
77 int event_request_id = -1; | 81 int event_request_id = -1; |
78 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); | 82 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); |
79 EXPECT_EQ(kRequestId, event_request_id); | 83 EXPECT_EQ(kRequestId, event_request_id); |
80 | 84 |
81 int event_open_request_id = -1; | 85 std::string event_directory_path; |
82 EXPECT_TRUE(options->GetInteger("openRequestId", &event_open_request_id)); | 86 EXPECT_TRUE(options->GetString("directoryPath", &event_directory_path)); |
83 EXPECT_EQ(kOpenRequestId, event_open_request_id); | 87 EXPECT_EQ(kDirectoryPath, event_directory_path); |
| 88 |
| 89 bool event_exclusive; |
| 90 EXPECT_TRUE(options->GetBoolean("exclusive", &event_exclusive)); |
| 91 EXPECT_FALSE(event_exclusive); |
| 92 |
| 93 bool event_recursive; |
| 94 EXPECT_TRUE(options->GetBoolean("recursive", &event_recursive)); |
| 95 EXPECT_TRUE(event_recursive); |
84 } | 96 } |
85 | 97 |
86 TEST_F(FileSystemProviderOperationsCloseFileTest, Execute_NoListener) { | 98 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_NoListener) { |
87 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 99 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
88 util::StatusCallbackLog callback_log; | 100 util::StatusCallbackLog callback_log; |
89 | 101 |
90 CloseFile close_file(NULL, | 102 CreateDirectory create_directory( |
91 file_system_info_, | 103 NULL, |
92 kOpenRequestId, | 104 file_system_info_, |
93 base::Bind(&util::LogStatusCallback, &callback_log)); | 105 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
94 close_file.SetDispatchEventImplForTesting( | 106 false /* exclusive */, |
| 107 true /* recursive */, |
| 108 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 109 create_directory.SetDispatchEventImplForTesting( |
95 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 110 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
96 base::Unretained(&dispatcher))); | 111 base::Unretained(&dispatcher))); |
97 | 112 |
98 EXPECT_FALSE(close_file.Execute(kRequestId)); | 113 EXPECT_FALSE(create_directory.Execute(kRequestId)); |
99 } | 114 } |
100 | 115 |
101 TEST_F(FileSystemProviderOperationsCloseFileTest, OnSuccess) { | 116 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnSuccess) { |
102 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 117 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
103 util::StatusCallbackLog callback_log; | 118 util::StatusCallbackLog callback_log; |
104 | 119 |
105 CloseFile close_file(NULL, | 120 CreateDirectory create_directory( |
106 file_system_info_, | 121 NULL, |
107 kOpenRequestId, | 122 file_system_info_, |
108 base::Bind(&util::LogStatusCallback, &callback_log)); | 123 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
109 close_file.SetDispatchEventImplForTesting( | 124 false /* exclusive */, |
| 125 true /* recursive */, |
| 126 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 127 create_directory.SetDispatchEventImplForTesting( |
110 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 128 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
111 base::Unretained(&dispatcher))); | 129 base::Unretained(&dispatcher))); |
112 | 130 |
113 EXPECT_TRUE(close_file.Execute(kRequestId)); | 131 EXPECT_TRUE(create_directory.Execute(kRequestId)); |
114 | 132 |
115 close_file.OnSuccess(kRequestId, | 133 create_directory.OnSuccess(kRequestId, |
116 scoped_ptr<RequestValue>(new RequestValue()), | 134 scoped_ptr<RequestValue>(new RequestValue()), |
117 false /* has_more */); | 135 false /* has_more */); |
118 ASSERT_EQ(1u, callback_log.size()); | 136 ASSERT_EQ(1u, callback_log.size()); |
119 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); | 137 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); |
120 } | 138 } |
121 | 139 |
122 TEST_F(FileSystemProviderOperationsCloseFileTest, OnError) { | 140 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnError) { |
123 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 141 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
124 util::StatusCallbackLog callback_log; | 142 util::StatusCallbackLog callback_log; |
125 | 143 |
126 CloseFile close_file(NULL, | 144 CreateDirectory create_directory( |
127 file_system_info_, | 145 NULL, |
128 kOpenRequestId, | 146 file_system_info_, |
129 base::Bind(&util::LogStatusCallback, &callback_log)); | 147 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
130 close_file.SetDispatchEventImplForTesting( | 148 false /* exclusive */, |
| 149 true /* recursive */, |
| 150 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 151 create_directory.SetDispatchEventImplForTesting( |
131 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 152 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
132 base::Unretained(&dispatcher))); | 153 base::Unretained(&dispatcher))); |
133 | 154 |
134 EXPECT_TRUE(close_file.Execute(kRequestId)); | 155 EXPECT_TRUE(create_directory.Execute(kRequestId)); |
135 | 156 |
136 close_file.OnError(kRequestId, | 157 create_directory.OnError(kRequestId, |
137 scoped_ptr<RequestValue>(new RequestValue()), | 158 scoped_ptr<RequestValue>(new RequestValue()), |
138 base::File::FILE_ERROR_TOO_MANY_OPENED); | 159 base::File::FILE_ERROR_TOO_MANY_OPENED); |
139 ASSERT_EQ(1u, callback_log.size()); | 160 ASSERT_EQ(1u, callback_log.size()); |
140 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); | 161 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); |
141 } | 162 } |
142 | 163 |
143 } // namespace operations | 164 } // namespace operations |
144 } // namespace file_system_provider | 165 } // namespace file_system_provider |
145 } // namespace chromeos | 166 } // namespace chromeos |
OLD | NEW |