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/create_directo
ry.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/create_directo
ry.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 }; | 49 }; |
50 | 50 |
51 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute) { | 51 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute) { |
52 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 52 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
53 util::StatusCallbackLog callback_log; | 53 util::StatusCallbackLog callback_log; |
54 | 54 |
55 CreateDirectory create_directory( | 55 CreateDirectory create_directory( |
56 NULL, | 56 NULL, |
57 file_system_info_, | 57 file_system_info_, |
58 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 58 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
59 false /* exclusive */, | |
60 true /* recursive */, | 59 true /* recursive */, |
61 base::Bind(&util::LogStatusCallback, &callback_log)); | 60 base::Bind(&util::LogStatusCallback, &callback_log)); |
62 create_directory.SetDispatchEventImplForTesting( | 61 create_directory.SetDispatchEventImplForTesting( |
63 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
64 base::Unretained(&dispatcher))); | 63 base::Unretained(&dispatcher))); |
65 | 64 |
66 EXPECT_TRUE(create_directory.Execute(kRequestId)); | 65 EXPECT_TRUE(create_directory.Execute(kRequestId)); |
67 | 66 |
68 ASSERT_EQ(1u, dispatcher.events().size()); | 67 ASSERT_EQ(1u, dispatcher.events().size()); |
69 extensions::Event* event = dispatcher.events()[0]; | 68 extensions::Event* event = dispatcher.events()[0]; |
(...skipping 11 matching lines...) Expand all Loading... |
81 EXPECT_EQ(kFileSystemId, event_file_system_id); | 80 EXPECT_EQ(kFileSystemId, event_file_system_id); |
82 | 81 |
83 int event_request_id = -1; | 82 int event_request_id = -1; |
84 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); | 83 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); |
85 EXPECT_EQ(kRequestId, event_request_id); | 84 EXPECT_EQ(kRequestId, event_request_id); |
86 | 85 |
87 std::string event_directory_path; | 86 std::string event_directory_path; |
88 EXPECT_TRUE(options->GetString("directoryPath", &event_directory_path)); | 87 EXPECT_TRUE(options->GetString("directoryPath", &event_directory_path)); |
89 EXPECT_EQ(kDirectoryPath, event_directory_path); | 88 EXPECT_EQ(kDirectoryPath, event_directory_path); |
90 | 89 |
91 bool event_exclusive; | |
92 EXPECT_TRUE(options->GetBoolean("exclusive", &event_exclusive)); | |
93 EXPECT_FALSE(event_exclusive); | |
94 | |
95 bool event_recursive; | 90 bool event_recursive; |
96 EXPECT_TRUE(options->GetBoolean("recursive", &event_recursive)); | 91 EXPECT_TRUE(options->GetBoolean("recursive", &event_recursive)); |
97 EXPECT_TRUE(event_recursive); | 92 EXPECT_TRUE(event_recursive); |
98 } | 93 } |
99 | 94 |
100 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_NoListener) { | 95 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_NoListener) { |
101 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 96 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
102 util::StatusCallbackLog callback_log; | 97 util::StatusCallbackLog callback_log; |
103 | 98 |
104 CreateDirectory create_directory( | 99 CreateDirectory create_directory( |
105 NULL, | 100 NULL, |
106 file_system_info_, | 101 file_system_info_, |
107 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 102 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
108 false /* exclusive */, | |
109 true /* recursive */, | 103 true /* recursive */, |
110 base::Bind(&util::LogStatusCallback, &callback_log)); | 104 base::Bind(&util::LogStatusCallback, &callback_log)); |
111 create_directory.SetDispatchEventImplForTesting( | 105 create_directory.SetDispatchEventImplForTesting( |
112 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 106 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
113 base::Unretained(&dispatcher))); | 107 base::Unretained(&dispatcher))); |
114 | 108 |
115 EXPECT_FALSE(create_directory.Execute(kRequestId)); | 109 EXPECT_FALSE(create_directory.Execute(kRequestId)); |
116 } | 110 } |
117 | 111 |
118 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_ReadOnly) { | 112 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_ReadOnly) { |
119 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 113 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
120 util::StatusCallbackLog callback_log; | 114 util::StatusCallbackLog callback_log; |
121 | 115 |
122 const ProvidedFileSystemInfo read_only_file_system_info( | 116 const ProvidedFileSystemInfo read_only_file_system_info( |
123 kExtensionId, | 117 kExtensionId, |
124 kFileSystemId, | 118 kFileSystemId, |
125 "" /* file_system_name */, | 119 "" /* file_system_name */, |
126 false /* writable */, | 120 false /* writable */, |
127 base::FilePath() /* mount_path */); | 121 base::FilePath() /* mount_path */); |
128 | 122 |
129 CreateDirectory create_directory( | 123 CreateDirectory create_directory( |
130 NULL, | 124 NULL, |
131 read_only_file_system_info, | 125 read_only_file_system_info, |
132 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 126 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
133 false /* exclusive */, | |
134 true /* recursive */, | 127 true /* recursive */, |
135 base::Bind(&util::LogStatusCallback, &callback_log)); | 128 base::Bind(&util::LogStatusCallback, &callback_log)); |
136 create_directory.SetDispatchEventImplForTesting( | 129 create_directory.SetDispatchEventImplForTesting( |
137 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 130 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
138 base::Unretained(&dispatcher))); | 131 base::Unretained(&dispatcher))); |
139 | 132 |
140 EXPECT_FALSE(create_directory.Execute(kRequestId)); | 133 EXPECT_FALSE(create_directory.Execute(kRequestId)); |
141 } | 134 } |
142 | 135 |
143 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnSuccess) { | 136 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnSuccess) { |
144 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 137 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
145 util::StatusCallbackLog callback_log; | 138 util::StatusCallbackLog callback_log; |
146 | 139 |
147 CreateDirectory create_directory( | 140 CreateDirectory create_directory( |
148 NULL, | 141 NULL, |
149 file_system_info_, | 142 file_system_info_, |
150 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 143 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
151 false /* exclusive */, | |
152 true /* recursive */, | 144 true /* recursive */, |
153 base::Bind(&util::LogStatusCallback, &callback_log)); | 145 base::Bind(&util::LogStatusCallback, &callback_log)); |
154 create_directory.SetDispatchEventImplForTesting( | 146 create_directory.SetDispatchEventImplForTesting( |
155 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 147 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
156 base::Unretained(&dispatcher))); | 148 base::Unretained(&dispatcher))); |
157 | 149 |
158 EXPECT_TRUE(create_directory.Execute(kRequestId)); | 150 EXPECT_TRUE(create_directory.Execute(kRequestId)); |
159 | 151 |
160 create_directory.OnSuccess(kRequestId, | 152 create_directory.OnSuccess(kRequestId, |
161 scoped_ptr<RequestValue>(new RequestValue()), | 153 scoped_ptr<RequestValue>(new RequestValue()), |
162 false /* has_more */); | 154 false /* has_more */); |
163 ASSERT_EQ(1u, callback_log.size()); | 155 ASSERT_EQ(1u, callback_log.size()); |
164 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); | 156 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); |
165 } | 157 } |
166 | 158 |
167 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnError) { | 159 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnError) { |
168 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 160 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
169 util::StatusCallbackLog callback_log; | 161 util::StatusCallbackLog callback_log; |
170 | 162 |
171 CreateDirectory create_directory( | 163 CreateDirectory create_directory( |
172 NULL, | 164 NULL, |
173 file_system_info_, | 165 file_system_info_, |
174 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 166 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
175 false /* exclusive */, | |
176 true /* recursive */, | 167 true /* recursive */, |
177 base::Bind(&util::LogStatusCallback, &callback_log)); | 168 base::Bind(&util::LogStatusCallback, &callback_log)); |
178 create_directory.SetDispatchEventImplForTesting( | 169 create_directory.SetDispatchEventImplForTesting( |
179 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 170 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
180 base::Unretained(&dispatcher))); | 171 base::Unretained(&dispatcher))); |
181 | 172 |
182 EXPECT_TRUE(create_directory.Execute(kRequestId)); | 173 EXPECT_TRUE(create_directory.Execute(kRequestId)); |
183 | 174 |
184 create_directory.OnError(kRequestId, | 175 create_directory.OnError(kRequestId, |
185 scoped_ptr<RequestValue>(new RequestValue()), | 176 scoped_ptr<RequestValue>(new RequestValue()), |
186 base::File::FILE_ERROR_TOO_MANY_OPENED); | 177 base::File::FILE_ERROR_TOO_MANY_OPENED); |
187 ASSERT_EQ(1u, callback_log.size()); | 178 ASSERT_EQ(1u, callback_log.size()); |
188 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); | 179 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); |
189 } | 180 } |
190 | 181 |
191 } // namespace operations | 182 } // namespace operations |
192 } // namespace file_system_provider | 183 } // namespace file_system_provider |
193 } // namespace chromeos | 184 } // namespace chromeos |
OLD | NEW |