| 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" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // Sample input as JSON. Keep in sync with file_system_provider_api.idl. | 178 // Sample input as JSON. Keep in sync with file_system_provider_api.idl. |
| 179 // As for now, it is impossible to create *::Params class directly, not from | 179 // As for now, it is impossible to create *::Params class directly, not from |
| 180 // base::Value. | 180 // base::Value. |
| 181 const std::string input = | 181 const std::string input = |
| 182 "[\n" | 182 "[\n" |
| 183 " \"testing-file-system\",\n" // kFileSystemId | 183 " \"testing-file-system\",\n" // kFileSystemId |
| 184 " 2,\n" // kRequestId | 184 " 2,\n" // kRequestId |
| 185 " [\n" | 185 " [\n" |
| 186 " {\n" | 186 " {\n" |
| 187 " \"isDirectory\": false,\n" | 187 " \"isDirectory\": false,\n" |
| 188 " \"name\": \"blueberries.txt\",\n" | 188 " \"name\": \"blueberries.txt\"\n" |
| 189 " \"size\": 4096,\n" | |
| 190 " \"modificationTime\": {\n" | |
| 191 " \"value\": \"Thu Apr 24 00:46:52 UTC 2014\"\n" | |
| 192 " }\n" | |
| 193 " }\n" | 189 " }\n" |
| 194 " ],\n" | 190 " ],\n" |
| 195 " false,\n" // has_more | 191 " false,\n" // has_more |
| 196 " 0\n" // execution_time | 192 " 0\n" // execution_time |
| 197 "]\n"; | 193 "]\n"; |
| 198 scoped_ptr<RequestValue> request_value; | 194 scoped_ptr<RequestValue> request_value; |
| 199 ASSERT_NO_FATAL_FAILURE(CreateRequestValueFromJSON(input, &request_value)); | 195 ASSERT_NO_FATAL_FAILURE(CreateRequestValueFromJSON(input, &request_value)); |
| 200 | 196 |
| 201 const bool has_more = false; | 197 const bool has_more = false; |
| 202 read_directory.OnSuccess(kRequestId, request_value.Pass(), has_more); | 198 read_directory.OnSuccess(kRequestId, request_value.Pass(), has_more); |
| 203 | 199 |
| 204 ASSERT_EQ(1u, callback_logger.events().size()); | 200 ASSERT_EQ(1u, callback_logger.events().size()); |
| 205 CallbackLogger::Event* event = callback_logger.events()[0]; | 201 CallbackLogger::Event* event = callback_logger.events()[0]; |
| 206 EXPECT_EQ(base::File::FILE_OK, event->result()); | 202 EXPECT_EQ(base::File::FILE_OK, event->result()); |
| 207 | 203 |
| 208 ASSERT_EQ(1u, event->entry_list().size()); | 204 ASSERT_EQ(1u, event->entry_list().size()); |
| 209 const storage::DirectoryEntry entry = event->entry_list()[0]; | 205 const storage::DirectoryEntry entry = event->entry_list()[0]; |
| 210 EXPECT_FALSE(entry.is_directory); | 206 EXPECT_FALSE(entry.is_directory); |
| 211 EXPECT_EQ("blueberries.txt", entry.name); | 207 EXPECT_EQ("blueberries.txt", entry.name); |
| 212 EXPECT_EQ(4096, entry.size); | |
| 213 base::Time expected_time; | |
| 214 EXPECT_TRUE( | |
| 215 base::Time::FromString("Thu Apr 24 00:46:52 UTC 2014", &expected_time)); | |
| 216 EXPECT_EQ(expected_time, entry.last_modified_time); | |
| 217 } | 208 } |
| 218 | 209 |
| 219 TEST_F(FileSystemProviderOperationsReadDirectoryTest, | 210 TEST_F(FileSystemProviderOperationsReadDirectoryTest, |
| 220 OnSuccess_InvalidMetadata) { | 211 OnSuccess_InvalidMetadata) { |
| 221 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 212 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 222 CallbackLogger callback_logger; | 213 CallbackLogger callback_logger; |
| 223 | 214 |
| 224 ReadDirectory read_directory(NULL, file_system_info_, | 215 ReadDirectory read_directory(NULL, file_system_info_, |
| 225 base::FilePath(kDirectoryPath), | 216 base::FilePath(kDirectoryPath), |
| 226 base::Bind(&CallbackLogger::OnReadDirectory, | 217 base::Bind(&CallbackLogger::OnReadDirectory, |
| 227 base::Unretained(&callback_logger))); | 218 base::Unretained(&callback_logger))); |
| 228 read_directory.SetDispatchEventImplForTesting( | 219 read_directory.SetDispatchEventImplForTesting( |
| 229 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 220 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 230 base::Unretained(&dispatcher))); | 221 base::Unretained(&dispatcher))); |
| 231 | 222 |
| 232 EXPECT_TRUE(read_directory.Execute(kRequestId)); | 223 EXPECT_TRUE(read_directory.Execute(kRequestId)); |
| 233 | 224 |
| 234 // Sample input as JSON. Keep in sync with file_system_provider_api.idl. | 225 // Sample input as JSON. Keep in sync with file_system_provider_api.idl. |
| 235 // As for now, it is impossible to create *::Params class directly, not from | 226 // As for now, it is impossible to create *::Params class directly, not from |
| 236 // base::Value. | 227 // base::Value. |
| 237 const std::string input = | 228 const std::string input = |
| 238 "[\n" | 229 "[\n" |
| 239 " \"testing-file-system\",\n" // kFileSystemId | 230 " \"testing-file-system\",\n" // kFileSystemId |
| 240 " 2,\n" // kRequestId | 231 " 2,\n" // kRequestId |
| 241 " [\n" | 232 " [\n" |
| 242 " {\n" | 233 " {\n" |
| 243 " \"isDirectory\": false,\n" | 234 " \"isDirectory\": false,\n" |
| 244 " \"name\": \"blue/berries.txt\",\n" | 235 " \"name\": \"blue/berries.txt\"\n" |
| 245 " \"size\": 4096,\n" | |
| 246 " \"modificationTime\": {\n" | |
| 247 " \"value\": \"Thu Apr 24 00:46:52 UTC 2014\"\n" | |
| 248 " }\n" | |
| 249 " }\n" | 236 " }\n" |
| 250 " ],\n" | 237 " ],\n" |
| 251 " false,\n" // has_more | 238 " false,\n" // has_more |
| 252 " 0\n" // execution_time | 239 " 0\n" // execution_time |
| 253 "]\n"; | 240 "]\n"; |
| 254 scoped_ptr<RequestValue> request_value; | 241 scoped_ptr<RequestValue> request_value; |
| 255 ASSERT_NO_FATAL_FAILURE(CreateRequestValueFromJSON(input, &request_value)); | 242 ASSERT_NO_FATAL_FAILURE(CreateRequestValueFromJSON(input, &request_value)); |
| 256 | 243 |
| 257 const bool has_more = false; | 244 const bool has_more = false; |
| 258 read_directory.OnSuccess(kRequestId, request_value.Pass(), has_more); | 245 read_directory.OnSuccess(kRequestId, request_value.Pass(), has_more); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 284 | 271 |
| 285 ASSERT_EQ(1u, callback_logger.events().size()); | 272 ASSERT_EQ(1u, callback_logger.events().size()); |
| 286 CallbackLogger::Event* event = callback_logger.events()[0]; | 273 CallbackLogger::Event* event = callback_logger.events()[0]; |
| 287 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); | 274 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); |
| 288 ASSERT_EQ(0u, event->entry_list().size()); | 275 ASSERT_EQ(0u, event->entry_list().size()); |
| 289 } | 276 } |
| 290 | 277 |
| 291 } // namespace operations | 278 } // namespace operations |
| 292 } // namespace file_system_provider | 279 } // namespace file_system_provider |
| 293 } // namespace chromeos | 280 } // namespace chromeos |
| OLD | NEW |